1

I was trying to optimize the following problem using python pulp

import pulp
# Instantiate our problem class
model = pulp.LpProblem("Cost minimising problem", pulp.LpMinimize)

W = pulp.LpVariable('W', cat='Integer')
X = pulp.LpVariable('X', cat='Integer')
Y = pulp.LpVariable('Y', cat='Integer')
Z = pulp.LpVariable('Z', cat='Integer')

# Objective function
model += 1.33 * W + 1.76 * X + 1.46 * Y + 0.79 * Z,"Cost"

# Constraints
model += W + X + Y + Z == 1

 model += W >= 0.1
 model += W <= 0.75

 model += X >= 0.1
 model += X <= 0.85

 model += Y >= 0.1
 model += Y <= 0.65

 model += Z >= 0.1
 model += Z <= 0.40


# Solve our problem
model.solve()
pulp.LpStatus[model.status]

'Undefined'

The solution turns out to be undefined. Am I making a mistake in problem formulation or missing out something ?

user6016731
  • 382
  • 5
  • 18

1 Answers1

1

When I implement the same code I get the result 'Infeasible'.

This makes sense as your variables W, X, Y, Z all have to be integers, but you then bound them to be more than 0.1, and less than another number which is less than 1.

There are no integers inbetween 0.1 and 0.XX, so there is no feasible solution.

kabdulla
  • 5,199
  • 3
  • 17
  • 30
  • Thanks that works but is there a way in PulP to not specify as integer . Like when I solve the same using excel solver I get values like 32.567 ,38.9867 etc. Can that be achieved using PulP ? – user6016731 Feb 11 '20 at 10:08
  • Replace `cat='Integer'` with `cat='Continuous'`. See https://www.coin-or.org/PuLP/pulp.html#pulp.LpVariable – kabdulla Feb 11 '20 at 13:48