]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Plugin/saemul.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Plugin / saemul.cxx
1 // -*- C++ -*-
2 // -*- coding: latin_1 -*-
3 //
4 //    File
5 //      creation : 2007-03-23.02.08.59
6 //      revision : $Id$
7 //
8 //    Copyright © 2007 Commissariat à l'Energie Atomique
9 //      par Gilles ARNAUD (DM2S/SFME/LETR)
10 //        C.E. Saclay; Bat 454; 91191 GIF/YVETTE CEDEX; France
11 //        Tel: 01 69 08 38 86; Fax : 33 1 69 08 85 68 
12 //        Gilles.Arnaud@cea.fr
13 // 
14 //    Object
15 //      class emulateur superviseur salome
16 // 
17 //___________________________________________________________________
18
19 #include "saemul.hxx"
20
21 #include "saconst.h"
22
23 #include "math.h"
24
25 Emulator::Emulator(void)
26 {
27     solver = new SalomeTest((Superviseur &) *this);
28 }
29
30 Emulator::~Emulator(void)
31 {
32     delete solver;
33     destroyAll();
34 }
35
36 void Emulator::destroyAll(void)
37 {
38     std::pair<long,std::vector<double> *>    pa;
39     
40     while (! q.empty()) {
41         pa = q.front();
42         q.pop();
43         delete pa.second;
44     }
45 }
46
47 void Emulator::push(long id, std::vector<double> &cal)
48 {
49     std::pair<long, std::vector<double> *> *tmp;
50
51     tmp = new std::pair<long, std::vector<double> *>(id, &cal);
52     q.push(*tmp);
53     delete tmp;
54 }
55
56 long Emulator::getCurrentId(void)
57 {   
58     std::vector<double>     *cal;
59     std::pair<long,std::vector<double> *>    pa;
60     
61     pa = q.front(); q.pop();
62     cal = pa.second;
63     out = eval(*cal);
64     delete cal;
65     return pa.first;
66 }
67
68 std::vector<double> *Emulator::getCurrentOut(void)
69 {
70     return out;
71 }
72
73 std::vector<double> *Emulator::eval(std::vector<double> &x)
74 {   
75     std::vector<double>     *res;
76     res = new std::vector<double>(1);
77 #ifdef TRIPOD
78     //Tripod
79     double      x1, x2;
80     
81     x1 = x[0]; x2 = x[1];
82
83     if (x2 < 0) 
84         (*res)[0] = fabs(x1) + fabs(x2+50);
85     else {
86         (*res)[0] = fabs(x2-50);
87         if (x1 < 0)
88             (*res)[0] += 1 + fabs(x1+50);
89         else
90             (*res)[0] += 2 + fabs(x1-50);
91     }
92 #endif
93 #ifdef ROSENBROCK
94     // rosenbrock
95     double      x1, x2;
96
97     x1 = x[0] ; x2 = x1*x1 - x[1]; x1 -= 1;
98     (*res)[0] = x1*x1 + 100*x2*x2 ;
99 #endif
100 #ifdef GRIEWANK
101     double      x1, x2, y;
102     int     i;
103
104     x1 = 0.0; x2 = 1.0;
105     for (i=0; i<NBGENE; i++) {
106         y = 3*x[i] - 100;
107         x1 += y*y;
108         x2 *= cos(y/sqrt(i+1));
109     }
110     (*res)[0] = x1 / 4000 - x2 + 1;
111 #endif
112     return res;
113 }
114
115 void Emulator::run(void)
116 {
117     solver->readFromFile("caca");
118     solver->start();
119     while (! q.empty())
120         solver->next();
121     solver->finish();
122 }
123