I am trying to code a Bender's decomposition algorithm using CPLEX. To ensure that I code it correctly, I follow the numerical example from "Decomposition techniques in mathematical programming" by A.J. Conejo et al., p.247.
However, my problem can be stated without access to the mentionned material or knowledge of the context. I need to solve the following LP and derive dual values for "fixing_x" constraint.
import cplex
x_master_value = 100.
c_toy_slave = cplex.Cplex()
types = c_toy_slave.variables.type
y = c_toy_slave.variables.add(names=["y"+str(i) for i in range(3)], lb=[0]*3, types=[types.continuous]*3)
x = c_toy_slave.variables.add(names=["x"], lb=[0], types=[types.continuous])
w = c_toy_slave.variables.add(names=["w"], lb=[0], types=[types.continuous])
cst1 = c_toy_slave.linear_constraints.add([[["y0", "y1", "x", "w"], [-1, -3, 2, -1]]],
names=["cst1"], rhs=[2], senses=['L'])
cst2 = c_toy_slave.linear_constraints.add([[["y0", "y1", "x", "w"], [1, 3, -1, -1]]],
names=["cst2"], rhs=[3], senses=['L'])
cst3 = c_toy_slave.linear_constraints.add([[["y2", "x"], [1, -3]]],
names=["cst3"], rhs=[7/2], senses=['L'])
cst4 = c_toy_slave.linear_constraints.add([[["x"], [1]]],
names=["fixing_x"], rhs=[x_master_value], senses=['E'])
c_toy_slave.objective.set_linear([("y0", -1.5), ("y1", -2), ("y2", -2), ("w", 40)])
c_toy_slave.objective.set_sense(c_toy_slave.objective.sense.minimize)
c_toy_slave.solve()
print("lambda = ", c_toy_slave.solution.get_dual_values("fixing_x"))
But CPLEX says it cannot use the get_dual_values method and prompt this message : CPLEX Error 1017: Not available for mixed-integer problems. I don't know how to solve that since the input I give is not a MIP but a genuine LP.
It turned out that removing the types=[type.continuous]
optional argument solved my problem (i.e., the optimization problem is then properly recognized as an LP). If we look at the documentation for Cplex.variables.add, it says:
If types is specified, the problem type will be a MIP, even if all variables are specified to be continuous.
So, this is the expected behavior.