Thursday, August 18, 2016

gdxrrw and R 3.3.1

From this post:

I have written a dispatch model in GAMS which optimizes by minimizing system costs. I want to loop runs of the model; Run the optimization, save the output, varying a single parameter(storageCap) -- increasing it by a small fraction each iteration, and running the model again. GDXRRW does not seem to be able to run on R v.3.3.1 -- "Bug In Your Hair".

Seems to work for me.

  1. Install the R package gdxrrw:

    > install.packages("C:\\GAMS\\win64\\24.7\\gdxrrw\\win3264\\",repos=NULL)
    Installing package into ‘C:/Users/Erwin/Documents/R/win-library/3.3’
    (as ‘lib’ is unspecified)
    package ‘gdxrrw’ successfully unpacked and MD5 sums checked

  2. Run a GAMS script like:

    set i /i1*i10/;
    p(i) = uniform(0,1);
    execute_unload "p.gdx"
    execute '"c:\program files\R\R-3.3.1\bin\Rscript.exe" p.R'

    $onecho > p.R



I like to put external scripts at the bottom of the GAMS model in order to reduce the clutter. Background: as the $onecho is performed at compile time the script is actually written before we call it in the execute statement (which runs at execution time).

The output looks like:

--- Job Untitled_56.gms Start 08/18/16 15:29:58 24.6.1 r55820 WEX-WEI x86 64bit/MS Windows
GAMS 24.6.1   Copyright (C) 1987-2016 GAMS Development. All rights reserved
Licensee: Erwin Kalvelagen                               G150803/0001CV-GEN
          Amsterdam Optimization Modeling Group                     DC10455
--- Starting compilation
--- Untitled_56.gms(17) 3 Mb
--- Starting execution: elapsed 0:00:00.013
--- Untitled_56.gms(5) 4 Mb
--- GDX File C:\tmp\p.gdx
--- Untitled_56.gms(6) 4 Mb
platform       x86_64-w64-mingw32         
arch           x86_64                     
os             mingw32                    
system         x86_64, mingw32            
major          3                          
minor          3.1                        
year           2016                       
month          06                         
day            21                         
svn rev        70800                      
language       R                          
version.string R version 3.3.1 (2016-06-21)
nickname       Bug in Your Hair           
     i          p
1   i1 0.17174713
2   i2 0.84326671
3   i3 0.55037536
4   i4 0.30113790
5   i5 0.29221212
6   i6 0.22405287
7   i7 0.34983050
8   i8 0.85627035
9   i9 0.06711372
10 i10 0.50021067
*** Status: Normal completion
--- Job Untitled_56.gms Stop 08/18/16 15:29:59 elapsed 0:00:00.907

No comments:

Post a Comment