Eşitsizlik kısıtlarıyla dışbükey kısıtlı optimizasyon

Python ile Optimizasyona Giriş

Jasmin Ludolf

Content Developer

Köşe ve iç çözüm

  • Alexia'nın yalnızca 5 saatlik işi var

$$ w\leq 5$$

  • İki kısıt:
    • Günde 24 saat
    • 5 saat iş
  • Kısıtlar bir köşe oluşturur
  • İç çözüm bir kesişim değildir

Kayıtsızlık eğrileri ve kısıtlar. En iyi fayda düzeyindeki kayıtsızlık eğrisi, kısıtların kesişiminden geçer.

Python ile Optimizasyona Giriş

Kapasite kısıtlı üretici

  • Otomobil üreticisi aynı araçları iki tesiste üretir: $A$, $B$
    • Miktarlar: $q_A$, $q_B$
    • Kapasite: $q_A\leq 90$, $q_B\leq 90$
    • Maliyet: $C_A(q)=3q$, $C_B(q)=3.5q$
  • Talep:
    • $P=120-Q$
  • Sözleşme:
    • $Q\geq 92$
  • Amaç: kârı maksimize etmek
    • $\displaystyle\max \Pi(q_A,q_B)$

Araba üretim hattı

Python ile Optimizasyona Giriş

Kârı maksimize etme

  • Amaç:
    • $\Pi = R-C$
      • $R = PQ$
Python ile Optimizasyona Giriş

Kârı maksimize etme

  • Amaç:
    • $\Pi = R-C$
      • $R = PQ = (120-Q)Q $
Python ile Optimizasyona Giriş

Kârı maksimize etme

  • Amaç:

    • $\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$
  • Sınırlar

    • $0\leq q_A, q_B\leq 90$
  • Kısıtlar
    • $Q\geq92\Leftrightarrow 92\leq q_A+q_B$
Python ile Optimizasyona Giriş

Formülasyon

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

$$k.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 ile Optimizasyona Giriş

SciPy ile kârı maksimize etme

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 ile Optimizasyona Giriş

SciPy'de doğrusal olmayan kısıtlar

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 ile Optimizasyona Giriş

NonlinearConstraint ile çözüm

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 
  • Doğrusal, basit problemler için LinearConstraint() kullanın
  • Diğer durumlarda NonlinearConstraint() kullanın
Python ile Optimizasyona Giriş

Hadi pratik yapalım!

Python ile Optimizasyona Giriş

Preparing Video For Download...