pythonproductionpulpmaximization

Production Maximization with Pulp


I am trying to solve a maximization problem using pulp in python. The problem is very simple, I have a demand and I want to maximize production. Production must be at least equal to the demand and the problem should also take into consideration the time required for production.

Here is the code:

# Declaring variables
A1 = pulp.LpVariable("Ciclo_A1", lowBound=0, cat='Integer')
A2 = pulp.LpVariable("Ciclo_A2", lowBound=0, cat='Integer')
A3 = pulp.LpVariable("Ciclo_A3", lowBound=0, cat='Integer')
A4 = pulp.LpVariable("Ciclo_A4", lowBound=0, cat='Integer')
A5 = pulp.LpVariable("Ciclo_A5", lowBound=0, cat='Integer')
P_XB = pulp.LpVariable("Produzione_XB", lowBound=0, cat='Integer')
P_XP = pulp.LpVariable("Produzione_XP", lowBound=0, cat='Integer')
P_XC = pulp.LpVariable("Produzione_XC", lowBound=0, cat='Integer')
Scorte_XB = pulp.LpVariable("Storage_XB", lowBound=0, cat='Integer')
Scorte_XP = pulp.LpVariable("Storage_XP", lowBound=0, cat='Integer')
Scorte_XC = pulp.LpVariable("Storage_XC", lowBound=0, cat='Integer')
Totale_Cicli = pulp.LpVariable("Time_required", lowBound=0, cat='Integer')

# Defining the problem as a maximization problem (Production must be at least equal to the one of the day before)
problem_2 = pulp.LpProblem("Production_Maximization", pulp.LpMaximize)

# Setting up variables
# Defining the demand for each cylinder (same as before)
D_XB, D_XP, D_XC = demand(groupedby_tipo_data_min)

# Defining quantities produced (supply) by each cycle for all cylinders
P_XB, P_XP, P_XC = supply(Cicli)

# Defining total time taken by each cycle to produce the danded quantity of cylinders, time is in minutes   
Totale_Cicli = time_required(Cicli)

# Defining storage 
Scorte_XB, Scorte_XP, Scorte_XC = storage(P_XB, P_XP, P_XC, D_XB, D_XP, D_XC)

# The Objective function
problem_2 += P_XB + P_XP + P_XC # I want to maximize production but I don't want to produce more than the requested quantity

# Constraints: Time constraint present
problem_2 += P_XB >= D_XB # my production must be at least equal to the demand
problem_2 += P_XP >= D_XP
problem_2 += P_XC >= D_XC
problem_2 += Totale_Cicli <= Tempo_disponibile
problem_2 += A1 >= 0
problem_2 += A2 >= 0
problem_2 += A3 >= 0
problem_2 += A4 >= 0
problem_2 += A5 >= 0

# Solving the problem
status = problem_2.solve()   # Solver

If I solve the problem with the time constraint I get some strange numbers for the cycles (-38.378) and the problem status is Infeasible. Because of this I tried solving the problem without the time constraint. What I get as result is 0 for the cycles and the problem is Unbounded.

I solved this by removing the constraints on production that were overwritting my objective function.

Now I have a similar problem with the maximization of production for two days. In particular the production must be at least equal to the demand of the first day and not greater than the demand of the second day.

The definition of the problem is the same as the one above, the constraints are:

# Constraints: Time constraint present 
problem_4 += P_XB >= D0_XB # supply must be at least equal to the demand of the day before, but as close as possible to the total demand
problem_4 += P_XP >= D0_XP
problem_4 += P_XC >= D0_XC
problem_4 += Totale_Cicli <= Tempo_disponibile
problem_4 += A1 >= 0
problem_4 += A2 >= 0
problem_4 += A3 >= 0
problem_4 += A4 >= 0
problem_4 += A5 >= 0

The thing is that it always exceeds production of the second day. I tried putting other constraints but then the problem becomes Infeasible. Can I set an UpperBound for P_XB, P_XP and P_XC?

Thanks, Carlotta.


Solution

  • I solved the problem removing the constraints reguarding production.

    Here are the constraints:

    # Constraints: Time constraint present
    problem_2 += P_XB >= D_XB # my production must be at least equal to the demand
    problem_2 += P_XP >= D_XP
    problem_2 += P_XC >= D_XC
    problem_2 += Totale_Cicli <= Tempo_disponibile
    problem_2 += A1 >= 0
    problem_2 += A2 >= 0
    problem_2 += A3 >= 0
    problem_2 += A4 >= 0
    problem_2 += A5 >= 0