Optimisation avec bornes

Introduction à l’optimisation en Python

Jasmin Ludolf

Content Developer

Optimisation avec bornes

 

  • Solveur par défaut : Broyden-Fletcher-Goldfarb-Shanno (BFGS)
  • La contrainte est un intervalle
  • Produire entre 50 et 100 unités par jour

 

from scipy.optimize import Bounds

bounds = Bounds(50, 100)
Introduction à l’optimisation en Python

L-BFGS-B

from scipy.optimize import minimize, Bounds

def objective_function(b):
  return (2*b[0] - 1.5*b[1])

bounds = Bounds([5, 10], [25, 30])
x0 = [10, 5] result = minimize(objective_function, x0, method='L-BFGS-B', bounds=bounds) print(result.x)
[ 5. 30.]
Introduction à l’optimisation en Python

Optimisation linéaire avec contrainte

Fonction objectif OU

  • Linéaire
  • $p = 2x + 1.5y$

Graphique linéaire de la fonction objectif

Contrainte

  • Linéaire
  • $3x + 2y <= 100$

Graphiques linéaires des contraintes

Introduction à l’optimisation en Python

Inégalité dure

  • Une condition
  • Plus de biscuits une fois la farine épuisée !

Sac de farine

Introduction à l’optimisation en Python

Résoudre un problème linéaire contraint

from scipy.optimize import minimize


def objective_function(b): return (b[0]) ** 2 + (b[1]) ** 0.5
def constraint_function(x): return 2*x[0] + 3*x[1] - 6
constraint = {'type': 'ineq', 'fun': constraint_function}
x0 = [20, 20]
result = minimize(objective_function, x0, constraints=[constraint])
print(result)
     fun: 1.4000405652399073
     jac: array([0.24057153, 0.36086182])
 message: 'Optimization terminated successfully'
    nfev: 25
     nit: 8
    njev: 8
  status: 0
 success: True
       x: array([0.12028576, 1.9198095 ])
  • Types de contraintes :
    • 'eq' : égalité
    • 'ineq' : inégalité
Introduction à l’optimisation en Python

Passons à la pratique !

Introduction à l’optimisation en Python

Preparing Video For Download...