CBCの2.8.0からmipstart optionが追加された 1ので,これを使います.
PULP_CBC_CMDに下のようにoptionを渡せばいいです.
prob.solve(PULP_CBC_CMD(options=["mips", "initialSolution.sol"]))
渡すsolutionファイルの形式はCBCが出力するsolutionファイルと同じです.
PuLpでは以下のようにすると出力されます2.
prob.solve(PULP_CBC_CMD(options=["solve", "solution", "initialSolution.sol"]))
ここで出力されたファイルを直接編集してもいいのですが,解を制約として与えた上でsolutionファイルを出力するようにするとそのまま使えて楽です.
例として以前解いたPC-FCTPに初期解を渡してみます
gist.github.com
出力されたsolutionファイル
結果
C:\Users\MitI_\Anaconda3\python.exe C:/Users/MitI_/IdeaProjects/untitled2/main2.py make initial solution Status:Infeasible Total Cost:13.0 solve Welcome to the CBC MILP Solver Version: 2.9.0 Build Date: Feb 12 2015 中略 Coin0008I MODEL read with 0 errors will open mipstart file .\initialSolution.sol. mipstart values read for 26 variables. Continuous objective value is 10.7778 - 0.00 seconds Cgl0004I processed model has 120 rows, 200 columns (200 integer (100 of which binary)) and 400 elements Cutoff increment increased from 1e-005 to 0.9999 Cbc0045I mipstart provided solution with cost 13 Cbc0038I Full problem 120 rows 200 columns, reduced to 40 rows 50 columns 中略 Result - Optimal solution found Objective value: 13.00000000 Enumerated nodes: 0 Total iterations: 90 Time (CPU seconds): 0.04 Time (Wallclock seconds): 0.04 Option for printingOptions changed from normal to all Total time (CPU seconds): 0.06 (Wallclock seconds): 0.06 Status:Optimal Total Cost:13.0 Assignment: Left:0 -> Right:4(8.0) Left:1 -> Right:1(6.0) Left:2 -> Right:3(7.0) Left:3 -> Right:2(10.0) Left:4 -> Right:0(11.0) Left:5 -> Right:6(13.0) Left:6 -> Right:8(6.0) Left:7 -> Right:4(2.0) Left:7 -> Right:5(11.0) Left:8 -> Right:1(5.0) Left:8 -> Right:7(9.0) Left:9 -> Right:8(3.0) Left:9 -> Right:9(9.0) 0sec
途中に「will open mipstart file .\initialSolution.sol.」と「Cbc0045I mipstart provided solution with cost 13」とあるのでちゃんと読めてそうです.
参考
-
なぜかStatusがInfeasibleになります.↩