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 Pietro,
Thank you for your reply and please have a look of the example I gave in this post which I thought will be helpful to clarify my question.
In my case, I am iterating the optimization and dynamically adding a set of variable X into the objective function as well as adding a set of constraints Constr1. The question is the dimension of variable X and constriant Constr1 is unknown.
In Xpress IVE, the code snippet looks as follows:
declaration
prob:mmproblem
I=1..NI # Set of index for X
iter:integer
X:dynamic array (range,range) of mpvar
sol_X:dynamic array(range,range) of real
Constr1:dynamic array(set of mpproblem,range,range) of linctr
Obj:array(set of mpproblem) of linctr
end-declaration
[#############]
# Define Optimization
...
[#############]
iter:=0
repeat
[#############]
# Solve Optimization
with prob do
minimize( Obj(prob) )
end-do
# Get Output...
if iter>=1 then
forall(i in I) create( sol_X(i,iter) )
forall(i in I, j in 1..iter) sol_X(i,j):=getsol( X(i,j) )
end-if
[#############]
iter+=1
forall(i in I) create( X(i,iter) ) # Create a new set of variable
with prob do
Obj(prob)+=sum(i in I)( X(i,iter) ) # Add the new set of variable into Obj
if iter>=2 then
# Create and define a new set of constraint based on the X which is just solved
forall(i in I) create( Constr1(prob,i,iter-1) )
forall(i in I, j in 1..iter-1) Constr1(prob,i,j):= X(i,j)<=sol_X(i,j)
end-if
end-do
until condition

