Retrieving solution from asynchronous solving sessions in different GMPs

  • 20 March 2020
  • 2 replies

Userlevel 2
Badge +4


I want to solve several GMPs at the same time. I adopted AsynchronousExecute AIMMS example to my code. From the progress window I can see that all GMPs get to an optimal solution. However, I can only retrieve the solution of the last GMP. Here is my code:

I generate 3 GMPs, resolve them, and create one solversession for each of the GMPs:

periods := 3;

for (i in periods) do

myGMP(i) := GMP::Instance::Generate(myMathProgram, "myGMP_" + i);

ProgressWindow := GMP::Instance::CreateProgressCategory(myGMP(i));

presolved_myGMP(i) := GMP::Instance::CreatePresolved(myGMP(ip),"presolved_myGMP_" + ipss);

SolverSession(i) := GMP::Instance::CreateSolverSession(presolved_myGMP(i),"SS_" + i);






Here I wait until all asynchronous solversessions are solved.



Here I want to retrieve the solution (variables, etc.) from solversessions into AIMMS so I can see them and save them. 

for (i in periods) do

    GMP::Solution::RetrieveFromSolverSession(SolverSession(i), 1);

    GMP::Solution::SendToModel(presolved_myGMP(i), 1);


    !Write the outcomes of each period solution





unfortunately, I only get the results from the last solved GMP. Do you know how can I retrieve the solution of all solversessions?



Best answer by mohansx 21 March 2020, 00:27

View original

2 replies

Userlevel 2
Badge +4

You are correct @mohansx, I was mistakenly overwriting the parameters. Thanks!

Userlevel 5
Badge +5

@afattahi , in your last piece of code - are you using parameters Period_tech_use(t,i) and hourly_prices(h,i) to store values of the variables tech_use(t,i) and balance_activitiesHourly(h,i)  ?


If yes, then the identifiers on the LHS must have one additional index to those on the RHS and this extra index must be same one that you used to create multiple solver sessions. Something like

for indexSolver do

GMP::Solution::RetrieveFromSolverSession(SolverSession(indexSolver), 1);

GMP::Solution::SendToModel(presolved_myGMP(indexSolver), 1);

Period_tech_use(t,i, indexSolver) := tech_use(t,i);



What’s happening in your code is that you are overwriting the values in each iteration of the loop. If your RHS was tech_use(t) instead of (t,i), then you would see different values in Period_tech_use(t,i) with your code. 

You used the same index i for generating the solver sessions which makes it a bit tricky. I suggest you create a separate set and index like I wrote above. 


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator