纸浆生产最大化

Production Maximization with Pulp

我正在尝试在 python 中使用纸浆解决最大化问题。 问题很简单,我有一个需求,我想最大化生产。产量至少要和需求量相等,问题还要考虑到生产所需的时间。

代码如下:

# 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

如果我在时间限制下解决问题,我会得到一些奇怪的周期数 (-38.378),并且问题状态为不可行。 因此,我尝试在没有时间限制的情况下解决问题。我得到的结果是循环为 0,问题是无限的。

我通过删除覆盖我的 objective 函数的生产约束解决了这个问题。

现在这两天生产最大化也遇到了类似的问题。 特别是产量必须至少等于第一天的需求并且不大于第二天的需求。

问题定义同上,约束条件为:

# 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

问题是它总是超过第二天的产量。我尝试设置其他约束,但问题变得不可行。 我可以为 P_XB、P_XP 和 P_XC 设置 UpperBound 吗?

谢谢, 卡洛塔.

我解决了消除生产限制的问题。

约束条件如下:

# 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