-
Notifications
You must be signed in to change notification settings - Fork 7
Test branch #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolaspoly
wants to merge
3
commits into
dpo-mth8408:main
Choose a base branch
from
nicolaspoly:test-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test branch #3
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| title: "Rapport de laboratoire 1: modélisation et résolution de problèmes avec IPOPT" | ||
| subtitle: "MTH8408" | ||
| author: | ||
| - name: Votre nom | ||
| - name: Nicolas Jouglet | ||
| email: votre.adresse@polymtl.ca | ||
| affiliation: | ||
| - name: Polytechnique Montréal | ||
|
|
@@ -41,26 +41,64 @@ Effectuez les opérations suivantes : | |
| 1. résolvez ce problème avec IPOPT et faites afficher la solution ; | ||
|
|
||
| ```{julia} | ||
| # Insérez votre code ici | ||
| Pkg.add("ADNLPModels") | ||
| Pkg.add("NLPModelsIpopt") # <- ces commandes auraient du aller dans le bloc de code précédent | ||
| using ADNLPModels, NLPModelsIpopt | ||
dpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Définition de la fonction objectif | ||
| f(x) = (x[1] - 2)^2 + (x[2] - 1)^2 | ||
|
|
||
|
|
||
| # Contraintes | ||
| c(x) = [x[1]^2 - x[2], x[1] + x[2] - 2] | ||
|
|
||
|
|
||
| # Point initial | ||
| x0 = [1.0, 1.0] | ||
|
|
||
| lcon = [-Inf, -Inf] | ||
| ucon = [0.0, 0.0] | ||
| lvar=[-Inf, -Inf] | ||
| uvar=[Inf, Inf] | ||
|
|
||
| # Modélisation | ||
| model = ADNLPModel(f, x0, lvar, uvar, c, lcon , ucon ) | ||
| # Résolution avec IPOPT | ||
| result = ipopt(model) | ||
|
|
||
| # Affichage de la solution | ||
| result.solution | ||
| ``` | ||
|
|
||
| 2. donnez le statut final d'IPOPT ; | ||
|
|
||
| ```{julia} | ||
| # Insérez votre code ici | ||
| result.status | ||
| ``` | ||
|
|
||
| 3. Validez manuellement que la solution vérifie les contraintes ; | ||
|
|
||
| ```{julia} | ||
| # Insérez votre code ici | ||
|
|
||
|
|
||
| cx = c(result.solution) | ||
|
|
||
| if all(cx .<= 0) | ||
| println("Toutes les contraintes sont respectées.") | ||
| else | ||
| println(" Certaines contraintes ne sont pas respectées.") | ||
| println("Valeurs des contraintes : ", cx) | ||
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, mais elles le sont dans les limites de l'arithmétique flottante. |
||
|
|
||
|
|
||
| ``` | ||
|
|
||
| 4. faites afficher les résidu d'optimalité calculés par IPOPT, contenues dans `stats.primal_feas` et `stats.dual_feas`, respectivement. | ||
| NB: `primal_feas` donne la satisfaction des contraintes et `dual_feas` est la norme du gradient du lagrangien du problème. | ||
|
|
||
| ```{julia} | ||
| # Insérez votre code ici | ||
| result.primal_feas | ||
| result.dual_feas | ||
| ``` | ||
|
|
||
| # Modélisation d'un problème dégénéré | ||
|
|
@@ -75,7 +113,19 @@ Un solveur comme IPOPT ne requiert pas un point initial réalisable. | |
| Utilisez le point initial $x = 1$. | ||
|
|
||
| ```{julia} | ||
| # Insérez votre code ici | ||
| f(x)=x[1] | ||
| c(x)=[x[1]^2] | ||
| lvar=[-Inf] | ||
| uvar=[Inf] | ||
| lcon=[0.0] | ||
| ucon=[0.0] | ||
| x0=[1.0] | ||
| model = ADNLPModel(f, x0, lvar, uvar, c, lcon , ucon ) | ||
| # Résolution avec IPOPT | ||
| result = ipopt(model) | ||
|
|
||
| # Affichage de la solution | ||
| result.solution | ||
| ``` | ||
|
|
||
| Commentez le statut final d'IPOPT, les résidus d'optimalité, ainsi que la solution finale identifiée. | ||
|
|
@@ -84,3 +134,6 @@ Ajoutez vos propres commentaires concernant ce problème d'optimisation. | |
| ## Commentaires | ||
|
|
||
| <!-- Insérez vos commentaires ci-dessous. --> | ||
| Ipopt annonce avoir trouvé une solution optimale. La solution qu'il retourne est 6.1035e-5. On se rend compte dans le résultat que la valeur de la violation des contraintes n'est pas nul tandisque le gradient du lagrangien vaut 0. | ||
| Le résultat obtenu n'est pas la valeur exacte attendu, surement du à un arrondi dans le calcul numérique. | ||
| La solution touvée est très proche de la solution réelle mais ne l'atteint pas, de plus le solveur met 14 itérations (beaucoup plus que le problème précédent). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. À quoi cela est-il dû, à ton avis ? |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il faut commencer par ajouter ces modules à votre environnement, comme dans le
qmdvu en exemple au laboratoire. As-tu essayé de générer ton rapport localement ?