Why Python import gurobipy MIP import SCOP CP
Why Python? • モジュールを読み込めば何 でもできる! • 最適化もできる! import gurobipy (MIP) import SCOP (CP) • グラフも描ける! import network. X import matplotlib • 空を飛ぶことも!? import antigravity ? http: //xkcd. com/353 / http: //www. logopt. com/ mikiokubo/に 20分の入門ビデオ
Pythonでの実装(2) for j in range(n): y[j]=model. add. Var(obj=0, vtype=“B”, name="y"+str(j)) for i in range(n): x[i, j]=model. add. Var(obj=cost[i, j], vtype=“B”, name="x"+str(i)+str(j)) model. update()
Pythonでの実装(3) for i in range(n): L=Lin. Expr() #線形表現オブジェクト L を空で作成 for j in range(n): L. add. Terms(1, x[i, j]) #線形表現オブジェクトに項を追加 model. add. Constr(lhs=L, sense= " = ", rhs=1, name="Demand"+str(i)) 線形表現(Linear Express) クラス Lin. Expr
Pythonでの実装(5) import networkx as NX #network. Xモジュールの読み込み import matplotlib. pyplot as P #描画の準備 P. ion() G = NX. Graph() #グラフオブジェクトGの生成 G. add_nodes_from(range(n)) #点の追加 for (i, j) in edge: #グラフに枝を追加 G. add_edge(i, j) NX. draw(G) #描画
弱い定式化での結果 n=200, k=20 Optimize a model with 401 Rows, 40200 Columns and 80400 Non. Zeros 中略 Explored 1445 nodes (63581 simplex iterations) in 67. 08 seconds Thread count was 2 (of 2 available processors) Optimal solution found (tolerance 1. 00 e-04) Best objective 1. 0180195861 e+01, best bound 1. 0179189780 e+01, gap 0. 0099% Opt. value= 10. 1801958607
強い定式化での結果 Optimize a model with 40401 Rows, 40200 Columns and 160400 Non. Zeros 中略 Explored 0 nodes (1697 simplex iterations) in 3. 33 seconds (分枝しないで終了!) Thread count was 2 (of 2 available processors) Optimal solution found (tolerance 1. 00 e-04) Best objective 1. 0180195861 e+01, best bound 1. 0180195861 e+01, gap 0. 0% Opt. value= 10. 1801958607
Miller-Tucker-Zemlinの定式化
結果 Optimize a model with 6480 Rows, 6400 Columns and 37762 Non. Zeros 中略 Cutting planes: Gomory: 62 Implied bound: 470 MIR: 299 Zero half: 34 Explored 125799 nodes (2799697 simplex iterations) in 359. 01 seconds Optimal solution found (tolerance 1. 00 e-04) Best objective 7. 4532855108 e+00, best bound 7. 4525704995 e+00, gap 0. 0096% Opt. value= 7. 45328551084
上界と下界の変化(原定式化) 点数 n=40,彩色数上限 Kmax=10 Optimize a model with 3820 Rows, 410 Columns and 11740 Non. Zeros Explored 17149 nodes (3425130 simplex iterations) in 1321. 63 seconds
上界と下界の変化(対称性除去) Optimize a model with 3829 Rows, 410 Columns and 11758 Non. Zeros Explored 4399 nodes (1013290 simplex iterations) in 384. 53 seconds MIPFocus=2(最適性保証優先) で 67秒,MIPFocus=3(下界優先) で 70秒
上界と下界の変化(+SOS) Optimize a model with 3829 Rows, 410 Columns and 11758 Non. Zeros. Explored 109 nodes (58792 simplex iterations) in 22. 02 seconds MIPFocus=2(最適性保証優先) で 65秒,MIPFocus=3(下界優先) で 126秒
- Slides: 46