Description
This model provides some means to generate large scale multi-dimensional sparse symbols and dumps them in a GDX file. First some domain sets are generated based on some pairs i 10 j 20 (i.e. i0 /i1*i10/, i1 /j1*j20/), some single numbers 5 10 20 (i.e. i0 /1*5/, i1 /1*10/, i2 /1*20/) or minium information 3 50 (i.e. i0 /1*50/, i1 /1*50/, i2 /1*50/) via the mkdom $batInclude. Next, the $batInclude mksym with arguments symbols type (parameter, set, ...), symbol name, symbols dimension, and data density (0<=density<=1) and an extra argument. In case the symbol type is set, the extra argument indicates if a random element text should be stored with the set records. For all other symbol types the extra argument indicates to either store a random value or a fixed values (the value of the extra argument. At the bottom of the file, three cases are given that demonstrate how to create different GDX files. Contributor: Michael Bussieck, December 2022
Small Model of Type : GAMS
Category : GAMS API library
Main file : generate.gms
$title 'Generate some random but structured GDX files' (generate,SEQ=63)
$onText
This model provides some means to generate large scale multi-dimensional sparse
symbols and dumps them in a GDX file.
First some domain sets are generated based on some pairs i 10 j 20 (i.e.
i0 /i1*i10/, i1 /j1*j20/), some single numbers 5 10 20 (i.e. i0 /1*5/,
i1 /1*10/, i2 /1*20/) or minium information 3 50 (i.e. i0 /1*50/, i1 /1*50/,
i2 /1*50/) via the mkdom $batInclude.
Next, the $batInclude mksym with arguments symbols type (parameter, set, ...),
symbol name, symbols dimension, and data density (0<=density<=1) and an extra
argument. In case the symbol type is set, the extra argument indicates if a random
element text should be stored with the set records. For all other symbol types the
extra argument indicates to either store a random value or a fixed values (the value
of the extra argument.
At the bottom of the file, three cases are given that demonstrate how to create
different GDX files.
Contributor: Michael Bussieck, December 2022
$offText
$onEchoV > mkdom.gms
* Syntax for mkdom type dom0 dom1 dom2 ... | ndom ndim
* type=pair specify domN as pair of string and number, this creates "%string%1*%string%%number%",
* string needs to be unique over all doms
* type=single specify domN as number, this creates "1*%number%"
* type=min specify ndom index domains i0 ... i(ndom-1) each with labels 1*%ndim%
$set type %1
$shift
$set dimtmp 0
$set cardi 1
$setGlobal dimadd 1
$setGlobal dimlen
$label loopdim
$ifThenI %type%==pair
$set char "%1" set num %2
set i%dimtmp% / %char%1*%char%%2 /;
$eval cardi %cardi%+card(i%dimtmp%)
$shift shift
$elseIfI %type%==single
set i%dimtmp% / 1*%1 /;
$shift
$elseIfI %type%==min
set i%dimtmp% / 1*%2 /;
$ifE %dimtmp%+1=%1 $shift shift
$else
$error unknown type=%type%
$endIf
$setGlobal dimadd %dimadd%,%cardi%
$eval cardX card(i%dimtmp%)
$if not x%dimlen%==x $setGlobal dimlen %dimlen%,%cardX%
$if x%dimlen%==x $setGlobal dimlen %cardX%
$eval dimtmp %dimtmp%+1
$if not x%1==x $goTo loopdim
$gdxOut dom.gdx
$unload
$gdxOut
$offEcho
$onEchoV > mksym.gms
* Syntax mksym type name dim density havetext
* type=set: for "havetext" <> '' or 0 we will write some element text, otherwise element text will be empty
* type<>set:for "havetext" <> '' or 0 we will use "havetext" as a numercial value to store (in L for var and equ),
* otherwise we create random numerical values
$setArgs symtype symname dim density havetext
$if x%havetext%==x $setLocal havetext 0
* Declaration
$ifThen.domloop %dim%==0
%symtype% %symname% 'text for %symname%';
$else.domloop
$set dom i0
$set dimtmp 1
$label loop1
$if.idxloop %dimtmp%==%dim% $goTo done1
$set dom %dom%,i%dimtmp%
$eval dimtmp %dimtmp%+1
$goTo loop1
$label done1
%symtype% %symname%(%dom%) 'text for %symname%';
$endIf.domloop
* Definition
$ifThen.domloop %dim%==0
$if %havetext% == 0 $eval rvalue uniform(1e-9,1)
$if not %havetext% == 0 $set rvalue %havetext%
$ifI.symtype %symtype%==parameter scalar %symname% / %rvalue% /;
$ifI.symtype not %symtype%==parameter %symtype% %symname% / L %rvalue% /;
$else.domloop
$gdxLoad 'tmp.gdx' %symname%
$endIf.domloop
$offEcho
set i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18,i19;
$ifThen.X 1==1
$batInclude mkdom min 3 500
$batInclude mksym parameter p3 3 0.001
$batInclude mksym parameter p0 0 1
$batInclude mksym set s1 1 0.5
$batInclude mksym set s2 2 0.1 1
$batInclude mksym variable v3 3 0.001
$batInclude mksym variable v0 0 1 2
$batInclude mksym equation e3 3 0.001
$batInclude mksym equation e0 0 1
$gdxOut 1.gdx
$unload
$gdxOut
$elseIf.X 1==0
$batInclude mkdom min 1 10000000
$batInclude mksym parameter p1 1 0.001
$batInclude mksym parameter p0 0 1
$batInclude mksym set s1 1 0.01 1
$batInclude mksym variable v1 1 0.001
$batInclude mksym variable v0 0 1 2
$batInclude mksym equation e1 1 0.001
$batInclude mksym equation e0 0 1
$gdxOut 2.gdx
$unload
$gdxOut
$elseIf.X 1==0
$batInclude mkdom min 1 5
$set maxcnt 5000
$maxGoTo %maxcnt%
$set cnt 1
$label sloop
$batInclude mksym parameter p0_%cnt% 0 1
$batInclude mksym variable v0_%cnt% 0 1 2
$batInclude mksym equation e0_%cnt% 0 1
$eval cnt %cnt%+1
$if.JUMP not %cnt%==%maxcnt% $goTo sloop
$gdxOut 3.gdx
$unload
$gdxOut
$endIf.X