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 a un probleme 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. * Procedure pour calculer f0, f1, f2 ainsi que les derivees 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 reference
  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 /4 x2ref /16 x3ref /28 f0ref /40) ;
  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 . 'A0' = 1. ;
  63. t . 'A' = PROG 0. 0. ;
  64. t . 'C' = PROG 1.E7 1.E7 ;
  65. t . 'D' = PROG 1. 1. ;
  66. t . 'MOVE' = 0.1 ;
  67.  
  68. * Iterations de la MMA
  69. x01 = EXTR x0 1 ;
  70. x02 = EXTR x0 2 ;
  71. x03 = EXTR x0 3 ;
  72. lx1 = PROG x01 ;
  73. lx2 = PROG x02 ;
  74. lx3 = PROG x03 ;
  75. lit = PROG 0. ;
  76. lf0 = PROG f0 ;
  77. f1 = EXTR fval 1 ;
  78. f2 = EXTR fval 2 ;
  79. li = PROG (MAXI 0. f1 f2) ;
  80. MESS 'Optimisation par MMA' ;
  81. MESS 'It x1 x2 x3 f0 kktnorm' ;
  82. MESS (CHAI 'FORMAT' '(F12.8)' 0 x01 /4 x02 /16 x03 /28 f0 /40) ;
  83. * Boucle d'optimisation
  84. REPE loop 25 ;
  85. * Appel a MMA
  86. lit = lit ET &loop ;
  87. MMA t ;
  88. xmma = t . 'X' ;
  89. x1 = EXTR xmma 1 ;
  90. x2 = EXTR xmma 2 ;
  91. x3 = EXTR xmma 3 ;
  92. lx1 = lx1 ET x1 ;
  93. lx2 = lx2 ET x2 ;
  94. lx3 = lx3 ET x3 ;
  95. * Mise a jour des valeurs des fonctions
  96. f0 df0dx fval dfdx = FONC xmma ;
  97. lf0 = lf0 ET f0 ;
  98. f1 = EXTR fval 1 ;
  99. f2 = EXTR fval 2 ;
  100. li = li ET (MAXI 0. f1 f2) ;
  101. t . 'F0VAL' = f0 ;
  102. t . 'DF0DX' = df0dx ;
  103. t . 'FVAL' = fval ;
  104. t . 'DFDX' = dfdx ;
  105. * Calcul du residu pour les conditions KKT
  106. res kkt2 kktinf = KKT_MMA t ;
  107. * Bilan de l'iteration
  108. MESS (CHAI 'FORMAT' '(F12.8)' &loop x1 /4 x2 /16 x3 /28 f0 /40 kkt2 /52) ;
  109. FIN loop ;
  110. nit = (DIME lf0) - 1 ;
  111.  
  112. * Verification du resultat
  113. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  114. MESS 'Erreur relative max (sur x)' ;
  115. MESS errmax ;
  116.  
  117. * Évolutions temporelles de f, de l'infaisabilité et des variables
  118. * en fonction des iterations d'optimisation
  119. SI itrac ;
  120. lit = PROG 0. 'PAS' 1. nit ;
  121. evf0 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'F0' lf0 ;
  122. evfr = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'F0' (PROG f0ref f0ref) ;
  123. tl = TABL ;
  124. tl . 2 = 'TIRR' ;
  125. tl . 'TITRE' = TABL ;
  126. tl . 'TITRE' . 1 = 'F0 calculee' ;
  127. tl . 'TITRE' . 2 = 'F0 ref.' ;
  128. DESS (evf0 ET evfr) 'TITR' 'Fonction objectif F0(x) VS Iterations' 'LEGE' tl ;
  129. evi = EVOL 'VERT' 'MANU' 'Iteration' lit 'Inf' li ;
  130. tl . 'TITRE' . 1 = 'Infaisabilite' ;
  131. DESS evi 'TITR' 'Infaisabilite VS Iterations' 'LEGE' tl ;
  132. evx1 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'x' lx1 ;
  133. evx1r = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x1ref x1ref) ;
  134. evx2 = EVOL 'ORAN' 'MANU' 'Iteration' lit 'x' lx2 ;
  135. evx2r = EVOL 'ORAN' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x2ref x2ref) ;
  136. evx3 = EVOL 'JAUN' 'MANU' 'Iteration' lit 'x' lx3 ;
  137. evx3r = EVOL 'JAUN' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x3ref x3ref) ;
  138. tl . 4 = 'TIRR' ;
  139. tl . 6 = 'TIRR' ;
  140. tl . 'TITRE' . 1 = 'x1 calcule' ;
  141. tl . 'TITRE' . 2 = 'x1 ref.' ;
  142. tl . 'TITRE' . 3 = 'x2 calcule' ;
  143. tl . 'TITRE' . 4 = 'x2 ref.' ;
  144. tl . 'TITRE' . 5 = 'x3 calcule' ;
  145. tl . 'TITRE' . 6 = 'x3 ref.' ;
  146. DESS (evx1 ET evx1r ET evx2 ET evx2r ET evx3 ET evx3r) 'TITR' 'Valeurs x VS Iterations' 'LEGE' tl ;
  147. FINSI ;
  148.  
  149. * Sortie en erreur si l'écart aux valeurs de références est trop important
  150. SI (errmax > 1.E-5) ;
  151. ERRE 'Erreur dans le calcul d''optimisation' ;
  152. SINON ;
  153. MESS 'Cas test passe avec succes !' ;
  154. FINSI ;
  155.  
  156.  
  157. FIN ;
  158.  
  159.  
  160.  

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