I am trying to solve a linear program with a lot of variables and restrictions. I need to dynamically generate constraint matrices and build lp in python. The only tutorial I can find on Cplex for Python is official from IBM, which is not completely developed. So my questions are: First, a general question: is there a better textbook or something that is well documented? Secondly, a more specific question, in the official textbook, there is an example showing another method for filling in lp, the problem operator:
Maximize
x1 + 2x2 + 3x3
subject to
–x1 + x2 + x3 <= 20
x1 – 3x2 + x3 <= 30
with these bounds
0 <= x1 <= 40
0 <= x2 <= infinity
0 <= x3 <= infinity
and fill the line as follows:
def populatebyrow(prob):
prob.objective.set_sense(prob.objective.sense.maximize)
prob.variables.add(obj = my_obj, ub = my_ub, names = my_colnames)
lbs = prob.variables.get_lower_bounds()
ub1 = prob.variables.get_upper_bounds(0)
names = prob.variables.get_names([0, 2])
rows = [[[0,"x2","x3"],[-1.0, 1.0,1.0]],
[["x1",1,2],[ 1.0,-3.0,1.0]]]
prob.linear_constraints.add(lin_expr = rows, senses = my_sense,
rhs = my_rhs, names = my_rownames)
cols = prob.variables.get_cols("x1", "x3")
, rows? , [0,"x2","x3"]? ( ).
!