Télécharger mma_00.dgibi

Retour à la liste

Numérotation des lignes :

  1. * fichier : mma_00.dgibi
  2. ************************************************************************
  3. ************************************************************************
  4.  
  5. ************************************************************************
  6. * Test de l'opérateur MMA : Méthode des Asymptotes Mobiles *
  7. * Application à une fonction à 1 variable et sans contraintes *
  8. * *
  9. * Le problème s'écrit : *
  10. * Minimiser : f0(x) = (x-50)² + 25 *
  11. * sur x *
  12. * avec : 1 <= x <= 100 *
  13. * *
  14. * La solution (évidente) est : x = 50 *
  15. ************************************************************************
  16.  
  17. * Options
  18. OPTI 'ECHO' 0 ;
  19. itrac = FAUX ;
  20.  
  21. * Procédure pour calculer f0 ainsi que la derivée partielle df0/dx
  22. DEBP FONC a*'LISTREEL' ;
  23. x = EXTR a 1 ;
  24. f = ((x - 50.) ** 2) + 25. ;
  25. df = 2. * (a - 50.) ;
  26. g = PROG 0. ;
  27. dgda = TABL ;
  28. dgda . 1 = PROG 0. ;
  29. FINP f df g dgda ;
  30.  
  31. * Solution de référence
  32. x1ref = 50. ;
  33. xref = PROG x1ref ;
  34. f0ref df0dxref fval0 dfdxref = FONC xref ;
  35. MESS 'Solution de reference' ;
  36. MESS ' x1 f0' ;
  37. MESS (CHAI 'FORMAT' '(F10.5)' x1ref /7 f0ref >3) ;
  38.  
  39. * Choix d'un point initial pour les inconnues
  40. x0 = PROG 1. ;
  41.  
  42. * Calcul de f0(x0), df0dx(x0), fval(x0), dfdx(x0)
  43. f0 df0dx fval dfdx = FONC x0 ;
  44.  
  45. * Initialisation de la table pour la MMA
  46. t = TABL ;
  47. t . 'X' = x0 ;
  48. t . 'XMIN' = 1. ;
  49. t . 'XMAX' = 100. ;
  50. t . 'F0VAL' = f0 ;
  51. t . 'DF0DX' = df0dx ;
  52. t . 'FVAL' = fval ;
  53. t . 'DFDX' = dfdx ;
  54. t . 'C' = PROG 1.E7 ;
  55.  
  56. * Itérations de la MMA
  57. x01 = EXTR x0 1 ;
  58. lx1 = PROG x01 ;
  59. lit = PROG 0. ;
  60. lf0 = PROG f0 ;
  61. f1 = EXTR fval 1 ;
  62. li = PROG (MAXI 0. f1) ;
  63. MESS 'Optimisation par MMA' ;
  64. MESS 'It x1 f0 kktnorm' ;
  65. MESS (CHAI 'FORMAT' '(F10.5)' 0 x01 /7 f0 >3) ;
  66. * Boucle d'optimisation
  67. REPE loop 25 ;
  68. * Appel à MMA
  69. lit = lit ET &loop ;
  70. MMA t ;
  71. xmma = t . 'X' ;
  72. x1 = EXTR xmma 1 ;
  73. lx1 = lx1 ET x1 ;
  74. * Mise à jour des valeurs des fonctions
  75. f0 df0dx fval dfdx = FONC xmma ;
  76. lf0 = lf0 ET f0 ;
  77. f1 = EXTR fval 1 ;
  78. li = li ET (MAXI 0. f1) ;
  79. t . 'F0VAL' = f0 ;
  80. t . 'DF0DX' = df0dx ;
  81. t . 'FVAL' = fval ;
  82. t . 'DFDX' = dfdx ;
  83. * Calcul du résidu pour les conditions KKT
  84. res kkt2 kktinf = KKT_MMA t ;
  85. * Bilan de l'itération
  86. MESS (CHAI 'FORMAT' '(F10.5)' &loop x1 /7 f0 >3 kkt2 >2) ;
  87. FIN loop ;
  88. nit = (DIME lf0) - 1 ;
  89.  
  90. * Vérification du résultat
  91. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  92. MESS 'Erreur relative max (sur x)' ;
  93. MESS errmax ;
  94.  
  95. * Évolutions temporelles de f, de l'infaisabilité et des variables
  96. * en fonction des itérations d'optimisation
  97. SI itrac ;
  98. labs = PROG (t . 'XMIN') 'PAS' 1. (t . 'XMAX') ;
  99. lord = ((labs - 50.) ** 2) + 25. ;
  100. evf0 = EVOL 'MANU' 'x' labs 'F0' lord ;
  101. path = EVOL 'ROUG' 'MANU' 'STYL' 'POIN' 'MARQ' 'ROND' 'x' lx1 'F0' lf0 ;
  102. DESS (evf0 ET path) 'TITR' 'Fonction objectif F0 et chemin au cours de l''optimisation' ;
  103. lit = PROG 0. 'PAS' 1. nit ;
  104. evf0 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'F0' lf0 ;
  105. evfr = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'F0' (PROG f0ref f0ref) ;
  106. tl = TABL ;
  107. tl . 2 = 'TIRR' ;
  108. tl . 'TITRE' = TABL ;
  109. tl . 'TITRE' . 1 = 'F0 calculee' ;
  110. tl . 'TITRE' . 2 = 'F0 ref.' ;
  111. DESS (evf0 ET evfr) 'TITR' 'Fonction objectif F0(x) VS Iterations' 'LEGE' tl ;
  112. evi = EVOL 'VERT' 'MANU' 'Iteration' lit 'Inf' li ;
  113. tl . 'TITRE' . 1 = 'Infaisabilite' ;
  114. DESS evi 'TITR' 'Infaisabilite VS Iterations' 'LEGE' tl ;
  115. evx1 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'x' lx1 ;
  116. evx1r = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x1ref x1ref) ;
  117. tl . 'TITRE' . 1 = 'x1 calcule' ;
  118. tl . 'TITRE' . 2 = 'x1 ref.' ;
  119. DESS (evx1 ET evx1r) 'TITR' 'Valeurs x VS Iterations' 'LEGE' tl ;
  120. FINSI ;
  121.  
  122. * Sortie en erreur si l'écart aux valeurs de références est trop important
  123. SI (errmax > 1.E-6) ;
  124. ERRE 'Erreur dans le calcul d''optimisation' ;
  125. SINON ;
  126. MESS 'Cas test passe avec succes !' ;
  127. FINSI ;
  128.  
  129.  
  130. FIN ;
  131.  
  132.  
  133.  
  134.  

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