Niet-lineaire problemen transformeren

Introductie tot optimalisatie in Python

Jasmin Ludolf

Content Developer

Maximaliseer een niet-lineaire functie

  • Kunstenaar maakt tot 16 schilderijen met kosten $C(q) = \sqrt q$ waarbij $q$ de hoeveelheid is
  • Omgekeerde vraag is $p=\frac{3}{\sqrt q}$ waarbij $p$ de prijs is
  • $\max \Pi = pq - C=\frac{3}{\sqrt q}q-\sqrt q = 2\sqrt q$

$$\max 2\sqrt q$$

$$s.t. \ \ \ \ q\leq 16 $$

Vrouw die op een canvas schildert

Introductie tot optimalisatie in Python

SciPy of PuLP?

  • SciPy: milp verwacht een lineair doel
  • PuLP:
model = LpProblem('Artist', LpMaximize)
q = LpVariable('q', lowBound=0, upBound=16)
model += 2 * q**(1/2)
--> 3 model += 2 * q**(1/2)

TypeError: unsupported operand type(s) for ** or pow(): 'LpVariable' and 'float'
Introductie tot optimalisatie in Python

Substitueren om te linearizeren

  • Vervang $z = \sqrt q$
  • $\rightarrow$ $\Pi=2\sqrt q =2z$
  • $\rightarrow$ capaciteitsrestrictie $z^2\leq 16\Leftrightarrow z\leq 4$
model = LpProblem('Artist', LpMaximize)
z = LpVariable('z', lowBound=0, upBound=4, cat='Integer')
model += 2 * z

model.solve() print(f"Solution is {LpStatus[model.status]}.") print(f"The optimal number of paintings is {round(z.varValue**2)}.")
Solution is Optimal. 
The optimal number of paintings is 16.
Introductie tot optimalisatie in Python

Investeringsselectie met afhankelijke projecten

Probleemstelling

  • Projecten $A$, $B$, $C$; $A$ is een vereiste voor $B$
  • Winsten zijn respectievelijk $V$ = [250, 200, 300]
  • Benodigde investering is $I$ = [2000, 1900, 2500] en er is slechts $4600 beschikbaar

Modelleerkeuzes

  • $o_A$, $o_B$, $o_C$ binaire variabelen; geven projectkeuze aan

$\max\ \ o_AV_A + o_Ao_BV_B + o_CV_C$

$s.t.\ \ \ \ o_AI_A + o_Ao_BI_B + o_CI_C\leq 4600$

Pictogram budgetbeheer

Introductie tot optimalisatie in Python

Linearisatie: product van binairen

  • Vervang $o_Ao_B=o_{AB}$
  • Voeg restricties toe
    • $o_{AB}\leq o_{A}$
    • $o_{AB}\leq o_{B}$
    • $o_{AB}\geq o_{A} + o_{B} -1$
  • Probleem wordt

$$\max\ \ o_AV_A + o_{AB}V_B + o_CV_C$$

$$s.t.\ \ \ \ o_AI_A + o_{AB}I_B + o_CI_C\leq 4600$$

$$ o_{A} + o_{B} -1 \leq o_{AB}\leq o_{A}, o_{B}$$

Introductie tot optimalisatie in Python

Resource-allocatie met trainingskosten

  • Wijs 120 taken toe om kosten te minimaliseren
  • Senior ($S$), junior ($J$) en stagiair ($I$)
  • Trainingskosten stagiair $500
  • Kosten per taak $c$ = [30, 40, 5]
  • Vector $x$: optimaal toegewezen taken
  • Binair $o$: of de stagiair training krijgt
  • $TC = 30x_S+40x_J+(5x_I+500)o$

Persoon met potlood naast grote takenlijst

Introductie tot optimalisatie in Python

Linearisatie: product van binair en continu

  • Big-M-methode introduceert een groot getal M
  • Vervangt het product door $z = (5x_I+500)o$
  • Legt op
    • $-oM\leq z \leq oM$
    • $-(1-o)M \leq z- (5x_I+500)o \leq (1-o)M$
Introductie tot optimalisatie in Python

Laten we oefenen!

Introductie tot optimalisatie in Python

Preparing Video For Download...