3

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.

  • As you observe, CPLEX considers your model to be a MIP, and in this case duals are not available. Without more context this is difficult to track. For example, what is the type of `x_master_value`? – Marcus Ritt Jun 19 '19 at 03:20
  • A good way to debug models is to write out the lp file. – Erwin Kalvelagen Jun 19 '19 at 07:22
  • The original post has been edited to provide more context in the code. It should be possible to run it easily if you have CPLEX installed. Also the value of x_master_value does not determine if the problem is a LP or a MIP. It reduces the search space from R^5 to a plane in R^5. Also I wrote the lp file and it corresponds to the problem I want to solve, as a LP (no integer variables). – boring_stack_user Jun 19 '19 at 16:14

1 Answers1

2

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.

rkersh
  • 4,447
  • 2
  • 22
  • 31