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

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