Télécharger gcmma_01.dgibi

Retour à la liste

Numérotation des lignes :

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

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