|
|
|
library(dplyr)
|
|
|
|
library(tidyr)
|
|
|
|
library(arsenal)
|
|
|
|
library(gdxrrw)
|
|
|
|
GAMSDir = "C:/GAMS/40" # Change to your GAMS Version!
|
|
|
|
|
|
|
|
igdx(GAMSDir)
|
|
|
|
|
|
|
|
set.seed(1234)
|
|
|
|
abcd <- c(stringi::stri_rand_strings(80,5))
|
|
|
|
|
|
|
|
mapping <- rep(LETTERS[5:9], times = c(10, 10, 40, 60, 68))
|
|
|
|
set.seed(1234)
|
|
|
|
all_binid <- c(sample(1:187), 'dummy')
|
|
|
|
set.seed(1234)
|
|
|
|
item <- c('global', 'yields', 'maxrot', 'misc')
|
|
|
|
set.seed(1234)
|
|
|
|
value <- rnorm(15040, mean = 0, sd=100)
|
|
|
|
|
|
|
|
a <- data.frame(item,abcd) %>% tibble()
|
|
|
|
|
|
|
|
a[a$item=='global',]$abcd[19:20] <- c('soilTypeFirm', 'derogatie')
|
|
|
|
|
|
|
|
|
|
|
|
map2id <- data.frame(all_binid = as.factor(all_binid), grouping = as.factor(mapping))
|
|
|
|
fadat2gui <- data.frame(all_binid = as.factor(all_binid), a, value=value)
|
|
|
|
|
|
|
|
test<- fadat2gui[fadat2gui$item=='global',]$value
|
|
|
|
|
|
|
|
#fadat2gui[fadat2gui$all_binid=='dummy',]$item <- 'global'
|
|
|
|
set.seed(1234)
|
|
|
|
fadat2gui[fadat2gui$all_binid=='dummy',]$value[sample(nrow(fadat2gui[fadat2gui$all_binid=='dummy',]),3)] <- c(1.6e+303, 1.59e+303, 1.56e+303)
|
|
|
|
|
|
|
|
set.seed(1234)
|
|
|
|
fdnl <- data.frame(all_binid = as.factor(all_binid[1:94]),
|
|
|
|
year = rep(2017:2020, c(5, 11, 15, 16)),
|
|
|
|
items = c(stringi::stri_rand_strings(94,5),rep('Weight', 94)),
|
|
|
|
value = rnorm(94, mean=0, sd=40)
|
|
|
|
)
|
|
|
|
set.seed(1234)
|
|
|
|
fdnl[fdnl$items == 'Weight',]$value <- runif(94, min = 0.01)
|
|
|
|
|
|
|
|
write.csv(fadat2gui, 'inst/extdata/GAMS/fadat2gui.csv')
|
|
|
|
write.csv(fdnl, 'inst/extdata/GAMS/fdnl.csv')
|
|
|
|
|
|
|
|
write.csv(map2id, 'inst/extdata/GAMS/map2id.csv')
|
|
|
|
|
|
|
|
|
|
|
|
# Run GAMS
|
|
|
|
|
|
|
|
# After running GAMS
|
|
|
|
|
|
|
|
fd2gui <- (gdxrrw::rgdx.param("inst/extdata/GAMS/DynRexampledata.gdx", "p_farmData2GUI", names=c("all_binid", 'items', "varias", "value"), compress=FALSE, ts=FALSE,
|
|
|
|
squeeze=TRUE, useDomInfo = TRUE, check.names = TRUE))
|
|
|
|
|
|
|
|
fdnl <- (gdxrrw::rgdx.param("inst/extdata/GAMS/DynRexampledata.gdx", "p_farmData_NL", names=c("all_binid", 'years', "items2", "value"), compress=FALSE, ts=FALSE,
|
|
|
|
squeeze=TRUE, useDomInfo = TRUE, check.names = TRUE))
|
|
|
|
|
|
|
|
gdxmapping <- (rgdx.set("inst/extdata/GAMS/DynRexampledata.gdx", 'map2binid',names = c('all_binid', 'mapping'), compress=FALSE, ts=FALSE,
|
|
|
|
useDomInfo = TRUE, check.names = TRUE))
|
|
|
|
|
|
|
|
save(fd2gui, file = 'data/fd2gui.RData')
|
|
|
|
save(fdnl, file = 'data/fdnl.RData')
|
|
|
|
save(gdxmapping, file = 'data/gdxmapping.RData')
|
|
|
|
|
|
|
|
groupstats('DynRexampledata.gdx', BINDir="inst/extdata/GAMS/", gdxmap = 'map2binid', mapping = 'mapping', cols = c('d0EfV', 'hXHvI'), w='Weight')
|
|
|
|
|
|
|
|
|
|
|
|
|