简体   繁体   English

如何使用Pulp解决以下LP / QP问题?

[英]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.

相关问题 如何使用纸浆解决只有约束而没有目标函数的线性程序? - How to solve a linear program with only constraints and no objective function using pulp? 求解时如何求出纸浆LP求出的值? - How to find out the value the pulp LP found when solving? 纸浆:如何构造这个工厂覆盖率问题 - PuLP: How to structure this factory coverage problem 如何将 OR 条件纳入纸浆优化问题? - How to incorporate OR condition into pulp optimization problem? 如何使用递归函数解决这个问题 - How to solve this problem by using recursive function 如何在PuLP问题中仅访问特定变量? - How do I access only specific variables in a PuLP problem? 我一直在尝试应用fuzzywuzzy包来解决查找欺诈条目的问题。 我如何在以下问题中应用相同的内容? - I have been trying to apply fuzzywuzzy package to solve a problem to find fraud entries. How do i apply the same in the following problem? 我们如何求解具有范围条件约束的纸浆 python 的线性方程 - how can we solve the linear equation with pulp python with range conditonal constraint 使用纸浆 python 进行优化 - Optimization using pulp python 如何使用 venv 解决 Python 3.7.2 中的多处理停止工作问题 - How to solve multiprocessing stop working problem in Python 3.7.2 using venv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM