Hello everyone

I am quite new to GAMS and its modeling language. I’m calling GAMS

from MATLAB and I would like to know how can I create a dynamic set in

GAMS with the size parameter from MATLAB, please? I have the codes

below for scenarios reduction and I would like to vary the size of the

set n and the mapping accordingly based on the number of nodes called

from MATLAB.

Your help is greatly appreciated, thank you

Set n nodes /0*72000/*

t time periods /t1t24/

ancestor(n,n) ancestor matrix

leaf(n) leaf nodes;

Set tn(t,n) time node mapping /

t1.(1*3000),*

t2.(30016000),

t3.(6001*9000),*

t4.(900112000),

t5.(12001*15000),*

t6.(1500118000),

t7.(18001*21000),*

t8.(2100124000),

t9.(24001*27000),*

t10.(2700130000),

t11.(30001*33000),*

t12.(3300136000),

t13.(36001*39000),*

t14.(3900142000),

t15.(42001*45000),*

t16.(4500148000),

t17.(48001*51000),*

t18.(5100154000),

t19.(54001*57000),*

t20.(5700160000),

t21.(60001*63000),*

t22.(6300166000),

t23.(66001*69000),*

t24.(6900172000)/;

\

This is possible using a command line argument --m=34

The GAMS/Matlab interface allows for such command line arguments in the call, something like:

gams(‘dynamic --m=34’)

A more complete example is given in the attached files, do_dynamic.m and dynamic.gms

Cheers, Michael

On Feb 13, 2012, at 6:40 PM, GA wrote:

Hello everyone

I am quite new to GAMS and its modeling language. I’m calling GAMS

from MATLAB and I would like to know how can I create a dynamic set in

GAMS with the size parameter from MATLAB, please? I have the codes

below for scenarios reduction and I would like to vary the size of the

set n and the mapping accordingly based on the number of nodes called

from MATLAB.

Your help is greatly appreciated, thank you

Set n nodes /0*72000/*

t time periods /t1t24/

ancestor(n,n) ancestor matrix

leaf(n) leaf nodes;

Set tn(t,n) time node mapping /

t1.(1*3000),*

t2.(30016000),

t3.(6001*9000),*

t4.(900112000),

t5.(12001*15000),*

t6.(1500118000),

t7.(18001*21000),*

t8.(2100124000),

t9.(24001*27000),*

t10.(2700130000),

t11.(30001*33000),*

t12.(3300136000),

t13.(36001*39000),*

t14.(3900142000),

t15.(42001*45000),*

t16.(4500148000),

t17.(48001*51000),*

t18.(5100154000),

t19.(54001*57000),*

t20.(5700160000),

t21.(60001*63000),*

t22.(6300166000),

t23.(66001*69000),*

t24.(6900172000)/;

–

dynamic.gms (103 Bytes)

do_dynamic.m (117 Bytes)

Hi

You can pass in command line values from the command line gams call

using the “–” prefix, and then use those in your gams code by putting

them between “%” characters. I made a sample bit of code based on

your gams and pasted it below.

Cheers

AndyC

$inlinecom { }

{ -------------------------------------------------

Special command line parameters %nodenum% and %timenum% are passed

into this code from the command

line call, and used to dynamically set the n and t sets.

Example of the command line call from MATLAB: gams test.gms –

nodenum 72000 --timenum 24

------------------------------------------------- }

{ dynamically set the number of nodes and time blocks using the

command line parameters passed in from the gams call }

set n /1*%nodenum%/; { 1) AND (ord(n) NODES_PER_TIME_BLOCK * (ord(t)-1))) = yes;

{ output to gdx file as a debug check }

execute_unload “debug.gdx”;

On Feb 14, 1:40 pm, GA wrote:

Hello everyone

I am quite new to GAMS and its modeling language. I’m calling GAMS

from MATLAB and I would like to know how can I create a dynamic set in

GAMS with the size parameter from MATLAB, please? I have the codes

below for scenarios reduction and I would like to vary the size of the

set n and the mapping accordingly based on the number of nodes called

from MATLAB.

Your help is greatly appreciated, thank you

Set n nodes /0*72000/*

t time periods /t1t24/

ancestor(n,n) ancestor matrix

leaf(n) leaf nodes;

Set tn(t,n) time node mapping /

t1.(1*3000),*

t2.(30016000),

t3.(6001*9000),*

t4.(900112000),

t5.(12001*15000),*

t6.(1500118000),

t7.(18001*21000),*

t8.(2100124000),

t9.(24001*27000),*

t10.(2700130000),

t11.(30001*33000),*

t12.(3300136000),

t13.(36001*39000),*

t14.(3900142000),

t15.(42001*45000),*

t16.(4500148000),

t17.(48001*51000),*

t18.(5100154000),

t19.(54001*57000),*

t20.(5700160000),

t21.(60001*63000),*

t22.(6300166000),

t23.(66001*69000),*

t24.(6900172000)/;

\

I really appreciate both of your helps.

Thank you so much.

Kind regards

Glenn

On Feb 15, 2:43 am, AC wrote:

Hi

You can pass in command line values from the command line gams call

using the “–” prefix, and then use those in your gams code by putting

them between “%” characters. I made a sample bit of code based on

your gams and pasted it below.

Cheers

AndyC

$inlinecom { }

{ -------------------------------------------------

Special command line parameters %nodenum% and %timenum% are passed

into this code from the command

line call, and used to dynamically set the n and t sets.

Example of the command line call from MATLAB: gams test.gms –

nodenum 72000 --timenum 24

------------------------------------------------- }

{ dynamically set the number of nodes and time blocks using the

command line parameters passed in from the gams call }

set n /1*%nodenum%/; { > ignored the “0” element, did you mean 1*72000? }*

set t /t1t%timenum%/;

set tn(t,n) “time node mapping”;

scalar NODES_PER_TIME_BLOCK;

{ BELOW IS A ROUCH GUESS AT THE tn MAPPING YOU WANT, YOU MIGHT HAVE A

SPECIFIC SET OF RULES YOU WANT TO USE THAT

IS DIFFERENT TO THIS.

And note that I assumed the “0” node was a mistake, if not then you

will need to +1 in the tests below when

checking against NODES_PER_TIME_BLOCK }

{ initial guess at how many nodes appear in each time block, round

down if not an integer }

NODES_PER_TIME_BLOCK = floor(card(n) / card(t));

{ allocate the nodes to time blocks REALLY INEFFICIENTLY }

tn(t,n)((ord(t) = 1) AND (ord(n) > tn(t,n)((ord(t) > 1) AND (ord(n) > AND (ord(n) > NODES_PER_TIME_BLOCK * (ord(t)-1))) = yes;

{ output to gdx file as a debug check }

execute_unload “debug.gdx”;

On Feb 14, 1:40 pm, GA wrote:

Hello everyone

I am quite new to GAMS and its modeling language. I’m calling GAMS

from MATLAB and I would like to know how can I create a dynamic set in

GAMS with the size parameter from MATLAB, please? I have the codes

below for scenarios reduction and I would like to vary the size of the

set n and the mapping accordingly based on the number of nodes called

from MATLAB.

Your help is greatly appreciated, thank you

Set n nodes /0*72000/*

t time periods /t1t24/

ancestor(n,n) ancestor matrix

leaf(n) leaf nodes;

Set tn(t,n) time node mapping /

t1.(1*3000),*

t2.(30016000),

t3.(6001*9000),*

t4.(900112000),

t5.(12001*15000),*

t6.(1500118000),

t7.(18001*21000),*

t8.(2100124000),

t9.(24001*27000),*

t10.(2700130000),

t11.(30001*33000),*

t12.(3300136000),

t13.(36001*39000),*

t14.(3900142000),

t15.(42001*45000),*

t16.(4500148000),

t17.(48001*51000),*

t18.(5100154000),

t19.(54001*57000),*

t20.(5700160000),

t21.(60001*63000),*

t22.(6300166000),

t23.(66001*69000),*

t24.(6900172000)/;

\