]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Plugin/saemul.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / Plugin / saemul.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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