1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "simplex.hxx"
26 Simplex::Simplex(long sz, long nbgen, Maestro &maest)
35 Simplex::~Simplex(void)
39 if (work.size() == size) {
40 for (i=0; i<size; i++)
42 for (i=0; i<nbin; i++)
47 void Simplex::setStop(long max)
52 void Simplex::start(void)
57 for (i=0; i<size; i++) {
58 work[i] = new Point(nbin);
59 calc->put(i, *(work[i]->next()));
65 int Simplex::next(void)
69 std::vector<double> *next, *res;
73 pt = work[id]->inform(*res);
77 work[id]->mute(*pnt, *barycentre(), *minimum());
81 next = work[id]->next();
90 void Simplex::finish(void)
92 std::cout << maxe - nbeval << std::endl;
96 Solution *Simplex::solution(void)
101 Solution *Simplex::add(Solution *sol)
106 if (simplx.size() < nbin) {
107 ret = (Solution *) NULL;
109 simplx.push_back(sol);
110 while (i && simplx[i]->obj[0] < simplx[i-1]->obj[0]) {
113 simplx[i] = simplx[i-1];
118 else if (sol->obj[0] > simplx[nbin-1]->obj[0])
124 while (i && simplx[i]->obj[0] < simplx[i-1]->obj[0]) {
126 simplx[i] = simplx[i-1];
134 std::vector<double> *Simplex::minimum(void)
136 return new std::vector<double>(*simplx[0]->param);
139 std::vector<double> *Simplex::barycentre(void)
142 std::vector<double> *ret;
144 ret = new std::vector<double>(nbin);
145 for (i=0; i<nbin; i++) {
147 for (j=0; j<nbin; j++)
148 (*ret)[i] += (*simplx[j]->param)[i];