Hello everyone,
Thanks for existing! I have a problem withe memory usage when solving a sequence of JuMP problems. The structure of my code is the following.
using JuMP
using Gurobi
function Opt(ID,Ind_availL)
Routing=demand(ID)
ArrivalsL=arrivals(ID)
InflowsL=Inflow(ID)
OutflowsL=Outflow(ID)
modelL=Model(() -> Gurobi.Optimizer(env))
set_string_names_on_creation(modelL, false)
@variable(modelL, x[p=1:nA,o=1:nA,d=1:nA,t=1:PCov]>=0, Int)
@variable(modelL, y[p=1:nA,t=1:PCov]>=0, Int)
@variable(modelL, s[o=1:nA,d=1:nA,t=1:PCov]>=0)
@constraint(modelL,demands[o=1:nA,d=1:nA,t=1:PCov], sum(x[p,o,d,tau]*Ind_availL[o,t][p,tau] for p in 1:nA, tau in 1:t)+s[o,d,t]==Routing[o,d,t])
@constraint(modelL, flow[p=1:nA,t=2:PCov], ArrivalsL[p,t]+y[p,t-1]+InflowsL[p,t]-OutflowsL[p,t]==sum(x[p,o,d,t] for o in 1:nA, d in 1:nA)+y[p,t])
@constraint(modelL, flow_base[p=1:nA], sum(x[p,o,d,1] for o in 1:nA, d in 1:nA)+y[p,1]==InflowsL[p,1])
@expression(modelL, cost, sum(Cost[p,o,idxVC]*x[p,o,d,t] for p in 1:nA, o in 1:nA, d in 1:nA, t in 1:PCov))
@expression(modelL, lost, sum(s[o,d,t] for o in 1:nA, d in 1:nA, t in 1:PCov))
@objective(modelL,Min, cost+10000000*lost)
optimize!(modelL)
if has_values(modelL)==true
Opt=value(cost)
lost=value(lost)
else
Opt="missing"
lost="missing"
end
return Opt,lost
end
function SolveForAll(List_of_IDs,Ind_availL)
OptSum=0
Lost=0
for ID in List_of_IDs
Em,Los=Opt(ID,Ind_availL)
if Em=="missing"
Lost+=100
OptSum+=200
else
EmissionsOpt+=Em
Lost+=Los
end
end
return OptSum,Lost
end
SolveForAll(MyList,Ind_AvailL)
Basically, the function Opt()
creates and solves an integer linear program solved with Gurobi, and the function SolveForAll()
solves a sequence of these problems and sums their optimal values if the problems are feasible, otherwise some number (specific to my application, here I say 100 and 200 for simplicity). The other functions called in Opt()
are defined in other parts of the code, and, as far as I know, are speedy and not too heavy on RAM.
MyList
is a Vector{String}
with 170 entries, and for the optimization model I have nA=28, PCov=147
. My issue is that, after I call SolveForAll(MyList,Ind_availL)
, the loop progresses until approx. half the list, and then the whole Julia process is killed. I am told by the server administrator that this is because I hit the RAM limit at my disposal, set at 192Gb. Can anyone advise/suggest what is creating this insane accumulation of stuff (for want of a better term)? Is it s problem with JuMP? Any suggestions on how I can decrease memory usage?
Thanks a lot to everyone!