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

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