Télécharger mma_04.dgibi

Retour à la liste

Numérotation des lignes :

  1. * fichier : mma_04.dgibi
  2. ************************************************************************
  3. ************************************************************************
  4.  
  5. ************************************************************************
  6. * Test de l'opérateur MMA : Méthode des Asymptotes Mobiles *
  7. * Application à une fonction à 2 variables avec 5 contraintes *
  8. * *
  9. * Le problème s'écrit : *
  10. * Minimiser : f0(x) = (x1-8)² + (x2-9)² *
  11. * sur x *
  12. * avec : f1(x) = ((x1-7)/5)² + ((x2-3)/2)² >= 1 (ellipse) *
  13. * f2(x) = ( x1/4 )² + ((x2-8)/5)² >= 1 (ellipse) *
  14. * f3(x) = (x1-6)² + (x2-7)² >= 1 (cercle) *
  15. * f4(x) = (x1-7)² + (x2-10)² >= 1 (cercle) *
  16. * f5(x) = (x1-10)² + (x2-7)² >= 1 (cercle) *
  17. * 0 <= xi <= 10 pour i=1,2 *
  18. * *
  19. * La solution (évidente) est : x1 = 8 x2 = 9 *
  20. ************************************************************************
  21.  
  22. * Options
  23. OPTI 'ECHO' 0 ;
  24. itrac = FAUX ;
  25.  
  26. * Procédures pour calculer f0 ainsi que les dérivées partielles df0/dx
  27. * Juste les valeurs des fonctions
  28. DEBP F012345 x1 x2 ;
  29. f0 = ((x1 - 8.) ** 2) + ((x2 - 9.) ** 2) ;
  30. f1 = (-1. * ((((x1 - 7.) / 5.) ** 2) + (((x2 - 3.) / 2.) ** 2))) + 1. ;
  31. f2 = (-1. * ((((x1 - 0.) / 4.) ** 2) + (((x2 - 8.) / 5.) ** 2))) + 1. ;
  32. f3 = (-1. * ((((x1 - 6.) / 1.) ** 2) + (((x2 - 7.) / 1.) ** 2))) + 1. ;
  33. f4 = (-1. * ((((x1 - 7.) / 1.) ** 2) + (((x2 - 10.) / 1.) ** 2))) + 1. ;
  34. f5 = (-1. * ((((x1 - 10.) / 1.) ** 2) + (((x2 - 7.) / 1.) ** 2))) + 1. ;
  35. FINP f0 f1 f2 f3 f4 f5 ;
  36.  
  37. * Les fonctions et leurs dérivées
  38. DEBP FONC lx*'LISTREEL' ;
  39. x1 = EXTR lx 1 ;
  40. x2 = EXTR lx 2 ;
  41. f0 f1 f2 f3 f4 f5 = F012345 x1 x2 ;
  42. f = PROG f1 f2 f3 f4 f5 ;
  43. df0dx = 2. * (lx - (PROG 8. 9.)) ;
  44. dfdx = ENUM (-2. * (lx - (PROG 7. 3.)) / ((PROG 5. 2.) ** 2))
  45. (-2. * (lx - (PROG 0. 8.)) / ((PROG 4. 5.) ** 2))
  46. (-2. * (lx - (PROG 6. 7.)) / ((PROG 1. 1.) ** 2))
  47. (-2. * (lx - (PROG 7. 10.)) / ((PROG 1. 1.) ** 2))
  48. (-2. * (lx - (PROG 10. 7.)) / ((PROG 1. 1.) ** 2)) ;
  49. FINP f0 df0dx f dfdx ;
  50.  
  51. * Solution de référence
  52. x1ref = 8. ;
  53. x2ref = 9. ;
  54. xref = PROG x1ref x2ref ;
  55. f0ref df0dxref fval0 dfdxref = FONC xref ;
  56. MESS 'Solution de reference' ;
  57. MESS ' x1 x2 f0' ;
  58. MESS (CHAI 'FORMAT' '(F10.5)' x1ref /4 x2ref /16 f0ref /28) ;
  59.  
  60. * Choix d'un point initial pour les inconnues
  61. x0 = PROG 1. 1. ;
  62.  
  63. * Calcul de f0(x0), df0dx(x0), fval(x0), dfdx(x0)
  64. f0 df0dx fval dfdx = FONC x0 ;
  65.  
  66. * Initialisation de la table pour la MMA
  67. t = TABL ;
  68. t . 'X' = x0 ;
  69. t . 'XMIN' = 0. ;
  70. t . 'XMAX' = 10. ;
  71. t . 'F0VAL' = f0 ;
  72. t . 'DF0DX' = df0dx ;
  73. t . 'FVAL' = fval ;
  74. t . 'DFDX' = dfdx ;
  75. t . 'MOVE' = 0.01 ;
  76.  
  77. * Itérations de la MMA
  78. x01 = EXTR x0 1 ;
  79. x02 = EXTR x0 2 ;
  80. lx1 = PROG x01 ;
  81. lx2 = PROG x02 ;
  82. lit = PROG 0. ;
  83. lf0 = PROG f0 ;
  84. li = PROG (MAXI (fval ET 0.)) ;
  85. MESS 'Optimisation par MMA' ;
  86. MESS 'It x1 x2 f0 kktnorm' ;
  87. MESS (CHAI 'FORMAT' '(F10.5)' 0 x01 /4 x02 /16 f0 /28) ;
  88. * Boucle d'optimisation
  89. REPE loop 150 ;
  90. * Appel à MMA
  91. lit = lit ET &loop ;
  92. MMA t ;
  93. xmma = t . 'X' ;
  94. x1 = EXTR xmma 1 ;
  95. x2 = EXTR xmma 2 ;
  96. lx1 = lx1 ET x1 ;
  97. lx2 = lx2 ET x2 ;
  98. * Mise à jour des valeurs des fonctions
  99. f0 df0dx fval dfdx = FONC xmma ;
  100. lf0 = lf0 ET f0 ;
  101. li = li ET (MAXI (fval ET 0.)) ;
  102. t . 'F0VAL' = f0 ;
  103. t . 'DF0DX' = df0dx ;
  104. t . 'FVAL' = fval ;
  105. t . 'DFDX' = dfdx ;
  106. * Calcul du résidu pour les conditions KKT
  107. res kkt2 kktinf = KKT_MMA t ;
  108. * Bilan de l'itération
  109. MESS (CHAI 'FORMAT' '(F10.5)' &loop x1 /4 x2 /16 f0 /28 kkt2 /40) ;
  110. FIN loop ;
  111. nit = (DIME lf0) - 1 ;
  112.  
  113. * Vérification du résultat
  114. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  115. MESS 'Erreur relative max (sur x)' ;
  116. MESS errmax ;
  117.  
  118. * Évolutions temporelles de f, de l'infaisabilité et des variables
  119. * en fonction des itérations d'optimisation
  120. SI itrac ;
  121. OPTI 'DIME' 2 'ELEM' 'QUA8' ;
  122. msh = (DROI 50 ((t . 'XMIN') (t . 'XMIN')) ((t . 'XMAX') (t . 'XMIN'))) TRAN 50 (0. ((t . 'XMAX') - (t . 'XMIN'))) ;
  123. cmsh = CONT msh ;
  124. x y = COOR msh ;
  125. f0msh f1msh f2msh f3msh f4msh f5msh = F012345 x y ;
  126. lf1 toto = @ISOSURF msh (PROG 0.) f1msh ;
  127. lf2 toto = @ISOSURF msh (PROG 0.) f2msh ;
  128. lf3 toto = @ISOSURF msh (PROG 0.) f3msh ;
  129. lf4 toto = @ISOSURF msh (PROG 0.) f4msh ;
  130. lf5 toto = @ISOSURF msh (PROG 0.) f5msh ;
  131. path = QUEL 'SEG2' lx1 lx2 ;
  132. pdep = x01 x02 ;
  133. pfin = x1 x2 ;
  134. cdep = (CERC 10 'ROTA' 360. (pdep PLUS (0.1 0.)) pdep) COUL 'VIOL' ;
  135. cfin = (CERC 10 'ROTA' 360. (pfin PLUS (0.1 0.)) pfin) COUL 'ROUG' ;
  136. annd = ANNO 'ETIQ' pdep 'VIOL' 'NO' 1. VRAI 'Depart' ;
  137. annf = ANNO 'ETIQ' pfin 'ROUG' 'NE' 1. VRAI 'Arrivee' ;
  138. TRAC f0msh msh (cmsh ET path ET lf1 ET lf2 ET lf3 ET lf4 ET lf5 ET cdep ET cfin) 25
  139. (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-2) ;
  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.  
  177.  
  178.  

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