Trouver l’optimum global
On vous confie le problème de maximisation du profit suivant et votre tâche est d’en trouver le maximum global.
\(\Pi= -\frac{1}{4}q^4 + 11q^3 - 160q^2 + 900q\)
\(0\) est une borne inférieure naturelle pour la quantité et vous avez observé qu’à \(q=30\) le profit est négatif ; \(30\) est donc une bonne candidate pour la borne supérieure.
Trouvez l’optimum global de ce problème.
basinhopping a été importé pour vous.
Cet exercice fait partie du cours
Introduction à l’optimisation en Python
Instructions
- Définissez le dictionnaire
kwargsdes arguments nommés, avec des bornes \(0\) et \(30\). - Exécutez
basinhopping, en prenant l’objectif comme l’opposé deprofitet en passant la valeur initialex0au minimiseur viakwargs.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
def profit(q):
return -q**4 / 4 + 11 * q**3 - 160 * q**2 + 900 * q
x0 = 0
# Define the keyword arguments for bounds
kwargs = {"bounds": [(____, ____)]}
# Run basinhopping to find the optimal quantity
result = basinhopping(____ q: -profit(q), ____, ____=kwargs)
print(f"{result.message}")
print(f"The maximum according to basinhopping(x0={x0}) is at {result.x[0]:.2f}\n")