End GAMS simulation from MATLAB

2 views (last 30 days)
Sujit Tripathy
Sujit Tripathy on 11 Feb 2022
Answered: Dinesh on 22 Dec 2023
Hey.
I am trying to develop a MATLAB based app (standalone .exe file) for setting parameters of a GAMS model, simulate the model and generate output files. Some info on GAMS: it is a modelling software to formulate and solve mathematical optimization problems <https://www.gams.com/>. I am using MATLAB API to implement various GAMS functions from MATLAB (formulate a model, start a simulation etc.) https://www.gams.com/latest/docs/API_MATLAB_GAMS_OVERVIEW.html.
On the app, I want to have various push buttons to implement different functions in a sequential manner (for e.g., read input data, set parameter values, start a simulation, and export results etc.). I am also trying to add a push button to abort a GAMS simulation while (using system and taskkill command) it is being executed.
Right now, When I press the button on app to abort simulation (with underlying call back function: system('taskkill /F /IM gams.exe')), the push button action takes place only after the simulation is over and I get an error as the process is already over. I tried ending the process (GAMS simulation) externally from 'command window' and 'task manager' and it works. However, I have not been able to implement it from the MATLAB based app. I would really appreciate if anyone can suggest how to have this implemented from the MATLAB based app.
Thanks.

Answers (1)

Dinesh
Dinesh on 22 Dec 2023
Hi Sujat,
It sounds like you're facing an issue with asynchronous execution in your app designer app, specifically when trying to terminate a GAMS simulation process mid-execution. One way to handle this might be to ensure that your abort button initiates a separate thread or process to kill the GAMS task. This can often be achieved by using MATLAB's batch function or other parallel computing tools to run the system('taskkill /F /IM gams.exe') command independently of the main app process. This way, the command to terminate the simulation doesn't have to wait for the simulation to complete before executing.
Another approach might be to investigate how MATLAB handles external calls and processes while a simulation is running. Ensuring that the app remains responsive and can execute commands even during intensive computational tasks is key. It may involve setting up your simulation or app architecture to periodically check for an abort signal or to run simulations in a mode that doesn't block other operations.
The following links might help you:

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!