![](/img/trans.png)
[英]How to solve a linear program with only constraints and no objective function using pulp?
[英]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)
[ ]在運行#### Define約束部分后得到以下錯誤:'TypeError:非常數表達式不能相乘。 這可能是因為我的約束條件包括非線性變量。
我的Objective函數是線性的:公式:Maximize [Variable * constant]
我的約束是二次方的:公式:[變量*變量*常數==常數值]
我是PULP的新手,並且遇到此錯誤遇到的困難。 有什么方法可以使用CVXPy或其他方法解決?
紙漿無法制定或解決QP問題。我建議您使用CVXpy,Gurobi或Cplex。 或重新制定問題以使用線性約束
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.