Change Working Directory of GAMS

Hello all,

Is it possible to change working directory that GAMS puts all those .gdx, .txt, .lst files by default ?

Thanks

Hi Barsssk

You could use a setlocal or setglobal parameter at the beginning of your file.
For example, if you want to have all your files in the directory results, which is below your model directory, I add:

$setglobal results .\results\

* Send to results directory
execute_unload "%results%myresults.gdx";

Gams now replaces every occurence of %results% by .\results\

I use this technique for all my subdirectories (data, temp, results), so I keep all stuff nicely separated. In the subdirectory “temp” I save everything that is created during the run and can be recreated easily. The results subdirectory is for excel files that will be filled everytime with new results (if available).

Cheers

Renger

Hi, same question here. I still don’t understand how to make sure that all the files generated by default (.log, .lst, .lxi) will all go into the same fodler.

Thanks for your help.

How do you run GAMS? From the command line, via Studio, …? It all depends. The GAMS defaults are set in a way that all files are written in the current directory (e.g. when you work from a command line). From a graphical environment that might be different. Please share what you use to execute GAMS and where your files end up.

-Michael

Thank you for your reply!

I currently run the model using GAMS Studio but also sometimes with the command line, so the solution should work for both. All the files generated are stored in the current directory. I’d like to clean up my repository to avoid cluttering the main project folder where I store my primary .gms file. Ideally, I’d prefer to place all auxiliary files into a sub-subfolder structure like /simulation_{datetime}/aux.

Thank you again for your help, and apologies I’m still new to GAMS.

Several solutions:

  1. Why not add the lst, lxi, etc to .gitignore?
  2. Command line: In some directory run gams /path/to/mymodel.gms and if you have include files etc you can add idir1= /path/to/
  3. In Studio: Click the cogwheel on a project and change the working directory. The main file will be found, but if you have include files or GDX files to be loaded you might need to add idir1=/path/to/ to the option line to let the compiler find your other include files.

-Michael

Hi Michael,

Thank you for your help!

I’ve added the files to .gitignore, but this doesn’t fully solve the issue since future simulation runs might overwrite previous results. Ideally, I’d like a way to generate a unique Result folder for each simulation, based on the datetime, and have it relative to the main project folder.

If I understand your solution correctly, I’d need to manually create a folder and launch the project from there. However, I also need this process to work automatically when running multiple simulations.

You understand correctly. There is no reason this can’t be automated and works with concurrent runs.

-Michael