1

我正在尝试使用 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,问题是无界的。

我通过消除覆盖我的目标函数的生产约束来解决这个问题。

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

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

# 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 吗?

谢谢,卡洛塔。

4

1 回答 1

0

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

以下是约束:

# 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
于 2020-03-18T15:03:43.640 回答