【发布时间】:2015-10-08 22:26:38
【问题描述】:
我在使用模块纸浆时遇到了一些问题。我想创建一个混合整数线性规划问题并将其写为 LP 文件。之后我用 cplex 解决它。
问题是当我添加第二个约束时,目标函数变为假(添加了虚拟)并且只添加了第一个约束,只有决策变量 x。
这是我的代码:希望你能帮帮我!
bay_model = pulp.LpProblem('Bay Problem', pulp.LpMinimize)
y = pulp.LpVariable.dicts(name = "y",indexs = (flight, flight, gates),
lowBound = 0, upBound = 1,cat = pulp.LpInteger)
x = pulp.LpVariable.dicts(name = "x",indexs = (flight,gates),lowBound = 0,
upBound = 1, cat=pulp.LpInteger)
bay_model += pulp.lpSum([x[i][j]*g.distance[j] for i in flight for j in gates])
for i in flight:
bay_model += pulp.lpSum([x[i][j] for j in gates]) == 1
print "flight must be assigned" + str(i)
for k in gates:
bay_model += [y[i][j][k] * f.time_matrix[i][j] for i in flight for j in flight if f.time_matrix[i][j] == 1] <= g.capacity[k]
bay_model += [(2 * y[i][j][k] - x[i][k] - x[j][k]) for i in flight for j in flight] == 0
print "time constraint" + str(k)
【问题讨论】:
-
你能给我一个关于航班和登机口外观的样本或样本值吗?
-
航班和登机口只是创建航班和登机口索引的范围。例如,当有 100 个航班时,航班 = 0,1,2 ... 99 或 xrange(100) 同样适用于登机口。我有强烈的感觉,问题出在 lp 文件的编写上。当我将它写入 MPS 时,它可以完美运行。