부등식 제약이 있는 볼록 제약 최적화

Python으로 배우는 Optimization 입문

Jasmin Ludolf

Content Developer

모서리 해 vs 내부 해

  • 알렉시아는 작업 시간이 5시간뿐임

$$ w\leq 5$$

  • 두 가지 제약:
    • 하루는 24시간
    • 작업 5시간
  • 제약이 모서리를 형성
  • 내부 해는 교점이 아님

무차별곡선과 제약. 최적 효용의 무차별곡선이 제약의 교점을 지난다.

Python으로 배우는 Optimization 입문

용량 제약이 있는 제조업체

  • 자동차 회사는 두 공장 $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...