2

I have a model with GMS extension. When I run that model with Gams studio, it run perfectly and I obtain the expected results. I have tried to run the GMS model with Gams IDE but I obtain a lot of errors, so, I have tried something different. I Have opened a file with GPR extension and after of that I have imported the GMS model and everything works perfectly when I run the project. I think I need to do same thing usinge Gams Java API, but I don't know how to import to my workspace a GPR file. In this moment I just have the next code:

        GAMSWorkspace workspace = new GAMSWorkspace();
        workspace.setDebugLevel(DebugLevel.KEEP_FILES);
        GAMSJob jobGams = workspace.addJobFromFile("fileModelGms");
        jobGams.run();

When I run that code, I obtain an error:

GAMS process returns unsuccessfully with return code : 2 [there was a compilation error]. Check \_gams_java_gjo1.lst] for more details.

Allanh
  • 465
  • 1
  • 7
  • 19

2 Answers2

2

The gpr file has a format that is only understood by the GAMSIDE. You can not pass it to any API. If you get errors calling your model from the API but not from the GAMSIDE, you probably have set certain options using the IDE which you should set now trough the API as well. Though, without seeing the exact error, it is hard to give further hints.

Lutz
  • 2,197
  • 1
  • 10
  • 12
  • Thanks Lutz. So, How can I know what options I need to set now through the API ? I'm newbie and I don't have idea about GAMS. do I need to modify the model to execute it in Java Api ? – Allanh Dec 10 '19 at 14:51
  • Did you set any options in the IDE? And what is the exact error you get, when you try to solve the model using the API? – Lutz Dec 10 '19 at 15:01
  • When I execute from IDE, I simply run the model and everything works perfectly, I don't need to modify or set anything. I open my gpr file, after that I import my GMS file and I run. When I do it from API Java I run the model GMS but I get errors in compilation time. This link contains the output log with errors. https://pastebin.com/0jkVybFL – Allanh Dec 10 '19 at 15:14
  • 1
    There are many errors, but the one that pops out in this context is "Unable to open include file". So it seems as if you are using something like a $include and point to a file that cannot be found. Make sure, that it is next to the main file or point to the right folder using the inputDir option (https://www.gams.com/latest/docs/UG_GamsCall.html#GAMSAOinputdir). – Lutz Dec 11 '19 at 08:08
  • Thanks Lutz. You're correct. The problem basically is GMS model not found include files. API Java creates a folder in temps directory and it doesn't copy the input data. I copy manually the input data to the new temp folder and that works. Now I would like to know if API Java has some option to add a folder to input data because I'm doing this just with Java. – Allanh Dec 11 '19 at 12:53
  • 1
    Did you check the inputDir option I mentioned before? For Java, this is part of the GAMSOptions class: https://www.gams.com/latest/docs/apis/java/classcom_1_1gams_1_1api_1_1GAMSOptions.html#a3eebf658872fc5357935fecf68b44a29 – Lutz Dec 11 '19 at 15:16
  • Thanks so much Lutz. I have resolved the problem. I changed my code using your suggestions and now the model is running correctly. I'm going no answer my question and I'm going to put my code in the answer. Thanks! – Allanh Dec 13 '19 at 14:33
1

I have solved the problem with Lutz's helper. I needed to Include a dir with input that model uses.

This is my code commented line per line to understand how API Gams works. I used a specific workspace too because API creates a folder in temps file when you run a new Job. I did use for a database GDX too to run my model.

       //specific workspace information is created example: C:/Desktop/Workspace
        GAMSWorkspaceInfo workspaceInfo = new GAMSWorkspaceInfo();
        workspaceInfo.setWorkingDirectory("specificPathWorkspace");
        //A new workspace is created with workspaceInfo.
        GAMSWorkspace workspace = new GAMSWorkspace(workspaceInfo);
        workspace.setDebugLevel(DebugLevel.KEEP_FILES);
        //Options where you're going to set input file data.
        GAMSOptions options = workspace.addOptions();
        //Set path with input Data example: C:/Desktop/InputDate
        options.IDir.add("PathWithInputData");
        //Using a database where is data to be processed example: db.gdx
        GAMSDatabase gdxdb = workspace.addDatabaseFromGDX("db.gdx");
        // Creating a JOB to execute the model.
        GAMSJob jobGams = workspace.addJobFromFile(entradasModeloGamsDTO.getPathModeloGams());
        //Running model
        jobGams.run(options,gdxdb);
Allanh
  • 465
  • 1
  • 7
  • 19