Path with variable inside

Hi!

I would like to change the path within a for loop.

The path looks like: C:\Data\Instanz Num 001.xlsm

and the 3 numbers at the end of the path are like a variable which must be counted up for each loop.

How can I write this path?



Thank you in advance :wink:

What do you want to do with these paths? Write a put file or unload a GDX file there? These can be arranged with put_utilities. See https://www.gams.com/latest/docs/UG_Put.html#UG_Put_PutUtil. It seems that you want to do something with the Excel files. Again put_utility ‘exec’ allows you to call programs with arguments build at execution time.

-Michael

The paths are needed for loading some data.

The code should look like this, while the bold highlighted Nummer in the path should be instead the intN value

for (intN=1 to 100,

$call gdxxrw “C:\Users\manue\Daten\i10 Instanz 001.xlsm” Squeeze=N @C:\Users\manue\Daten\Index_det.txt
$gdxin “C:\Users\manue\Daten\i10 Instanz 001.gdx”
$load i k
$gdxin

…some futher arguments… ;

);

Therefore my question is how I can add it to the path.
I know that in VBA for example I could write the path like: “C:\Users\manue\Daten\i10 Instanz” &intN & “.xlsm”
Is something similar possible in GAMS?

This does not work. In the other post I was pointing you to a chapter understanding compile- and runtime in GAMS. All complile time statements (like $gdxin/$load are done at compile time) while others like loop(…) are done at execution time. So you cannot mix and match them. Is sounds like that you have a model that you want to run for each instance in a loop. Separate the two:

* This mymodel.gms is a model for one instance
$call gdxxrw "%fn%.xlsm" output="%fn%.gdx" Squeeze=N @C:\Users\manue\Daten\Index_det.txt
$gdxin "%fn.gdx%"
$load i k
$gdxin

* The model 
...



* The scenario driver
set i / 001*100 /;
loop(i,
   put_utility 'exec' / 'gams mymodel --"C:\Users\manue\Daten\i10 Instanz ' t.tl:0 '" lo=%gams.lo% o=mymodel' t.tl:0 '.lst';
);

-Michael

Dear Mr Michael,

Can you help me by answering this question. I have a problem which has quadratic objective function and linear constraints. All variables are continuous. I used BARON solver with model type QCP. IS the solution obtained global optimal? Do I have to adjust any option in the solver? Or any local optimal will be global as this is a convex problem So I guarantee to have the global optimal solution reached.

Thanks a lot.

Thank you very much!

I do have some questions about the code you wrote.

  1. The %gams.lo% in lo=%gams.lo%. What does it do?
  2. Are my changes correct? I insert i.tl instead of t.tl and “fn=” infront of the path.
  3. Do I have to declare fn somewhere?