Version: 8.3.0
Simplex Class Reference

#include <simplex.hxx>

Collaboration diagram for Simplex:

Public Member Functions

 Simplex (long, long, Maestro &)
 
 ~Simplex (void)
 
void setStop (long)
 
void start (void)
 
int next (void)
 
void finish (void)
 
void solve (void)
 
Solutionsolution (void)
 

Protected Member Functions

Solutionadd (Solution *)
 
std::vector< double > * minimum (void)
 
std::vector< double > * barycentre (void)
 

Protected Attributes

long size
 
long nbin
 
long maxe
 
long nbeval
 
std::vector< Solution * > simplx
 
std::vector< Point * > work
 
Maestrocalc
 

Detailed Description

Definition at line 29 of file simplex.hxx.

Constructor & Destructor Documentation

Simplex::Simplex ( long  sz,
long  nbgen,
Maestro maest 
)

Definition at line 26 of file simplex.cxx.

References calc, maxe, nbeval, nbin, and size.

27 {
28  size = sz;
29  nbin = nbgen;
30  calc = &maest;
31  maxe = 40000;
32  nbeval = 0;
33 }
Simplex::~Simplex ( void  )

Definition at line 35 of file simplex.cxx.

References CORBAEngineTest::i, nbin, simplx, size, and work.

36 {
37  int i;
38 
39  if (work.size() == size) {
40  for (i=0; i<size; i++)
41  delete work[i];
42  for (i=0; i<nbin; i++)
43  delete simplx[i];
44  }
45 }

Member Function Documentation

Solution * Simplex::add ( Solution sol)
protected

Definition at line 101 of file simplex.cxx.

References CORBAEngineTest::i, nbin, Solution::obj, PMMLBasicsTestLauncher::ret, and simplx.

Referenced by next().

102 {
103  int i;
104  Solution *ret, *swp;
105 
106  if (simplx.size() < nbin) {
107  ret = (Solution *) NULL;
108  i = simplx.size();
109  simplx.push_back(sol);
110  while (i && simplx[i]->obj[0] < simplx[i-1]->obj[0]) {
111  // TODO swap interne
112  swp = simplx[i];
113  simplx[i] = simplx[i-1];
114  simplx[i-1] = swp;
115  i--;
116  }
117  }
118  else if (sol->obj[0] > simplx[nbin-1]->obj[0])
119  ret = sol;
120  else {
121  i = nbin -1;
122  ret = simplx[i];
123  simplx[i] = sol;
124  while (i && simplx[i]->obj[0] < simplx[i-1]->obj[0]) {
125  swp = simplx[i];
126  simplx[i] = simplx[i-1];
127  simplx[i-1] = swp;
128  i--;
129  }
130  }
131  return ret;
132 }
std::vector< double > * Simplex::barycentre ( void  )
protected

Definition at line 139 of file simplex.cxx.

References CORBAEngineTest::i, nbin, PMMLBasicsTestLauncher::ret, and simplx.

Referenced by next().

140 {
141  int i,j;
142  std::vector<double> *ret;
143 
144  ret = new std::vector<double>(nbin);
145  for (i=0; i<nbin; i++) {
146  (*ret)[i] = 0.0;
147  for (j=0; j<nbin; j++)
148  (*ret)[i] += (*simplx[j]->param)[i];
149  (*ret)[i] /= nbin;
150  }
151  return ret;
152 }
void Simplex::finish ( void  )

Definition at line 90 of file simplex.cxx.

References maxe, and nbeval.

Referenced by YACS::ENGINE::PluginSimplex::finish().

91 {
92  std::cout << maxe - nbeval << std::endl;
93  return;
94 }
std::vector< double > * Simplex::minimum ( void  )
protected

Definition at line 134 of file simplex.cxx.

References simplx.

Referenced by next().

135 {
136  return new std::vector<double>(*simplx[0]->param);
137 }
int Simplex::next ( void  )

Definition at line 65 of file simplex.cxx.

References add(), barycentre(), calc, Maestro::get(), minimum(), nbeval, Maestro::put(), size, and work.

Referenced by start(), and YACS::ENGINE::PluginSimplex::takeDecision().

66 {
67  long id;
68  Solution *pt, *pnt;
69  std::vector<double> *next, *res;
70 
71  res = calc->get(&id);
72  nbeval--;
73  pt = work[id]->inform(*res);
74  if (pt) {
75  pnt = add(pt);
76  if (pnt)
77  work[id]->mute(*pnt, *barycentre(), *minimum());
78  else
79  work[id]->reinit();
80  }
81  next = work[id]->next();
82  if (nbeval > size)
83  if (next)
84  calc->put(id, *next);
85  //else
86  // nbeval = size - 1;
87  return (nbeval > 0);
88 }
void Simplex::setStop ( long  max)

Definition at line 47 of file simplex.cxx.

References maxe.

Referenced by YACS::ENGINE::PluginSimplex::parseFileToInit().

48 {
49  maxe = max;
50 }
Solution * Simplex::solution ( void  )

Definition at line 96 of file simplex.cxx.

References simplx.

Referenced by YACS::ENGINE::PluginSimplex::finish().

97 {
98  return simplx[0];
99 }
void Simplex::solve ( void  )
void Simplex::start ( void  )

Definition at line 52 of file simplex.cxx.

References calc, CORBAEngineTest::i, maxe, nbeval, nbin, next(), Maestro::put(), size, and work.

Referenced by YACS::ENGINE::PluginSimplex::start().

53 {
54  long i;
55 
56  work.resize(size);
57  for (i=0; i<size; i++) {
58  work[i] = new Point(nbin);
59  calc->put(i, *(work[i]->next()));
60  }
61  nbeval = maxe;
62 }

Member Data Documentation

Maestro* Simplex::calc
protected

Definition at line 34 of file simplex.hxx.

Referenced by next(), Simplex(), and start().

long Simplex::maxe
protected

Definition at line 31 of file simplex.hxx.

Referenced by finish(), setStop(), Simplex(), and start().

long Simplex::nbeval
protected

Definition at line 31 of file simplex.hxx.

Referenced by finish(), next(), Simplex(), and start().

long Simplex::nbin
protected

Definition at line 31 of file simplex.hxx.

Referenced by add(), barycentre(), Simplex(), start(), and ~Simplex().

std::vector<Solution *> Simplex::simplx
protected

Definition at line 32 of file simplex.hxx.

Referenced by add(), barycentre(), minimum(), solution(), and ~Simplex().

long Simplex::size
protected

Definition at line 31 of file simplex.hxx.

Referenced by next(), Simplex(), start(), and ~Simplex().

std::vector<Point *> Simplex::work
protected

Definition at line 33 of file simplex.hxx.

Referenced by next(), start(), and ~Simplex().


The documentation for this class was generated from the following files: