我正在使用 cplex 在 python/java 中解决纯网络流问题(最小成本流模型)。因此,我明确告诉 cplex 使用网络算法(即
lpmethod = network = 3
)。然而,在模型求解后,我要求 cplex 告诉我它使用什么算法来产生解决方案,它告诉我它是对偶单纯形(即,lpmethod = dual = 2
)。我知道,当我调用网络算法时,cplex 会提取一个嵌入式网络以使用网络优化器,然后它使用该解决方案构建要通过单纯形优化器解决的完整 LP 问题的起始基础。然而,我提供了一个纯粹的网络流模型,因此不需要提取,并且在找到网络解决方案后绝对不需要重建到 lp 基础。
Cplex 告诉我,我可以仅使用 C 可调用库来克服这一步。不过,我正在使用 .NET、Python 和 Java 库。
如果我提供纯网络模型并且想使用Java库,如何避免在获得真实解决方案后提取网络并重建基础的额外时间?
我正在使用具有数百万个变量的大型网络,但尝试了较小规模的东西。例如,我正在使用 cplex python 示例
lpex3.py
:
import cplex
c = cplex.Cplex()
c.parameters.simplex.display.set(2)
c.parameters.read.datacheck.set(1)
c.linear_constraints.add(senses="EEEEEEE",
rhs=[-1.0, 4.0, 1.0, 1.0, -2.0, -2.0, -1.0])
flow = [[[1, 6], [1.0, -1.0]],
[[2, 6], [1.0, -1.0]],
[[3, 6], [1.0, -1.0]],
[[2, 5], [1.0, -1.0]],
[[3, 5], [1.0, -1.0]],
[[1, 4], [1.0, -1.0]],
[[2, 4], [1.0, -1.0]],
[[0, 1], [-1.0, 1.0]],
[[0, 2], [-1.0, 1.0]],
[[0, 3], [1.0, -1.0]],
[[4, 5], [-1.0, 1.0]],
[[4, 6], [1.0, -1.0]]]
# lower bounds are set to their default value of 0.0
c.variables.add(obj=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 0.0, 0.0, 0.0, 2.0, 2.0],
ub=[50.0] * 12, columns=flow)
c.parameters.lpmethod.set(c.parameters.lpmethod.values.network) # Here I set the algorithm to network
c.solve()
print("After network optimization, objective is ", c.solution.get_objective_value())
print("Algorithm used: ", c.solution.get_method()) # Here I ask for the algorithm used to produce the solution.
但是,输出是
CPXPARAM_Simplex_Display 2
CPXPARAM_Read_DataCheck 1
CPXPARAM_LPMethod 3
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time = 0.00 sec. (0.01 ticks)
Extracted network with 7 nodes and 12 arcs.
Extraction time = 0.00 sec. (0.00 ticks)
Iteration log . . .
Iteration: 0 Infeasibility = 11.000000 (11)
Network - Optimal: Objective = 5.0000000000e+00
Network time = 0.00 sec. (0.00 ticks) Iterations = 6 (5)
After network optimization, objective is 5.0
Algorithm used: 2
显然,虽然问题是纯网络流模型,并且我调用了网络算法,并且不需要后处理,但使用的算法是对偶单纯形(值为2)。在一个小例子中,这可能并不重要,但是当在列生成中并行求解具有数百万个变量的多个网络模型时,每一秒都很重要。
嗨,Jorge Huertas,你能弄清楚吗?