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 a une fonction a 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 (evidente) est : x1 = 8 x2 = 9 *
  20. ************************************************************************
  21.  
  22. * Options
  23. OPTI 'ECHO' 0 ;
  24. itrac = FAUX ;
  25.  
  26. * Procedure pour calculer f0 ainsi que les derivees partielles df0/dx
  27. DEBP FONC a*'LISTREEL' ;
  28. c0 = PROG 8. 9. ;
  29. f = SOMM ((a - c0) ** 2) ;
  30. df = 2. * (a - c0) ;
  31. c1 = PROG 7. 3. ;
  32. d1 = PROG 5. 2. ;
  33. c2 = PROG 0. 8. ;
  34. d2 = PROG 4. 5. ;
  35. c3 = PROG 6. 7. ;
  36. d3 = PROG 1. 1. ;
  37. c4 = PROG 7. 10. ;
  38. d4 = PROG 1. 1. ;
  39. c5 = PROG 10. 7. ;
  40. d5 = PROG 1. 1. ;
  41. g = PROG ((-1. * (SOMM (((a - c1) / d1) ** 2))) + 1.)
  42. ((-1. * (SOMM (((a - c2) / d2) ** 2))) + 1.)
  43. ((-1. * (SOMM (((a - c3) / d3) ** 2))) + 1.)
  44. ((-1. * (SOMM (((a - c4) / d4) ** 2))) + 1.)
  45. ((-1. * (SOMM (((a - c5) / d5) ** 2))) + 1.) ;
  46. dgda = TABL ;
  47. dgda . 1 = -2. * (a - c1) / (d1 ** 2) ;
  48. dgda . 2 = -2. * (a - c2) / (d2 ** 2) ;
  49. dgda . 3 = -2. * (a - c3) / (d3 ** 2) ;
  50. dgda . 4 = -2. * (a - c4) / (d4 ** 2) ;
  51. dgda . 5 = -2. * (a - c5) / (d5 ** 2) ;
  52. FINP f df g dgda ;
  53.  
  54. * Solution de reference
  55. x1ref = 8. ;
  56. x2ref = 9. ;
  57. xref = PROG x1ref x2ref ;
  58. f0ref df0dxref fval0 dfdxref = FONC xref ;
  59. MESS 'Solution de reference' ;
  60. MESS ' x1 x2 f0' ;
  61. MESS (CHAI 'FORMAT' '(F10.5)' x1ref /4 x2ref /16 f0ref /28) ;
  62.  
  63. * Choix d'un point initial pour les inconnues
  64. x0 = PROG 1. 1. ;
  65.  
  66. * Calcul de f0(x0), df0dx(x0), fval(x0), dfdx(x0)
  67. f0 df0dx fval dfdx = FONC x0 ;
  68.  
  69. * Initialisation de la table pour la MMA
  70. t = TABL ;
  71. t . 'X' = x0 ;
  72. t . 'XMIN' = 0. ;
  73. t . 'XMAX' = 10. ;
  74. t . 'F0VAL' = f0 ;
  75. t . 'DF0DX' = df0dx ;
  76. t . 'FVAL' = fval ;
  77. t . 'DFDX' = dfdx ;
  78. t . 'A0' = 1. ;
  79. t . 'A' = PROG (DIME dfdx)*0. ;
  80. t . 'C' = PROG (DIME dfdx)*1.E5 ;
  81. t . 'D' = PROG (DIME dfdx)*1. ;
  82. t . 'MOVE' = 0.01 ;
  83.  
  84. * Iterations de la MMA
  85. x01 = EXTR x0 1 ;
  86. x02 = EXTR x0 2 ;
  87. lx1 = PROG x01 ;
  88. lx2 = PROG x02 ;
  89. lit = PROG 0. ;
  90. lf0 = PROG f0 ;
  91. li = PROG (MAXI (fval ET 0.)) ;
  92. MESS 'Optimisation par MMA' ;
  93. MESS 'It x1 x2 f0 kktnorm' ;
  94. MESS (CHAI 'FORMAT' '(F10.5)' 0 x01 /4 x02 /16 f0 /28) ;
  95. * Boucle d'optimisation
  96. REPE loop 150 ;
  97. * Appel a MMA
  98. lit = lit ET &loop ;
  99. MMA t ;
  100. xmma = t . 'X' ;
  101. x1 = EXTR xmma 1 ;
  102. x2 = EXTR xmma 2 ;
  103. lx1 = lx1 ET x1 ;
  104. lx2 = lx2 ET x2 ;
  105. * Mise a jour des valeurs des fonctions
  106. f0 df0dx fval dfdx = FONC xmma ;
  107. lf0 = lf0 ET f0 ;
  108. li = li ET (MAXI (fval ET 0.)) ;
  109. t . 'F0VAL' = f0 ;
  110. t . 'DF0DX' = df0dx ;
  111. t . 'FVAL' = fval ;
  112. t . 'DFDX' = dfdx ;
  113. * Calcul du residu pour les conditions KKT
  114. res kkt2 kktinf = KKT_MMA t ;
  115. * Bilan de l'iteration
  116. MESS (CHAI 'FORMAT' '(F10.5)' &loop x1 /4 x2 /16 f0 /28 kkt2 /40) ;
  117. FIN loop ;
  118. nit = (DIME lf0) - 1 ;
  119.  
  120. * Verification du resultat
  121. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  122. MESS 'Erreur relative max (sur x)' ;
  123. MESS errmax ;
  124.  
  125. * Évolutions temporelles de f, de l'infaisabilité et des variables
  126. * en fonction des iterations d'optimisation
  127. SI itrac ;
  128. OPTI 'DIME' 2 'ELEM' 'QUA8' ;
  129. msh = (DROI 50 ((t . 'XMIN') (t . 'XMIN')) ((t . 'XMAX') (t . 'XMIN'))) TRAN 50 (0. ((t . 'XMAX') - (t . 'XMIN'))) ;
  130. cmsh = CONT msh ;
  131. x y = COOR msh ;
  132. f0msh = ((x - 8.) ** 2) + ((y - 9.) ** 2) ;
  133.  
  134. f1msh = (((x - 7.) / 5.) ** 2) + (((y - 3.) / 2.) ** 2) - 1. ;
  135. f2msh = (((x - 0.) / 4.) ** 2) + (((y - 8.) / 5.) ** 2) - 1. ;
  136. f3msh = (((x - 6.) / 1.) ** 2) + (((y - 7.) / 1.) ** 2) - 1. ;
  137. f4msh = (((x - 7.) / 1.) ** 2) + (((y - 10.) / 1.) ** 2) - 1. ;
  138. f5msh = (((x - 10.) / 1.) ** 2) + (((y - 7.) / 1.) ** 2) - 1. ;
  139. lf1 toto = @ISOSURF msh (PROG 0.) f1msh ;
  140. lf2 toto = @ISOSURF msh (PROG 0.) f2msh ;
  141. lf3 toto = @ISOSURF msh (PROG 0.) f3msh ;
  142. lf4 toto = @ISOSURF msh (PROG 0.) f4msh ;
  143. lf5 toto = @ISOSURF msh (PROG 0.) f5msh ;
  144. path = QUEL 'SEG2' lx1 lx2 ;
  145. pdep = x01 x02 ;
  146. pfin = x1 x2 ;
  147. cdep = (CERC 10 'ROTA' 360. (pdep PLUS (0.1 0.)) pdep) COUL 'VIOL' ;
  148. cfin = (CERC 10 'ROTA' 360. (pfin PLUS (0.1 0.)) pfin) COUL 'ROUG' ;
  149. annd = ANNO 'ETIQ' pdep 'VIOL' 'NO' 1. VRAI 'Depart' ;
  150. annf = ANNO 'ETIQ' pfin 'ROUG' 'NE' 1. VRAI 'Arrivee' ;
  151. TRAC f0msh msh (cmsh ET path ET lf1 ET lf2 ET lf3 ET lf4 ET lf5 ET cdep ET cfin) 25
  152. (annd ET annf) 'TITR' 'Isovaleurs de la fonction objectif F0 et chemin au cours de l''optimisation' ;
  153. lit = PROG 0. 'PAS' 1. nit ;
  154. evf0 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'F0' lf0 ;
  155. evfr = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'F0' (PROG f0ref f0ref) ;
  156. tl = TABL ;
  157. tl . 2 = 'TIRR' ;
  158. tl . 'TITRE' = TABL ;
  159. tl . 'TITRE' . 1 = 'F0 calculee' ;
  160. tl . 'TITRE' . 2 = 'F0 ref.' ;
  161. DESS (evf0 ET evfr) 'TITR' 'Fonction objectif F0(x) VS Iterations' 'LEGE' tl ;
  162. evi = EVOL 'VERT' 'MANU' 'Iteration' lit 'Inf' li ;
  163. tl . 'TITRE' . 1 = 'Infaisabilite' ;
  164. DESS evi 'TITR' 'Infaisabilite VS Iterations' 'LEGE' tl ;
  165. evx1 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'x' lx1 ;
  166. evx1r = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x1ref x1ref) ;
  167. evx2 = EVOL 'ORAN' 'MANU' 'Iteration' lit 'x' lx2 ;
  168. evx2r = EVOL 'ORAN' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x2ref x2ref) ;
  169. tl . 4 = 'TIRR' ;
  170. tl . 'TITRE' . 1 = 'x1 calcule' ;
  171. tl . 'TITRE' . 2 = 'x1 ref.' ;
  172. tl . 'TITRE' . 3 = 'x2 calcule' ;
  173. tl . 'TITRE' . 4 = 'x2 ref.' ;
  174. DESS (evx1 ET evx1r ET evx2 ET evx2r) 'TITR' 'Valeurs x VS Iterations' 'LEGE' tl ;
  175. FINSI ;
  176.  
  177. * Sortie en erreur si l'écart aux valeurs de références est trop important
  178. SI (errmax > 1.E-2) ;
  179. ERRE 'Erreur dans le calcul d''optimisation' ;
  180. SINON ;
  181. MESS 'Cas test passe avec succes !' ;
  182. FINSI ;
  183.  
  184.  
  185. FIN ;
  186.  
  187.  
  188.  

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