I have a semi-continuous optimization problem reformulated as a MIQP optimization problem.
My objective has a quadratic form $x^{T}Qx$ and my $x_{i}$ are such as $x_{i} \in [m,M] \cup \{0\}$. Therefore, I introduce a vector of binary variables $y$ such as $y_{i} \in \{0,1\}$ and consider the following constraint on the $x_{i}$ : $m * y_{i} \leq x_{i} \leq M * y_{i}$.
My optimization problem is hence defined by the objective function, the ranged constraint on the $x_{i}$ and the binary constraint on $y_{i}$.
I'm trying to solve my problem with CPLEX but I'm having trouble specifying the ranged constraint on the $x_{i}$. Here's what I have so far for the constraints :
myProblem=cplex.Cplex()
#define the variables
names_amounts=["amounts " + str(i) for i in range(50))]
names_binary=["binary " + str(i) for i in range(50))]
myProblem.variables.add(ub=[1]*50,
lb=[0]*50,
names=names_amounts)
myProblem.variables.add(ub=[1]*50,
lb=[0]*50,
names=names_binary)
for i in range(50):
myProblem.variables.set_types("amounts " + str(i), myProblem.variables.type.continuous)
myProblem.variables.set_types("binary " + str(i), myProblem.variables.type.integer)
#define the constraints
myProblem.linear_constraints.add(
lin_expr=[[names_amounts,[1]*50]],
senses=['E'],
rhs=[1.0])
I need to add the ranged constraint but can't figure out how. I know my senses
attribute will become ['E'] + ['R' for i in range(50)]
but what about the lin_expr
and rhs
attributes ? How to specify the dependance of the rhs
attribute with the binary variables ?