Mosel Iterations - Clean Memory

143 Views Asked by At

I am trying to optimize a model for 250 different price scenarios using a loop. At the beginning, XPRESS can handle 5 scenarios within a minute, but then the memory starts to increase, the runs get slower and after 50 scenarios, XPRESS starts to solve a single scenario in 5 minutes. How can I clean the memory at the end of each iteration?

Thank you very much,

Ahu

2

There are 2 best solutions below

0
On

You can use 'dellcell' command to delete dynamic arrays of mpvars.

dellcell(myVar)

Also, you can use a mpproblem variable

declarations
   MyProblem: mpprob
end-declarations


forall(p in Prices) do
    with MyProblem do
        ! create mpvar
        ! create constraints
        ! solve problem
        reset(MyProblem)
        delcell(MyVar1)
        delcell(MyVar2)
        ! etc
    end-do
end-do
0
On

I know this is an old post, but could you wrap the optimization within a procedure and loop through the scenarios?

From slightly dated docs:

2.9.3 Local declarations

Several declaration blocks may be used in a subroutine and all identifiers declared are local to this subroutine. This means that all of these symbols exist only in the scope of the subroutine (i.e. between the declaration and the end-procedure or end-function statement) and all of the resource they use is released once the subroutine terminates its execution unless they are referenced outside of the routine (e.g. member of a set defined globally). As a consequence, active constraints (linctr that are not just linear expressions) declared inside a subroutine and the variables they employ are still effective after the termination of the subroutine (because they are part of the current problem) even if the symbols used to name the related objects are not defined any more. Note also that a local declaration may hide a global symbol.