纸浆生产最大化

2024-09-23 14:32:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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的上限吗

谢谢, 卡洛塔


Tags: thetointegerxppulpcatproblemxc
1条回答
网友
1楼 · 发布于 2024-09-23 14:32:28

我解决了这个问题,消除了限制生产的因素

以下是限制条件:

# 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

相关问题 更多 >