Skip to content

Commit

Permalink
Merge pull request #35 from rschuchmann/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
FFiand authored Mar 4, 2022
2 parents 164797c + 72086bc commit 55ee8b9
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 486 deletions.
2 changes: 1 addition & 1 deletion TIMES-DK_COMETS
Submodule TIMES-DK_COMETS updated 1 files
+2 −2 README.md
2 changes: 1 addition & 1 deletion TIMES_Demo
Submodule TIMES_Demo updated 76 files
+22 −0 model-ge/README.txt
+4,196 −0 model-ge/base.dd
+73 −0 model-ge/bounds-uc_wsets.dd
+3 −0 model-ge/cbc.opt
+7 −0 model-ge/cplex.opt
+783 −0 model-ge/dem_ref.dd
+71 −0 model-ge/demo12Base.run
+72 −0 model-ge/demo12MLF-BaseRep.run
+73 −0 model-ge/demo12MLF-PolicyEx.run
+11 −0 model-ge/demo12_ts.dd
+14 −0 model-ge/demomacro.dd
+26 −0 model-ge/demproj_dtcar.dd
+35 −0 model-ge/ghgpolicy.dd
+3 −0 model-ge/kestrel.opt
+1,400 −0 model-ge/newtechs.dd
+13 −0 model-ge/offdummy.dd
+26 −0 model-ge/peak_rsv.dd
+39 −0 model-ge/refinery.dd
+85 −0 model-ge/rundemo.gms
+198 −0 model-ge/syssettings.dd
+20 −0 model-ge/trade_param.dd
+48 −0 model-ge/uc_nuc_maxcap.dd
+37 −37 source/AUTHORS.md
+57 −53 source/README.md
+109 −5 source/Version.log
+ source/_times.g00
+1 −1 source/bnd_flo.mod
+8 −6 source/bndmain.mod
+118 −0 source/calibase.mlf
+1 −1 source/coef_ptr.mod
+1 −1 source/ddfupd.msa
+100 −0 source/dynslite.vda
+11 −14 source/eqdamage.mod
+2 −3 source/eqdeclr.mod
+39 −6 source/eqdeclr.tm
+6 −6 source/eqmain.mod
+2 −1 source/eqobj.tm
+19 −25 source/eqobjann.tm
+11 −2 source/eqobjcst.tm
+182 −0 source/equ_ext.mlf
+41 −28 source/equ_ext.vda
+1 −1 source/err_stat.mod
+62 −0 source/initmty.mlf
+9 −7 source/initmty.mod
+6 −6 source/initmty.tm
+2 −3 source/initmty.vda
+1 −1 source/initsys.mod
+6 −3 source/maindrv.mod
+49 −18 source/mod_equa.tm
+1 −0 source/mod_vars.mod
+10 −5 source/mod_vars.tm
+3 −0 source/pp_prelv.vda
+11 −11 source/pp_qafs.mod
+5 −2 source/pp_reduce.red
+92 −0 source/ppm_ext.mlf
+2 −0 source/ppm_ext.vda
+8 −7 source/ppmain.mod
+44 −0 source/prep_ext.mlf
+14 −5 source/prepxtra.mod
+103 −0 source/presolve.mlf
+22 −10 source/readbprice.mod
+5 −15 source/resloadc.vda
+113 −0 source/rpt_ext.mlf
+1 −1 source/rptmain.mod
+1 −0 source/rptmain.tm
+12 −10 source/rptmisc.rpt
+1 −1 source/sensis.stc
+1 −0 source/setglobs.gms
+9 −1 source/solsetv.v3
+3 −2 source/solve.mod
+30 −10 source/spoint.mod
+17 −4 source/times2veda.vdd
+17 −3 source/times2veda_stc.vdd
+13 −11 source/timslice.mod
+2 −10 source/ucbet.vda
+23 −16 source/wrtbprice.mod
33 changes: 12 additions & 21 deletions renderer_times_miro/mirowidget_scenddmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ mirowidget_scenddmapOutput <- function(id, height = NULL, options = NULL, path =
tags$div(class = "col-sm-12 col-md-6 box-custom",
tags$div(class = "table-styles",
rHandsontableOutput(ns('boEoTime'))
),
tags$div(id = ns("boEoTimeWarn"), class="config-message", style = "font-size: 11pt;",
"BOTIME (default: 1960) and EOTIME (default: 2200) usually do not need to be changed.
Be sure what you are doing!")
)
)
)),
tags$div(class = "col-sm-12 col-md-4 col-lg-6 box-custom",
Expand All @@ -155,7 +152,7 @@ mirowidget_scenddmapOutput <- function(id, height = NULL, options = NULL, path =
min = 10, max = 36000, value = 1000L, step = 1)
),
tags$div(class = "col-sm-6 custom-2 box-custom",
selectInput(ns("gmsobj"), tags$h4("Objective function formulation"), c("ALT", "AUTO", "LIN", "MOD", "STD"), selected = "MOD"),
selectInput(ns("gmsobj"), tags$h4("Objective function formulation"), c("ALT", "AUTO", "LIN", "MOD", "STD"), selected = "AUTO"),
sliderInput(ns("gmsbratio"),
tags$div(
tags$h4("Basis indicator (bRatio)", tags$a("",
Expand Down Expand Up @@ -200,10 +197,9 @@ mirowidget_scenddmapOutput <- function(id, height = NULL, options = NULL, path =
tags$h4("Upload DD files and runfile here", class="highlight-block"),
fileInput(ns("ddFilesUpload"), tags$h4("DD file(s):"),
width = "100%", multiple = TRUE,
accept = c("text/plain",
".gms", ".inc", "txt", ".dd", ".DD")),
accept = c(".dd", ".dds")),
tags$div(id = "invalidFileExtensionDD", class="config-message custom-message",
"Invalid file extension! allowed are 'dd', 'DD', 'gms', 'inc', 'txt'."),
"Invalid file extension! allowed are 'dd', 'dds'."),
tags$div(id = "attachmentAddedDD", class="config-message",
"File(s) added as attachment."),
fileInput(ns("gmsrunlocation"), tags$h4("RUN file:"),
Expand Down Expand Up @@ -288,7 +284,7 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
updateSelectInput(session, "gmsreslim", selected = if(length(rv$gmsreslim))rv$gmsreslim else 1000)
updateSelectInput(session, "gmssolver", selected = if(length(rv$gmssolver)) rv$gmssolver else "cplex")
rv$boEoTimeData <<- tibble(Time = c("BOTIME", "EOTIME"),
Value = c(if(length(rv$gmsbotime)) rv$gmsbotime else 1960,
Value = c(if(length(rv$gmsbotime)) rv$gmsbotime else 1850,
if(length(rv$gmseotime)) rv$gmseotime else 2200))
})

Expand All @@ -297,7 +293,7 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
attachments$save(zipFilePath, "dd_files.zip", overwrite = TRUE)
attachmentsZip <- zip::zip_list(zipFilePath)
attachmentsZip <- attachmentsZip[attachmentsZip$compressed_size > 0, ]$filename
rv$ddFiles <- attachmentsZip[grep(".dd", attachmentsZip, ignore.case = TRUE)]
rv$ddFiles <- attachmentsZip[grep(".dds?$", attachmentsZip, ignore.case = TRUE)]
}, error = function(e){
print("An unexpected error occured.")
})
Expand Down Expand Up @@ -381,22 +377,17 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
rv$gmsbotime <<- as_tibble(hot_to_r(input$boEoTime)) %>%
filter(Time == "BOTIME") %>% pull(Value) %>% unique() %>% as.numeric()
}else{
rv$gmsbotime <<- 1960
rv$gmsbotime <<- 1850
}
if(length(as_tibble(hot_to_r(input$boEoTime)))){
rv$gmseotime <<- as_tibble(hot_to_r(input$boEoTime)) %>%
filter(Time == "EOTIME") %>% pull(Value) %>% unique() %>% as.numeric()
}else{
rv$gmseotime <<- 2200
}
if(rv$gmsbotime != 1960 || rv$gmseotime != 2200){
showEl(session, paste0("#", session$ns("boEoTimeWarn")))
}else{
hideEl(session, paste0("#", session$ns("boEoTimeWarn")))
}
}else{
rv$boEoTimeData <<- rv$boEoTimeData[0,]
rv$gmsbotime <<- 1960
rv$gmsbotime <<- 1850
rv$gmseotime <<- 2200
}
})
Expand Down Expand Up @@ -438,9 +429,9 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
filePath <- file$datapath
fileName <- file$name
ext <- tools::file_ext(file$datapath)
ddToAdd <- fileName[grep(".dd$", fileName, ignore.case = TRUE)]
ddToAdd <- fileName[grep(".dds?$", fileName, ignore.case = TRUE)]
req(file)
if(any(!ext %in% c("gms", "txt", "inc", "dd", "DD"))){
if(any(!tolower(ext) %in% c("dd", "dds"))){
showHideEl(session, "#invalidFileExtensionDD")
return()
}
Expand All @@ -461,7 +452,7 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
{
attachmentsZip <- zip::zip_list(zipFilePath)
attachmentsZip <- attachmentsZip[attachmentsZip$compressed_size > 0, ]$filename
ddFiles <- attachmentsZip[grep(".dd", attachmentsZip, ignore.case = TRUE)]
ddFiles <- attachmentsZip[grep(".dds?$", attachmentsZip, ignore.case = TRUE)]

attachments$add(session, zipFilePath, "dd_files.zip", overwrite = TRUE, execPerm = TRUE)
showHideEl(session, "#attachmentAddedDD")
Expand Down Expand Up @@ -565,7 +556,7 @@ renderMirowidget_scenddmap <- function(input, output, session, data, options = N
search = TRUE,
height = 400) %>%
hot_table(stretchH = "all", highlightRow = TRUE) %>%
hot_col(1, type = "autocomplete", source = c(if(length(rv$gmsbotime)) rv$gmsbotime else 1960:if(length(rv$gmseotime)) rv$gmseotime else 2200), strict = TRUE, allowInvalid = FALSE) %>%
hot_col(1, type = "autocomplete", source = c(if(length(rv$gmsbotime)) rv$gmsbotime else 1850:if(length(rv$gmseotime)) rv$gmseotime else 2200), strict = TRUE, allowInvalid = FALSE) %>%
hot_cols(manualColumnResize = TRUE, columnSorting = TRUE) %>%
hot_col(col = 'Text', colWidths=0.001)
return(milestonyrTableTmp)
Expand Down
28 changes: 18 additions & 10 deletions times_miro.gms
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ FLO_BND .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,ALL_TS,LIM' //
FLO_COST .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,ALL_TS,CUR' // 'Added variable O&M of using a commodity'
FLO_CUM .'Par'.'ALL_REG,PRC,COM_GRP,ALLYEAR,1,LIM' // 'Bound on cumulative flow'
FLO_DELIV .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,ALL_TS,CUR' // 'Delivery cost for using a commodity'
FLO_EFF .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,1,2' // 'General process flow-relation parameter'
FLO_EMIS .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,1,ALL_TS' // 'General process emission 'Par'.'
FLO_FR .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,ALL_TS,LIM' // 'Load-curve of availability of commodity to a process'
FLO_FUNC .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,1,ALL_TS' // 'Relationship between 2 .'group of' flows'
Expand Down Expand Up @@ -197,6 +198,7 @@ NCAP_AFM .'Par'.'ALL_REG,ALLYEAR,PRC' //
NCAP_AFS .'Par'.'ALL_REG,ALLYEAR,PRC,ALL_TS,LIM' // 'Seasonal Availability of capacity'
NCAP_AFX .'Par'.'ALL_REG,ALLYEAR,PRC' // 'Change in capacity availability'
NCAP_BND .'Par'.'ALL_REG,ALLYEAR,PRC,LIM' // 'Bound on overall capacity in a period'
NCAP_CEH .'Par'.'ALL_REG,ALLYEAR,PRC' // 'Coefficient of electricity to heat'
NCAP_CHPR .'Par'.'ALL_REG,ALLYEAR,PRC,LIM' // 'Combined heat:power ratio'
NCAP_CLED .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP' // 'Leadtime of a commodity before new capacity ready'
NCAP_COM .'Par'.'ALL_REG,ALLYEAR,PRC,COM_GRP,1' // 'Use .'but +' of commodity based upon capacity'
Expand Down Expand Up @@ -454,6 +456,7 @@ $onMulti
$onembeddedCode Python:
import glob
import os
import re
import shutil
import zipfile
gams.wsWorkingDir = '.'
Expand All @@ -477,16 +480,17 @@ if r'%gams.idcgdxinput% '.strip() == '_miro_gdxin_.gdx':
shutil.rmtree(dirpath)
with zipfile.ZipFile("dd_files.zip", 'r') as zip_ref:
zip_ref.extractall("dd_files")
ddFiles = [f for f in os.listdir(r'%DDPREFIX% '.rstrip()) if f.endswith('.dd')]
ddFiles = [f for f in os.listdir(r'%DDPREFIX% '.rstrip()) if f.endswith(('.dd', '.dds'))]

gams.printLog("Start writing myrun.gms")
with open('myrun.gms','w') as frun:
for l in rl:
if len(l.rstrip()) == 0 or l[0]=="*":
continue
if 'batinclude' in l.lower():
if ('_ts.dd' in l.lower() or l.lower().split('batinclude ')[1].strip() == 'ts.dd') and len(isTS) == 0:
isTS = l.lower().split('batinclude ')[1].strip()
if 'include' in l.lower():
ltmp = l.lower().split('include ')[1].strip()
if ('_ts.dd' in l.lower() or ltmp == 'ts.dd' or ltmp == 'ts.dds') and len(isTS) == 0:
isTS = ltmp
frun.write(l)
ddList.append(l.split(' ')[1].split('\n')[0])
elif '.dd' in l.lower():
Expand Down Expand Up @@ -525,8 +529,10 @@ db = gams.ws.add_database_from_gdx('myrun.gdx')
db['ALL_TS'].copy_symbol(gams.db['TimeSlice'])
dd = []
offeps = []
for df in glob.glob(r'%DDPREFIX% '.rstrip()+'*.dd'):
if df[len(r'%DDPREFIX% '.rstrip()):].strip() != isTS:
filePathTmp = r'%DDPREFIX% '.rstrip()
filesTmp = [f for f in os.listdir(filePathTmp) if re.search(r'.*\.dds?$', f, re.IGNORECASE)]
for df in [os.path.join(filePathTmp, file) for file in filesTmp]:
if df[len(filePathTmp):].strip().lower() != isTS:
ddbase = os.path.splitext(os.path.basename(df))[0]
s = 'grep -i offeps "' + df + '" > ' + os.devnull
rc = os.system(s)
Expand All @@ -551,8 +557,9 @@ gams.printLog("Compile time variable report starts in line " + str(start))
end = [i for i, s in enumerate(rl) if 'End of Compile-time Variable List' in s][0]
gams.printLog("Compile time variable report ends in line " + str(end-1))

gams.set('gmsBOTime',[float(1960)])
gams.set('gmsBOTime',[float(1850)])
gams.set('gmsEOTime',[float(2200)])
gams.set('gmsObj',['AUTO'])
while start<end:
vl = rl[start].split()
if vl[1].lower() == 'obj':
Expand Down Expand Up @@ -588,7 +595,8 @@ gams.printLog("com_idx = " + str(com_idx))

gams.printLog("Turning dd files into gdx files")
for dd in gams.get('dd'):
s = 'grep -iv offeps "' + r'%DDPREFIX% '.rstrip()+dd+'.dd" > "' + r'%gams.scrDir%mydd.%gams.scrExt%'+'"'
fileTmp = [f for f in os.listdir(r'%DDPREFIX% '.rstrip()) if re.search(dd + r'.dds?$', f, re.IGNORECASE)][0]
s = 'grep -iv offeps "' + r'%DDPREFIX% '.rstrip()+fileTmp+'" > "' + r'%gams.scrDir%mydd.%gams.scrExt%'+'"'
rc = os.system(s)
if not rc==0:
raise NameError('probem executing: ' + s)
Expand All @@ -597,7 +605,7 @@ for dd in gams.get('dd'):
if not rc==0:
raise NameError('probem executing: ' + s)
dd_db[dd] = gams.ws.add_database_from_gdx(dd+'.gdx')
gams.printLog(str(dd) + ".dd --> " + str(dd) + ".gdx")
gams.printLog(str(fileTmp) + " --> " + str(dd) + ".gdx")
noDD = []
for cdRec in cd_input:
sym = cdRec[0]
Expand Down Expand Up @@ -760,7 +768,7 @@ $eval.set GMSOBJ gmsObj.tl
$eval.set GMSRUNOPT gmsRunOpt.tl

$onecho > timesdriver.gms
$Title TIMES -- VERSION 4.5.9
$Title TIMES -- VERSION 4.6.0
option resLim=%GMSRESLIM%, profile=1, solveOpt=REPLACE, bRatio=%GMSBRATIO%;
option limRow=0, limCol=0, solPrint=OFF, solver=%GMSSOLVER%;
$offListing
Expand Down
Binary file modified times_miro.miroapp
Binary file not shown.
Loading

0 comments on commit 55ee8b9

Please sign in to comment.