1
1

More than 1 year has passed since last update.

【Python】PuLPの最適化問題備忘録

Posted at

PuLPをインストールする

pip install pulp
import pulp

#最適化問題のインスタンスを作成します。
problem = pulp.LpProblem("MyOptimizationProblem", pulp.LpMinimize)
#変数を作成します。変数は問題の中で最適化される値を表します。
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
#目的関数を定義します。目的関数は最小化または最大化したい式です。
problem += 2*x + 3*y
#制約条件を追加します。
problem += x + y <= 10
problem += x - y >= 1
#最適化問題を解きます。
problem.solve()
#解を取得します。
print("Optimization status:", pulp.LpStatus[problem.status])
print("Optimal solution:")
print("x =", pulp.value(x))
print("y =", pulp.value(y))
print("Objective value =", pulp.value(problem.objective))

まとめ

今回は、数値最適化ライブラリPuLPの簡単な使い方を紹介した

1
1
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
1
1