我试图通过将其公式化为(整数)线性问题来优化时间表。我在编码部分遇到了一些问题(主要是由于纸浆),这与配方完全不同。
问题:
附表 n 船舶,为期 5 年(时间步长以月为单位),受以下限制:
- 每月只有一艘船必须在“本地巡逻”(状态 = 'C')
- 每年只有一艘船必须进行“扩展巡逻”(状态 = 'A'),即从 7 月到 10 月的四个月时间段
- 每艘船必须在 5 年内进行一次为期 4 个月的检查(状态 = '4')
- 每艘船在 5 年期间必须有 8 个月的休息时间(状态 = '8')
- 每艘船必须大约每 5 个月进行一次定期维护(状态 = 'M')
- 一艘船在给定月份只能处于一种状态,但它也可以没有状态(开放/空置,'_')
目标函数公式:
定义计算计划偏离 5 个月 ('M') 维护计划的次数(和数量)的松弛变量。
如果需要,我可以更多地解释设置,但现在我有一些基本问题可能是我的问题的根源。
这是我的限制之一(blockList 存储每艘船的 4 个月和 8 个月块的开始):
# Each ship must have one 8block and one m4block in a 5 year schedule, which must be between 2 and 3 years apart
for n in ship_list:
prob += blockList[n][0] - blockList[n][1] >= 24
prob += blockList[n][0] - blockList[n][1] <= 36
我想取上述表达式的LHS的绝对值,但我不能,因为对象被初始化为pulp.LpVariable。任何解决方法的建议?
Anyways, that may or may not fix my problem. If it doesn't, my next question is for anyone familiar with pulp. How can I know if the solution true, or if there was some sort of elasticity added by the solver in the background? (Running the code as is with that constraint gives incorrect results, and using a different solver like GLPK gives an error).