参考:Python求解线性规划——PuLP使用教程 - Only(AR) - 博客园 (cnblogs.com)
1.Define the model
model = pl.LpProblem(name="",sense=pl.LpMaximize)
name 模型的名字
sense 模型的类型(pl.LpMaximize/pl.LpMinimize)
2.Define the decision variables
用x[i]存储变量,命名为xi
x = {
i: pl.LpVariable(name=f"x{
i}", lowBound=,upBound=, cat=) for i in range(1,)}
name 变量名
lowBound 变量最小值(默认负无穷)
upBound 变量最大值 (默认正无穷)
cat 变量的类型(pl.Binary 0/1,pl.Integer 整数,pl.Continuous 实数(默认值))
3.Set the objective
目标函数不用括号
model += x[1]+x[2]+x[3]
4.Add constraints
约束式用括号括起来
式子可以是>=,<=,==,不能是>,<,=
model +=