1
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)

[Dataframe] Getting the following error after running the ####Define constraints part: 'TypeError: Non-constant expressions cannot be multiplied.' This might be because my constraints include non-linear variables.

My Objective function is linear: formula : 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. Is there any way I could use CVXPy to solve it or some other way?

Nitish Gaddam
  • 101
  • 1
  • 11

1 Answers1

0

Pulp can't formulate or solve QP problems I suggest you either use CVXpy, Gurobi, or Cplex; or reformulate the problem to use linear constraints

Stuart Mitchell
  • 1,060
  • 6
  • 7