]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Plugin/PluginSimplex.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Plugin / PluginSimplex.cxx
1 #include "PluginSimplex.hxx"
2 #include "TypeCode.hxx"
3 #include "Pool.hxx"
4
5 #include "saconst.h"
6
7 #include "solution.hxx"
8
9 #include <cmath>
10
11 using namespace YACS::ENGINE;
12
13 PluginSimplex::PluginSimplex(Pool *pool):OptimizerAlgSync(pool),_tc(0)
14 {
15     // type
16     TypeCode    *tctmp=new TypeCode(Double);
17     _tc=new TypeCodeSeq("", "", tctmp);
18     tctmp->decrRef();
19     // distribution
20     dst = (SalomeEventLoop *) NULL;
21     dec = (LinearDecoder *) NULL;
22     mtr = (Maestro *) NULL;
23     // swarm
24     solv = (Simplex *) NULL;
25
26 }
27
28 PluginSimplex::~PluginSimplex()
29 {
30     _tc->decrRef();
31     // distribution
32     delete dst;
33     delete dec;
34     delete mtr;
35     // swarm
36     delete solv;
37 }
38
39 TypeCode *PluginSimplex::getTCForIn() const
40 {
41     return _tc;
42 }
43
44 TypeCode *PluginSimplex::getTCForOut() const
45 {
46     return _tc;
47 }
48
49 void PluginSimplex::parseFileToInit(const std::string& fileName)
50 {
51     std::vector<std::pair<double, double> > dom(NBGENE);
52     long    i;
53
54     // domaine de recherche
55     for (i=0; i<NBGENE; i++) {
56         dom[i].first = BORNEMIN;
57         dom[i].second = BORNEMAX;
58     }
59     // distribution
60     dst = new SalomeEventLoop(_pool);
61     dec = new LinearDecoder(dom);
62     mtr = new Maestro((Decoder &) *dec, (Critere *) NULL, (Distrib &) *dst);
63     // swarm
64     solv = new Simplex(NBNODE, NBGENE, *mtr);
65     
66     solv->setStop(NBEVAL);
67 }
68
69 void PluginSimplex::start()
70 {
71     solv->start();
72 }
73
74 void PluginSimplex::takeDecision()
75 {
76     int     rien;
77     rien = solv->next();
78 }
79
80 void PluginSimplex::initialize(const Any *input) throw (Exception)
81 {
82 }
83
84 void PluginSimplex::finish()
85 {
86     Solution        *res;
87
88     solv->finish();
89     res = solv->solution();
90     dec->echo(*res);
91 }
92
93 OptimizerAlgBase *PluginSimplexFactory(Pool *pool)
94 {
95   return new PluginSimplex(pool);
96 }
97