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

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