不等式制約付きの凸制約最適化

Pythonで学ぶOptimization入門

Jasmin Ludolf

Content Developer

コーナー解と内点解

  • アレクシアは労働が5時間だけ

$$ w\leq 5$$

  • 制約は2つ:
    • 1日は24時間
    • 労働は5時間
  • 制約はコーナーを形成
  • 内点解は交点ではない

無差別曲線と制約。最適効用の無差別曲線は制約の交点を通る。

Pythonで学ぶOptimization入門

生産能力制約のあるメーカー

  • 自動車メーカーは同一車種を2工場 $A$, $B$ で生産
    • 生産量: $q_A$, $q_B$
    • 能力: $q_A\leq 90$, $q_B\leq 90$
    • 費用: $C_A(q)=3q$, $C_B(q)=3.5q$
  • 需要:
    • $P=120-Q$
  • 契約:
    • $Q\geq 92$
  • 目的: 利潤最大化
    • $\displaystyle\max \Pi(q_A,q_B)$

自動車の生産ライン

Pythonで学ぶOptimization入門

利潤最大化

  • 目的:
    • $\Pi = R-C$
      • $R = PQ$
Pythonで学ぶOptimization入門

利潤最大化

  • 目的:
    • $\Pi = R-C$
      • $R = PQ = (120-Q)Q $
Pythonで学ぶOptimization入門

利潤最大化

  • 目的:

    • $\Pi = R-C$
      • $R = PQ = (120-Q)Q=\left[120-(q_A+q_B)\right](q_A+q_B)$
      • $C=C_A+C_B=3q_A+3.5q_B$
  • 境界

    • $0\leq q_A, q_B\leq 90$
  • 制約
    • $Q\geq92\Leftrightarrow 92\leq q_A+q_B$
Pythonで学ぶOptimization入門

定式化

$$\max_{q_A,q_B}R(q_A,q_B)-C(q_A,q_B)$$

$$s.t.$$

$$R(q_A,q_B)=\left[120-(q_A+q_B)\right](q_A+q_B)$$

$$\ \ \ \ \ C(q_A,q_B)=3q_A+3.5q_B$$

$$\ \ \ 0\leq q_A, q_B\leq 90$$

$$ \ \ \ \ 92\leq q_A+q_B$$

from scipy.optimize import minimize,\
        Bounds, LinearConstraint


def R(q): return (120 - (q[0] + q[1] )) * (q[0] + q[1])
def C(q): return 3*q[0] + 3.5*q[1]
def profit(q): return R(q) - C(q)
bounds = Bounds([0, 0], [90, 90])
constraints = LinearConstraint([1, 1], lb=92)
Pythonで学ぶOptimization入門

SciPyで利潤最大化

result = minimize(lambda q: -profit(q),

[50, 50],
bounds=bounds, constraints=constraints)
print(result.message) print(f'The optimal number of cars produced in plant A is: {result.x[0]:.2f}') print(f'The optimal number of cars produced in plant B is: {result.x[1]:.2f}') print(f'The firm made: ${-result.fun:.2f}')
Optimization terminated successfully
The optimal number of cars produced in plant A is: 90.00
The optimal number of cars produced in plant B is: 2.00
The firm made: $2299.00
Pythonで学ぶOptimization入門

SciPyの非線形制約

from scipy.optimize import NonlinearConstraint 
import numpy as np


constraints = NonlinearConstraint(lambda q: q[0] + q[1], lb=92, ub=np.inf)
result = minimize(lambda q: -profit(q), [50, 50], bounds=Bounds([0, 0], [90, 90]), constraints=constraints)
Pythonで学ぶOptimization入門

NonlinearConstraintによる解

print(result.message)
print(f'The optimal number of cars produced in plant A is: {result.x[0]:.2f}')
print(f'The optimal number of cars produced in plant B is: {result.x[1]:.2f}')
print(f'The firm made: ${-result.fun:.2f}') 
Optimization terminated successfully
The optimal number of cars produced in plant A is: 90.00
The optimal number of cars produced in plant B is: 2.00
The firm made: $2299.00 
  • 線形の単純な問題にはLinearConstraint()を使用
  • それ以外はNonlinearConstraint()を使用
Pythonで学ぶOptimization入門

演習に進みましょう!

Pythonで学ぶOptimization入門

Preparing Video For Download...