Télécharger mma_02.dgibi

Retour à la liste

Numérotation des lignes :

  1. * fichier : mma_02.dgibi
  2. ************************************************************************
  3. ************************************************************************
  4.  
  5. ************************************************************************
  6. * Test de l'opérateur MMA : Méthode des Asymptotes Mobiles *
  7. * Application à un problème simple (pour jouer) *
  8. * *
  9. * Le problème s'écrit : *
  10. * Minimiser : f0(x) = x1² + x2² + x3² *
  11. * sur x *
  12. * avec : f1(x) = (x1-5)² + (x2-2)² + (x3-1)² - 9 <= 0 *
  13. * f2(x) = (x1-3)² + (x2-4)² + (x3-3)² - 9 <= 0 *
  14. * 0 <= xi <= 5 pour i=1,2,3 *
  15. * *
  16. * La solution est : x1 = 2.0175 x2 = 1.7800 x3 = 1.2375 *
  17. ************************************************************************
  18.  
  19. * Options d'affichage
  20. OPTI 'ECHO' 0 ;
  21. itrac = FAUX ;
  22.  
  23. * Procédure pour calculer f0, f1, f2 ainsi que les dérivées partielles
  24. * df0/dxi, df1/dxi, df2/dxi pour i=1,2,3
  25. DEBP FONC a*'LISTREEL' ;
  26. f = SOMM (a ** 2) ;
  27. df = 2. * a ;
  28. b1 = PROG 5. 2. 1. ;
  29. b2 = PROG 3. 4. 3. ;
  30. g = PROG ((SOMM ((a - b1) ** 2)) - 9.)
  31. ((SOMM ((a - b2) ** 2)) - 9.) ;
  32. dgda = TABL ;
  33. dgda . 1 = 2. * (a - b1) ;
  34. dgda . 2 = 2. * (a - b2) ;
  35. FINP f df g dgda ;
  36.  
  37. * Solution de référence
  38. x1ref = 2.0175 ;
  39. x2ref = 1.7800 ;
  40. x3ref = 1.2375 ;
  41. xref = PROG x1ref x2ref x3ref ;
  42. f0ref df0dxref fval0 dfdxref = FONC xref ;
  43. MESS 'Solution de reference' ;
  44. MESS ' x1 x2 x3 f0' ;
  45. MESS (CHAI 'FORMAT' '(F12.8)' x1ref /7 x2ref >1 x3ref >1 f0ref >1) ;
  46.  
  47. * Choix d'un point initial pour les inconnues
  48. x0 = PROG 4. 3. 2. ;
  49.  
  50. * Calcul de f0(x0), df0dx(x0), fval(x0), dfdx(x0)
  51. f0 df0dx fval dfdx = FONC x0 ;
  52.  
  53. * Initialisation de la table pour la MMA
  54. t = TABL ;
  55. t . 'X' = x0 ;
  56. t . 'XMIN' = 0. ;
  57. t . 'XMAX' = 5. ;
  58. t . 'F0VAL' = f0 ;
  59. t . 'DF0DX' = df0dx ;
  60. t . 'FVAL' = fval ;
  61. t . 'DFDX' = dfdx ;
  62. t . 'C' = 1000. ;
  63.  
  64. * Itérations de la MMA
  65. x01 = EXTR x0 1 ;
  66. x02 = EXTR x0 2 ;
  67. x03 = EXTR x0 3 ;
  68. lx1 = PROG x01 ;
  69. lx2 = PROG x02 ;
  70. lx3 = PROG x03 ;
  71. lit = PROG 0. ;
  72. lf0 = PROG f0 ;
  73. f1 = EXTR fval 1 ;
  74. f2 = EXTR fval 2 ;
  75. li = PROG (MAXI 0. f1 f2) ;
  76. MESS 'Optimisation par MMA' ;
  77. MESS 'It x1 x2 x3 f0 kktnorm' ;
  78. MESS (CHAI 'FORMAT' '(F12.8)' 0 x01 /7 x02 >1 x03 >1 f0 >1) ;
  79. * Boucle d'optimisation
  80. REPE loop 10 ;
  81. * Appel à MMA
  82. lit = lit ET &loop ;
  83. MMA t ;
  84. * Mise à jour des valeurs des fonctions
  85. xmma = t . 'X' ;
  86. f0 df0dx fval dfdx = FONC xmma ;
  87. t . 'F0VAL' = f0 ;
  88. t . 'DF0DX' = df0dx ;
  89. t . 'FVAL' = fval ;
  90. t . 'DFDX' = dfdx ;
  91. * Calcul du résidu pour les conditions KKT
  92. res kkt2 kktinf = KKT_MMA t ;
  93. * Bilan de l'itération
  94. x1 = EXTR xmma 1 ;
  95. x2 = EXTR xmma 2 ;
  96. x3 = EXTR xmma 3 ;
  97. lx1 = lx1 ET x1 ;
  98. lx2 = lx2 ET x2 ;
  99. lx3 = lx3 ET x3 ;
  100. lf0 = lf0 ET f0 ;
  101. f1 = EXTR fval 1 ;
  102. f2 = EXTR fval 2 ;
  103. li = li ET (MAXI 0. f1 f2) ;
  104. MESS (CHAI 'FORMAT' '(F12.8)' &loop x1 /7 x2 >1 x3 >1 f0 >1 kkt2 >1) ;
  105. FIN loop ;
  106. nit = (DIME lf0) - 1 ;
  107.  
  108. * Vérification du résultat
  109. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  110. MESS 'Erreur relative max (sur x)' ;
  111. MESS errmax ;
  112.  
  113. * Évolutions temporelles de f, de l'infaisabilité et des variables
  114. * en fonction des itérations d'optimisation
  115. SI itrac ;
  116. lit = PROG 0. 'PAS' 1. nit ;
  117. evf0 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'F0' lf0 ;
  118. evfr = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'F0' (PROG f0ref f0ref) ;
  119. tl = TABL ;
  120. tl . 2 = 'TIRR' ;
  121. tl . 'TITRE' = TABL ;
  122. tl . 'TITRE' . 1 = 'F0 calculee' ;
  123. tl . 'TITRE' . 2 = 'F0 ref.' ;
  124. DESS (evf0 ET evfr) 'TITR' 'Fonction objectif F0(x) VS Iterations' 'LEGE' tl ;
  125. evi = EVOL 'VERT' 'MANU' 'Iteration' lit 'Inf' li ;
  126. tl . 'TITRE' . 1 = 'Infaisabilite' ;
  127. DESS evi 'TITR' 'Infaisabilite VS Iterations' 'LEGE' tl ;
  128. evx1 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'x' lx1 ;
  129. evx1r = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x1ref x1ref) ;
  130. evx2 = EVOL 'ORAN' 'MANU' 'Iteration' lit 'x' lx2 ;
  131. evx2r = EVOL 'ORAN' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x2ref x2ref) ;
  132. evx3 = EVOL 'JAUN' 'MANU' 'Iteration' lit 'x' lx3 ;
  133. evx3r = EVOL 'JAUN' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x3ref x3ref) ;
  134. tl . 4 = 'TIRR' ;
  135. tl . 6 = 'TIRR' ;
  136. tl . 'TITRE' . 1 = 'x1 calcule' ;
  137. tl . 'TITRE' . 2 = 'x1 ref.' ;
  138. tl . 'TITRE' . 3 = 'x2 calcule' ;
  139. tl . 'TITRE' . 4 = 'x2 ref.' ;
  140. tl . 'TITRE' . 5 = 'x3 calcule' ;
  141. tl . 'TITRE' . 6 = 'x3 ref.' ;
  142. DESS (evx1 ET evx1r ET evx2 ET evx2r ET evx3 ET evx3r) 'TITR' 'Valeurs x VS Iterations' 'LEGE' tl ;
  143. FINSI ;
  144.  
  145. * Sortie en erreur si l'écart aux valeurs de références est trop important
  146. SI (errmax > 1.E-5) ;
  147. ERRE 'Erreur dans le calcul d''optimisation' ;
  148. SINON ;
  149. MESS 'Cas test passe avec succes !' ;
  150. FINSI ;
  151.  
  152.  
  153. FIN ;
  154.  
  155.  
  156.  
  157.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales