1
$\begingroup$

I'm trying to represent the following problem with PuLP:
A car factory needs to maximize profit with an X amount of car models. Each car model has an individual profit and a manufacturing limit, and there is a limit on how many cars can be produced in total. They also sell a package with 3 cars of different models. The profit of a single package is bigger than the sum of the profit those 3 cars.

My question is how can I represent those packages in the objetive function and constraints? Should I represent them as a new decision variable? How could I control the constraints?

Example:
(car model, number of cars of that model that can be made, profit from 1 car of that model)
x1, 25, 45
x2, 32, 27
x3, 28, 43
x4, 35, 37
x5, 34, 33
Let's say there is a package that contains x2, x3, x4 and the profit of selling a single package is 125$.
The number of cars (total) that be produced are 140.

The code below represents the example but without the packages

from pulp import *

# Problem
prob = LpProblem("myProblem", LpMaximize)

# Decision variables
x1 = LpVariable(name="x1", lowBound=0, upBound=25, cat='Integer')
x2 = LpVariable(name="x2", lowBound=0, upBound=32, cat='Integer')
x3 = LpVariable(name="x3", lowBound=0, upBound=28, cat='Integer')
x4 = LpVariable(name="x4", lowBound=0, upBound=35, cat='Integer')
x5 = LpVariable(name="x5", lowBound=0, upBound=34, cat='Integer')

# Objective function
prob += lpSum(
    + 45*x1
    + 27*x2
    + 43*x3
    + 37*x4
    + 33*x5
)

# Restrictions
prob += x1 + x2 + x3 + x4 + x5 <= 140

# Solution
status = prob.solve(PULP_CBC_CMD (msg=False))
print(value(prob.objective))

I'm new here so excuse me if this post isn't in the right format or was cryptic in any way.

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes, you can model each package with a new decision variable. For your example, introduce $x_{234}$ with objective coefficient $125$ and constraint coefficient $3$ because that package uses $3$ cars from the total allotment of $140$: $$x_1 + x_2 + x_3 + x_4 + x_5 + 3 x_{234} \le 140$$ To account for packages, you also need an explicit constraint for each model, rather than just an upper bound on a variable. For example, the constraint for model 2 becomes $x_2 + 3x_{234} \le 32$.

$\endgroup$
4
  • $\begingroup$ Thanks for answering! Understood the part about the objective coeffiecient and the constraint for the models but didn't understand really how to apply the constraint coefficent. $\endgroup$
    – user13035
    Commented Dec 30, 2023 at 19:47
  • $\begingroup$ @sneed_master I made that part more explicit just now. $\endgroup$
    – RobPratt
    Commented Dec 30, 2023 at 19:51
  • $\begingroup$ Thank you so much for answering! $\endgroup$
    – user13035
    Commented Dec 30, 2023 at 19:53
  • $\begingroup$ Glad to help, and welcome to ORStackExchange! Note my correction made just now: both constraints need coefficient $3$ to correctly count the number of cars. $\endgroup$
    – RobPratt
    Commented Dec 30, 2023 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.