0

I am stuck with a problem in Integer Programming constraint using PULP in python. I have 2 variables x1, x2 and a constant y. How do i write a constraint on x1 = min(x2 ,y1).

I have written below two condition: x1 < y1;

x1 < x2

But it is giving me x1 = 0 for my problem. It should take one of the values from x2 and y1

Thanks in advance. Will really appreciate your help.

Code used:

*import pandas as pd
from pulp import *

data = pd.read_csv("Test.csv")
limit = LpVariable("limit",0, 1000, cat='Integer')
sales = LpVariable.dicts("Sales", (i for i in data.index), lowBound=0,  cat="Integer")

####### Defining the Problem
prob = pulp.LpProblem("Profit", pulp.LpMaximize)
prob += pulp.lpSum((1-data.loc[i,'Prize']) * sales[i] for i in data.index)

####### Constraints
for idx in data.index:
    max_sales = data.loc[idx, 'Sales'] + data.loc[idx, 'Rejec']
    prob += sales[idx] <= max_sales
    prob += sales[idx] <= limit

###### Getting the output    
prob.solve()
for v in prob.variables():
    print v.name,v.varValue

print value(prob.objective)

Data Used (try.csv) enter image description here

  • You should show your code. –  Sep 07 '17 at 16:52
  • Edited the Question with the code and the data... Hope it helps. – Rahul Kataria Sep 07 '17 at 17:14
  • Does https://stackoverflow.com/q/36245856/1531971 help? –  Sep 07 '17 at 17:15
  • No.. this the above is not helpful.. as i am maximizing my profit and the optimized sales takes value of 0 where prize >0 but it should take one value - either limit or sales.. that is is the reason I want to put a condition that optimized sales should be min of sales and limit and not less than equal to sales and limit – Rahul Kataria Sep 08 '17 at 12:03
  • Comments like that should be in the body of the question. –  Sep 08 '17 at 15:45

0 Answers0