I solve a problem thousands of times a day. The structure of the problem remains the same (ie no new contraints, only new coeffs in A_eq).
I create a new xp problem at each iteration but can't delete it to from memory (del p or p=None probably leaves the instance in the back end - running memory profiler shows memory increasing at each increment and ultimately runs out of memory - after a few hours - the two pictures attached show the memory increasing or staying flat if the creation of the problem is taken out of the loop). I use Python 3.6, XPress updated to 8.4.7.
Question is: is there a way to delete the instance to free memory (del problem or problem=None are inefficient)? Alternatively I could create only one problem instance at the beginning and then only update the problem. How can I implement such solution (I can change bounds with chngbounds but don't see how to update A_eq * x = b_eq contraint. Note that A_ub does not change nor the objective. ).
The problem is of the form:
minimize: c^T * x
subject to: A_ub * x <= b_ub
A_eq * x == b_eq
lb<= x <= ub
Sample code below - A_eq and A_ub files attached. Note that the only change I need at each run is by providing a new A_eq matrix and update bounds (can do with: ). A_ub unchanged.
import xpress as xp
import numpy as np
import datetime as dt
'''build objective function. we want to minimize the last variable'''
b_ub=np.ndarray.flatten(np.zeros((A_ub.shape,1))) #b_ub is a vector of 0 except last two rows
bounds=tuple(((0,100) for i in range(0,nb_dogs)))
bounds=bounds+tuple((0,0) for i in range(nb_dogs,8*nb_dogs+4*nb_dogs*(nb_dogs-1)))
bounds=bounds+tuple(((0,None) for _ in range(0,4*nb_dogs+6*nb_dogs*(nb_dogs-1))))
bounds=bounds+tuple((None,None)for _ in range(0,1))
'''converts list of tuples to vectors for XPress'''
for b in bounds:
writes problem for xPress and solves
for i in range(0,500):
p = xp.problem ()
x = np.array ([xp.var(lb=-xp.infinity,ub=xp.infinity, vartype=xp.continuous) for i in range(A_ub.shape)])
p.addVariable ( x )
p.addConstraint (xp.Dot(A_ub,x) <= b_ub)
p.addConstraint (xp.Dot(A_eq,x) == b_eq)
# del p or p=None don't prevent the memory from increasing