[英]How to solve the following LP/QP problem using Pulp?
from pulp import *
import pandas as pd
import numpy as np
pd.read_excel('Example.xlsx', encoding='latin-1')
prob = pulp.LpProblem('Performance', pulp.LpMaximize)
#### Create Decision Variables:
decision_variables = []
for rownum, row in data.iterrows():
variable = str('x' + str(rownum))
variable = pulp.LpVariable(str(variable), lowBound= row['D']*0.7,
upBound= row['D']*1.3, cat='Continuous')
decision_variables.append(variable)
#### Define Objective Function
total_cost = ""
for rownum, row in data.iterrows():
for i, variable in enumerate(decision_variables):
if rownum == i:
formula = variable * row['C'] * row['F'] / row['D']
total_cost += formula
prob += total_cost
print("Optimization Function: " + str(total_cost))
#### Define Constraints
problem_spend = ""
for rownum, row in data.iterrows():
for i, variable in enumerate(decision_variables):
if rownum == i:
formula = variable * variable * row['C'] * row['F'] * row['E'] / row['D']
problem_spend += formula
prob += (total_spend == problem_spend)
[ [ ] Getting the following error after running the ####Define constraints part: 'TypeError: Non-constant expressions cannot be multiplied.' ]在运行#### Define约束部分后得到以下错误:'TypeError:非常数表达式不能相乘。 This might be because my constraints include non-linear variables. 这可能是因为我的约束条件包括非线性变量。
My Objective function is linear: formula : Maximize[Variable * constant] 我的Objective函数是线性的:公式:Maximize [Variable * constant]
My Constraints are Quadratic: formula : [Variable * Variable * Constant == Constant_Value] 我的约束是二次方的:公式:[变量*变量*常数==常数值]
I am new to PULP and am facing difficulty with this error. 我是PULP的新手,并且遇到此错误遇到的困难。 Is there any way I could use CVXPy to solve it or some other way? 有什么方法可以使用CVXPy或其他方法解决?
Pulp can't formulate or solve QP problems I suggest you either use CVXpy, Gurobi, or Cplex; 纸浆无法制定或解决QP问题。我建议您使用CVXpy,Gurobi或Cplex。 or reformulate the problem to use linear constraints 或重新制定问题以使用线性约束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.