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 a une fonction a 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 (evidente) est : x = 50 *
  15. ************************************************************************
  16.  
  17. * Options
  18. OPTI 'ECHO' 0 ;
  19. itrac = FAUX ;
  20.  
  21. * Procedure pour calculer f0 ainsi que la derivee 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 reference
  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 /4 f0ref /16) ;
  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 . 'A0' = 1. ;
  55. t . 'A' = PROG 0. ;
  56. t . 'C' = PROG 1.E7 ;
  57. t . 'D' = PROG 1. ;
  58. t . 'MOVE' = 0.1 ;
  59.  
  60. * Iterations de la MMA
  61. x01 = EXTR x0 1 ;
  62. lx1 = PROG x01 ;
  63. lit = PROG 0. ;
  64. lf0 = PROG f0 ;
  65. f1 = EXTR fval 1 ;
  66. li = PROG (MAXI 0. f1) ;
  67. MESS 'Optimisation par MMA' ;
  68. MESS 'It x1 f0 kktnorm' ;
  69. MESS (CHAI 'FORMAT' '(F10.5)' 0 x01 /4 f0 /16) ;
  70. * Boucle d'optimisation
  71. REPE loop 25 ;
  72. * Appel a MMA
  73. lit = lit ET &loop ;
  74. MMA t ;
  75. xmma = t . 'X' ;
  76. x1 = EXTR xmma 1 ;
  77. lx1 = lx1 ET x1 ;
  78. * Mise a jour des valeurs des fonctions
  79. f0 df0dx fval dfdx = FONC xmma ;
  80. lf0 = lf0 ET f0 ;
  81. f1 = EXTR fval 1 ;
  82. li = li ET (MAXI 0. f1) ;
  83. t . 'F0VAL' = f0 ;
  84. t . 'DF0DX' = df0dx ;
  85. t . 'FVAL' = fval ;
  86. t . 'DFDX' = dfdx ;
  87. * Calcul du residu pour les conditions KKT
  88. res kkt2 kktinf = KKT_MMA t ;
  89. * Bilan de l'iteration
  90. MESS (CHAI 'FORMAT' '(F10.5)' &loop x1 /4 f0 /16 kkt2 /28) ;
  91. FIN loop ;
  92. nit = (DIME lf0) - 1 ;
  93.  
  94. * Verification du resultat
  95. errmax = MAXI 'ABS' ((xmma - xref) / xref) ;
  96. MESS 'Erreur relative max (sur x)' ;
  97. MESS errmax ;
  98.  
  99. * Évolutions temporelles de f, de l'infaisabilité et des variables
  100. * en fonction des iterations d'optimisation
  101. SI itrac ;
  102. labs = PROG (t . 'XMIN') 'PAS' 1. (t . 'XMAX') ;
  103. lord = ((labs - 50.) ** 2) + 25. ;
  104. evf0 = EVOL 'MANU' 'x' labs 'F0' lord ;
  105. path = EVOL 'ROUG' 'MANU' 'STYL' 'POIN' 'MARQ' 'ROND' 'x' lx1 'F0' lf0 ;
  106. DESS (evf0 ET path) 'TITR' 'Fonction objectif F0 et chemin au cours de l''optimisation' ;
  107. lit = PROG 0. 'PAS' 1. nit ;
  108. evf0 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'F0' lf0 ;
  109. evfr = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'F0' (PROG f0ref f0ref) ;
  110. tl = TABL ;
  111. tl . 2 = 'TIRR' ;
  112. tl . 'TITRE' = TABL ;
  113. tl . 'TITRE' . 1 = 'F0 calculee' ;
  114. tl . 'TITRE' . 2 = 'F0 ref.' ;
  115. DESS (evf0 ET evfr) 'TITR' 'Fonction objectif F0(x) VS Iterations' 'LEGE' tl ;
  116. evi = EVOL 'VERT' 'MANU' 'Iteration' lit 'Inf' li ;
  117. tl . 'TITRE' . 1 = 'Infaisabilite' ;
  118. DESS evi 'TITR' 'Infaisabilite VS Iterations' 'LEGE' tl ;
  119. evx1 = EVOL 'ROUG' 'MANU' 'Iteration' lit 'x' lx1 ;
  120. evx1r = EVOL 'ROUG' 'MANU' 'Iteration' (PROG 0. nit) 'x' (PROG x1ref x1ref) ;
  121. tl . 'TITRE' . 1 = 'x1 calcule' ;
  122. tl . 'TITRE' . 2 = 'x1 ref.' ;
  123. DESS (evx1 ET evx1r) 'TITR' 'Valeurs x VS Iterations' 'LEGE' tl ;
  124. FINSI ;
  125.  
  126. * Sortie en erreur si l'écart aux valeurs de références est trop important
  127. SI (errmax > 1.E-8) ;
  128. ERRE 'Erreur dans le calcul d''optimisation' ;
  129. SINON ;
  130. MESS 'Cas test passe avec succes !' ;
  131. FINSI ;
  132.  
  133.  
  134. FIN ;
  135.  
  136.  
  137.  

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