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

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