LoginSignup
0
0

More than 5 years have passed since last update.

〜備忘録〜 SCIPを使って問題を解いてみる

Last updated at Posted at 2017-11-10

実行するにあたっての前提の環境

scipoptsuite-4.0.0がインストールされている。
ターミナル
〜備忘録〜 SCIP scipoptsuite-4.0.0をMacにインストール

実行手順

ターミナル上でscipを起動する

MacBook-Pro:local user$ scip

すると、

SCIP>

このような表示に変わる。

輸送問題を記述したmondai.lpというファイルを読み込む。

lpファイルの作り方メモ

lpファイルの作り方はまずテキストエディタなどで編集してから拡張子を.txt→.lpに変更するだけ。

因みにmondai.lpの中身、輸送問題を定式化したものは以下のものになる。

minimize
obj: x(a1,b1) + 5 x(a1,b2) + 6 x(a2,b2) + 5 x(a2,b3)
+ 2 x(a3,b2) + 4 x(a3,b3)
subject to
const(a1): x(a1,b1) + x(a1,b2) <= 5
const(a2): x(a2,b2) + x(a2,b3) <= 4
const(a3): x(a3,b2) + x(a3,b3) <= 7
const(b1): x(a1,b1) >= 1
const(b2): x(a1,b2) + x(a2,b2) + x(a3,b2) >= 5
const(b3): x(a2,b3) + x(a3,b3) >= 10
end

である。

メモ

minimize は予約語.最大化の場合は maximizeと書く

subject toは予約語であり、ここから後ろに制約式を書く

制約式を書くときは、(制約名)+コロン +制約式
制約名は任意で変えられる(c(1),c(2)などでもよい)

endは予約語でファイルの最後に書く

問題を解く

mondai.lpを読み込むためには、以下のreadコマンドを用いる。

SCIP> read /Users/user/Desktop/mondai.lp

読み込む際はデスクトップ上などにlpファイルを配置しておいてターミナル上にドラッグ&ドロップすると楽。

読み込むと、

original problem has 6 variables (0 bin, 0 int, 0 impl, 6 cont) and 6 constraints

と表示される。

次に最適化を実行するためにoptimizeコマンドを実行する

SCIP> optimize

すると、以下のように表示される。

presolving:
(round 1, fast) 1 del vars, 2 del conss, 0 add conss, 9 chg bounds, 0 chg sides, 0 chg coeffs, 0 upgd conss, 0 impls, 0 clqs
(round 2, fast) 3 del vars, 4 del conss, 0 add conss, 13 chg bounds, 0 chg sides, 0 chg coeffs, 0 upgd conss, 0 impls, 0 clqs
(round 3, exhaustive) 5 del vars, 4 del conss, 0 add conss, 13 chg bounds, 0 chg sides, 0 chg coeffs, 0 upgd conss, 0 impls, 0 clqs
presolving (4 rounds: 4 fast, 2 medium, 2 exhaustive):
6 deleted vars, 6 deleted constraints, 0 added constraints, 14 tightened bounds, 0 added holes, 0 changed sides, 0 changed coefficients
0 implications, 0 cliques
presolved problem has 0 variables (0 bin, 0 int, 0 impl, 0 cont) and 0 constraints
transformed objective value is always integral (scale: 1)
Presolving Time: 0.00

time | node | left |LP iter|LP it/n| mem |mdpt |frac |vars |cons |cols |rows |cuts |confs|strbr| dualbound | primalbound | gap

t 0.0s| 1 | 0 | 0 | - | 557k| 0 | - | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6.700000e+01 | 6.700000e+01 | 0.00%

SCIP Status : problem is solved [optimal solution found]
Solving Time (sec) : 0.00
Solving Nodes : 1
Primal Bound : +6.70000000000000e+01 (1 solutions)
Dual Bound : +6.70000000000000e+01
Gap : 0.00 %*

最後に変数ごとの値を表示するには

SCIP> display solution

とすると、

objective value: 67
x(a1,b1) 1 (obj:1)
x(a1,b2) 4 (obj:5)
x(a2,b3) 4 (obj:5)
x(a3,b2) 1 (obj:2)
x(a3,b3) 6 (obj:4)

と表示される。
ここで目的関数の最小値が67、そのときの各変数の値がわかる。
※メモ
67=1*1+4*5+4*5+1*2+6*4
ここでx(a2,b2)の値は0であるので無視されている。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0