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

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