我正在尝试用大量变量和约束来解决线性程序.我需要动态生成约束矩阵并在python中构建lp.我可以在Cplex for Python上找到的唯一一个教程是来自IBM的官方教程,这个教程还不太详细.所以我的问题是:首先,一般问题是,是否有更好的教程或有充分记录的内容?第二,一个更具体的问题,在官方教程中,有一个例子显示填充lp的不同方法,问题陈述是:
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
Run Code Online (Sandbox Code Playgroud)
并按行填充如下:
def populatebyrow(prob):
prob.objective.set_sense(prob.objective.sense.maximize)
# since lower bounds are all 0.0 (the default), lb is omitted here
prob.variables.add(obj = my_obj, ub = my_ub, names = my_colnames)
# can query variables like the following:
# lbs is a …Run Code Online (Sandbox Code Playgroud)