Salome HOME
b7b892843534530a8ee0e0693fc7367a50f2e8bb
[modules/yacs.git] / src / engine / Plugin / PluginSimplex.cxx
1 // Copyright (C) 2006-2021  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, or (at your option) any later version.
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
20 #include "PluginSimplex.hxx"
21 #include "TypeCode.hxx"
22 #include "Pool.hxx"
23
24 #include "saconst.h"
25
26 #include "solution.hxx"
27
28 #include <cmath>
29
30 using namespace YACS::ENGINE;
31
32 PluginSimplex::PluginSimplex(Pool *pool):OptimizerAlgSync(pool),_tc(0)
33 {
34     // type
35     TypeCode    *tctmp=new TypeCode(Double);
36     _tc=new TypeCodeSeq("", "", tctmp);
37     tctmp->decrRef();
38     // distribution
39     dst = (SalomeEventLoop *) NULL;
40     dec = (LinearDecoder *) NULL;
41     mtr = (Maestro *) NULL;
42     // swarm
43     solv = (Simplex *) NULL;
44
45 }
46
47 PluginSimplex::~PluginSimplex()
48 {
49     _tc->decrRef();
50     // distribution
51     delete dst;
52     delete dec;
53     delete mtr;
54     // swarm
55     delete solv;
56 }
57
58 TypeCode *PluginSimplex::getTCForIn() const
59 {
60     return _tc;
61 }
62
63 TypeCode *PluginSimplex::getTCForOut() const
64 {
65     return _tc;
66 }
67
68 void PluginSimplex::parseFileToInit(const std::string& fileName)
69 {
70     std::vector<std::pair<double, double> > dom(NBGENE);
71     long    i;
72
73     // domaine de recherche
74     for (i=0; i<NBGENE; i++) {
75         dom[i].first = BORNEMIN;
76         dom[i].second = BORNEMAX;
77     }
78     // distribution
79     dst = new SalomeEventLoop(_pool);
80     dec = new LinearDecoder(dom);
81     mtr = new Maestro((Decoder &) *dec, (Critere *) NULL, (Distrib &) *dst);
82     // swarm
83     solv = new Simplex(NBNODE, NBGENE, *mtr);
84     
85     solv->setStop(NBEVAL);
86 }
87
88 void PluginSimplex::start()
89 {
90     solv->start();
91 }
92
93 void PluginSimplex::takeDecision()
94 {
95     int     rien;
96     rien = solv->next();
97 }
98
99 void PluginSimplex::initialize(const Any *input)
100 {
101 }
102
103 void PluginSimplex::finish()
104 {
105     Solution        *res;
106
107     solv->finish();
108     res = solv->solution();
109     dec->echo(*res);
110 }
111
112 OptimizerAlgBase *PluginSimplexFactory(Pool *pool)
113 {
114   return new PluginSimplex(pool);
115 }
116