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

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