0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CBCでのlpファイルからの最適化

Posted at

CBCソルバーでlpファイルからモデルを読み込んで最適化してみます。

sample1.lp
Maximize
 obj: 2 x2 + 3 x3
Subject To
 c1: x2 + x3 - x1 <= 20
 c2: - 3 x2 + x3 + x1 <= 30
Bounds
 0 <= x1 <= 40
 0 <= x2
 0 <= x3
End

コマンドの形式は以下です。

コマンド形式
cbc.exe <lpファイル名> <オプション> solve solu <結果ファイル名>

以下の例ではsample1.lpからモデルを読み込みratioGap(相対ギャップ)50%で実行をし、結果をsolution.txtに出力しています。

コマンド例
cbc.exe sample1.lp ratioGap 0.5 solve solu solution.txt

以下は実行log例です。cbcはpulpで導入されたものを使いました。

実行ログ
command line - C:\Users\xxxx\Downloads\pulp-master\pulp-master\pulp\solverdir\cbc\win\64\cbc.exe sample1.lp ratioGap 0.5 solve solu solution.txt (default strategy 1)
 CoinLpIO::readLp(): Maximization problem reformulated as minimization
Coin0009I Switching back to maximization to get correct duals etc
ratioGap was changed from 0 to 0.5
Presolve 2 (0) rows, 3 (0) columns and 6 (0) elements
0  Obj 0 Dual inf 4.9999998 (2)
0  Obj 0 Dual inf 4.9999998 (2)
3  Obj 162.5
Optimal - objective value 162.5
Optimal objective 162.5 - 3 iterations time 0.002
Total time (CPU seconds):       0.00   (Wallclock seconds):       0.00

経過時間(elapsedTime)は約0.00秒です。

ソリューションはsolution.txtに出力されました。

solution.txt
Optimal - objective value 162.50000000
      0 x2                  17.5                      -0
      1 x3                  42.5                      -0
      2 x1                    40                     2.5

目的関数は162.5です。
決定変数は以下です。

変数名
x1 40
x2 17.5
x3 42.5

サンプルファイル

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?