Forum Discussion
FICO
7 years agoCommunity Manager
Dynamic array type in Xpress Python interface
Hello, I query is there any functionality or method in Xpress Python Interface that can be used to resemble the dynamic array type (e.g., "dynamic array(set of range) of mpvar/linctr)") available in...
FICO
7 years agoCommunity Manager
Hello Yijun,
I translated the script you provided to Python, I hope this helps clarify. As you can see in Python you can amend an item to a dictionary at any time as (i,j) in this point is just a key to a dictionary, but we can use it as our index set.
import xpress as xp
X = {}
sol_X = {}
# Define optimization problem here
iter = 0
condition = True
objective = 0 # Initially, the objective function is null
while condition:
prob.solve() # Optimization sense has been specified in the
# definition of prob
if iter >= 1:
for i in I:
for j in range(1, iter + 1):
sol_X[i,j] = prob.getSolution(X[i, j])
iter += 1
# Create new variables
for i in I:
X[i,iter] = xp.var()
prob.addVariable(X[i, iter])
# Update objective function
objective += xp.Sum(X[i,iter] for i in I)
prob.setObjective(objective)
if iter >= 2:
prob.addConstraint(X[i, j] <= sol_X[i, j] for i in I for j in range(1, iter))
condition = ... # update exit condition hereUsing dictionaries for both X and sol_X, while ensuring both have the same set of keys (which you can get with X.keys() and sol_X.keys()).
I hope this helps. Regards,
Pietro


