intermediate commit
This commit is contained in:
parent
7f9b8fe607
commit
1e6240f9bf
9 changed files with 370 additions and 178 deletions
|
|
@ -27,3 +27,4 @@ int main(int ac, char** av)
|
||||||
T t(666);
|
T t(666);
|
||||||
MyClass mc3(t);
|
MyClass mc3(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <continuator/moTrueContinuator.h>
|
#include <continuator/moTrueContinuator.h>
|
||||||
#include <eval/moEval.h>
|
#include <eval/moEval.h>
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoOptional.h>
|
||||||
|
#include <eval/moFullEvalByCopy.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulated Annealing
|
* Simulated Annealing
|
||||||
|
|
@ -60,38 +62,60 @@ public:
|
||||||
* @param _span number of iteration with equal temperature for cooling schedule (default = 100)
|
* @param _span number of iteration with equal temperature for cooling schedule (default = 100)
|
||||||
* @param _finalT final temperature, threshold of the stopping criteria for cooling schedule (default = 0.01)
|
* @param _finalT final temperature, threshold of the stopping criteria for cooling schedule (default = 0.01)
|
||||||
*/
|
*/
|
||||||
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01):
|
/*moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01)
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
: defaultCool(_initT, _alpha, _span, _finalT),
|
||||||
defaultCool(_initT, _alpha, _span, _finalT),
|
explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool),
|
||||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool)
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
|
||||||
{}
|
{ }*/
|
||||||
|
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01)
|
||||||
|
: moLocalSearch<Neighbor>(*(explorer = new moSAexplorer<Neighbor>(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool)), *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval),
|
||||||
|
defaultCool(new moSimpleCoolingSchedule<EOT>(_initT, _alpha, _span, _finalT)),
|
||||||
|
default_eval(NULL), // removed in C++11 with unique_ptr
|
||||||
|
defaultSolNeighborComp(new moSolNeighborComparator<Neighbor>())
|
||||||
|
//explorer(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool)
|
||||||
|
{ }
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Simple constructor for a simulated annealing
|
// * Simple constructor for a simulated annealing
|
||||||
* @param _neighborhood the neighborhood
|
// * @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
// * @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
// * @param _eval neighbor's evaluation function
|
||||||
* @param _cool a cooling schedule
|
// * @param _cool a cooling schedule
|
||||||
*/
|
// */
|
||||||
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool):
|
// moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
// moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
defaultCool(0, 0, 0, 0),
|
// defaultCool(0, 0, 0, 0),
|
||||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
|
// explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
|
||||||
{}
|
// {}
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* General constructor for a simulated annealing
|
// * General constructor for a simulated annealing
|
||||||
* @param _neighborhood the neighborhood
|
// * @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
// * @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
// * @param _eval neighbor's evaluation function
|
||||||
* @param _cool a cooling schedule
|
// * @param _cool a cooling schedule
|
||||||
* @param _cont an external continuator
|
// * @param _cont an external continuator
|
||||||
*/
|
// */
|
||||||
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moContinuator<Neighbor>& _cont):
|
// moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
// moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
defaultCool(0, 0, 0, 0),
|
// defaultCool(0, 0, 0, 0),
|
||||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
|
// explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
|
||||||
{}
|
// {}
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * General constructor for a simulated annealing
|
||||||
|
// * @param _neighborhood the neighborhood
|
||||||
|
// * @param _fullEval the full evaluation function
|
||||||
|
// * @param _eval neighbor's evaluation function
|
||||||
|
// * @param _cool a cooling schedule
|
||||||
|
// * @param _comp a solution vs neighbor comparator
|
||||||
|
// * @param _cont an external continuator
|
||||||
|
// */
|
||||||
|
// moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moSolNeighborComparator<Neighbor>& _comp, moContinuator<Neighbor>& _cont):
|
||||||
|
// moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
|
// defaultCool(0, 0, 0, 0),
|
||||||
|
// explorer(_neighborhood, _eval, _comp, _cool)
|
||||||
|
// {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a simulated annealing
|
* General constructor for a simulated annealing
|
||||||
|
|
@ -102,19 +126,75 @@ public:
|
||||||
* @param _comp a solution vs neighbor comparator
|
* @param _comp a solution vs neighbor comparator
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moSolNeighborComparator<Neighbor>& _comp, moContinuator<Neighbor>& _cont):
|
moSA (
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
Neighborhood& _neighborhood,
|
||||||
defaultCool(0, 0, 0, 0),
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
explorer(_neighborhood, _eval, _comp, _cool)
|
moCoolingSchedule<EOT>& _cool,
|
||||||
{}
|
eoOptional< moEval<Neighbor> > _eval = NULL,
|
||||||
|
eoOptional< moContinuator<Neighbor> > _cont = NULL,
|
||||||
|
eoOptional< moSolNeighborComparator<Neighbor> > _comp = NULL
|
||||||
|
)
|
||||||
|
/*: moLocalSearch<Neighbor>(explorer, _cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval),
|
||||||
|
defaultCool(NULL), // removed in C++11 with unique_ptr
|
||||||
|
default_eval(NULL), // removed in C++11 with unique_ptr
|
||||||
|
defaultSolNeighborComp(NULL), // removed in C++11 with unique_ptr
|
||||||
|
trueCont(NULL), // removed in C++11 with unique_ptr
|
||||||
|
explorer (
|
||||||
|
_neighborhood,
|
||||||
|
_eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy<Neighbor>(_fullEval)),
|
||||||
|
// C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy<Neighbor>(),
|
||||||
|
_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator<Neighbor>()),
|
||||||
|
_cool )
|
||||||
|
{ }*/
|
||||||
|
: moLocalSearch<Neighbor> (
|
||||||
|
*(explorer = new moSAexplorer<Neighbor> (
|
||||||
|
_neighborhood,
|
||||||
|
_eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy<Neighbor>(_fullEval)),
|
||||||
|
// C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy<Neighbor>(),
|
||||||
|
_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator<Neighbor>()),
|
||||||
|
_cool )),
|
||||||
|
_cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval ),
|
||||||
|
defaultCool(NULL), // removed in C++11 with unique_ptr
|
||||||
|
default_eval(NULL), // removed in C++11 with unique_ptr
|
||||||
|
trueCont(NULL), // removed in C++11 with unique_ptr
|
||||||
|
defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr
|
||||||
|
{ }
|
||||||
|
|
||||||
|
moSA (
|
||||||
|
moSAexplorer<Neighbor>& _explorer,
|
||||||
|
eoOptional< moContinuator<Neighbor> > _cont = NULL,
|
||||||
|
)
|
||||||
|
: moLocalSearch<Neighbor> (
|
||||||
|
*(explorer = &_explorer),
|
||||||
|
_cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval ),
|
||||||
|
defaultCool(NULL), // removed in C++11 with unique_ptr
|
||||||
|
default_eval(NULL), // removed in C++11 with unique_ptr
|
||||||
|
trueCont(NULL), // removed in C++11 with unique_ptr
|
||||||
|
defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual ~moSA ()
|
||||||
|
{
|
||||||
|
// Note: using unique_ptr would allow us to remove this explicit destructor, but they were only introduced in C++11
|
||||||
|
if (trueCont != NULL)
|
||||||
|
delete trueCont;
|
||||||
|
if (defaultSolNeighborComp != NULL)
|
||||||
|
delete defaultSolNeighborComp;
|
||||||
|
if (default_eval != NULL)
|
||||||
|
delete default_eval;
|
||||||
|
if (defaultCool != NULL)
|
||||||
|
delete defaultCool;
|
||||||
|
delete explorer;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
moTrueContinuator<Neighbor> trueCont;
|
moSAexplorer<Neighbor>* explorer; // Not NULL
|
||||||
moSimpleCoolingSchedule<EOT> defaultCool;
|
moSimpleCoolingSchedule<EOT>* defaultCool; // C++11: const std::unique_ptr<moSimpleCoolingSchedule<EOT>>
|
||||||
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
|
moFullEvalByCopy<Neighbor>* default_eval;
|
||||||
moSAexplorer<Neighbor> explorer;
|
moTrueContinuator<Neighbor>* trueCont;
|
||||||
|
moSolNeighborComparator<Neighbor>* defaultSolNeighborComp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,26 @@
|
||||||
/*
|
/*
|
||||||
<moBestFitnessStat.h>
|
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
|
||||||
|
|
||||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
(c) Thales group, 2010
|
||||||
|
|
||||||
This software is governed by the CeCILL license under French law and
|
This library is free software; you can redistribute it and/or
|
||||||
abiding by the rules of distribution of free software. You can use,
|
modify it under the terms of the GNU Lesser General Public
|
||||||
modify and/ or redistribute the software under the terms of the CeCILL
|
License as published by the Free Software Foundation;
|
||||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
version 2 of the License.
|
||||||
"http://www.cecill.info".
|
|
||||||
|
|
||||||
As a counterpart to the access to the source code and rights to copy,
|
This library is distributed in the hope that it will be useful,
|
||||||
modify and redistribute granted by the license, users are provided only
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
with a limited warranty and the software's author, the holder of the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
economic rights, and the successive licensors have only limited liability.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
In this respect, the user's attention is drawn to the risks associated
|
You should have received a copy of the GNU Lesser General Public
|
||||||
with loading, using, modifying and/or developing or reproducing the
|
License along with this library; if not, write to the Free Software
|
||||||
software by the user in light of its specific status of free software,
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
that may mean that it is complicated to manipulate, and that also
|
|
||||||
therefore means that it is reserved for developers and experienced
|
Contact: http://eodev.sourceforge.net
|
||||||
professionals having in-depth computer knowledge. Users are therefore
|
|
||||||
encouraged to load and test the software's suitability as regards their
|
Authors:
|
||||||
requirements in conditions enabling the security of their systems and/or
|
Lionel Parreaux <lionel.parreaux@gmail.com>
|
||||||
data to be ensured and, more generally, to use and operate it in the
|
|
||||||
same conditions as regards security.
|
|
||||||
The fact that you are presently reading this means that you have had
|
|
||||||
knowledge of the CeCILL license and that you accept its terms.
|
|
||||||
|
|
||||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef moFitnessMomentsStat_h
|
#ifndef moFitnessMomentsStat_h
|
||||||
|
|
|
||||||
|
|
@ -141,10 +141,10 @@ public:
|
||||||
//costs_sum += _solution.fitness();
|
//costs_sum += _solution.fitness();
|
||||||
//varStat(_solution);
|
//varStat(_solution);
|
||||||
if (statIsInitialized)
|
if (statIsInitialized)
|
||||||
momStat(_solution);
|
momentStat(_solution);
|
||||||
else momStat.init(_solution), statIsInitialized = true;
|
else momentStat.init(_solution), statIsInitialized = true;
|
||||||
|
|
||||||
//cout << _solution.fitness() << " avgCost=" << momStat.value().first << endl;
|
//cout << _solution.fitness() << " avgCost=" << momentStat.value().first << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -167,21 +167,20 @@ public:
|
||||||
//double avgCost = costs_sum/(double)accepted;
|
//double avgCost = costs_sum/(double)accepted;
|
||||||
//double stdDev = sqrt(varStat.value()); // WARNING: IT'S NO MORE THE AVG COST, NOW IT'S THE STD DEV!
|
//double stdDev = sqrt(varStat.value()); // WARNING: IT'S NO MORE THE AVG COST, NOW IT'S THE STD DEV!
|
||||||
//double variance = varStat.value();
|
//double variance = varStat.value();
|
||||||
double avgCost = momStat.value().first;
|
double avgCost = momentStat.value().first;
|
||||||
double variance = momStat.value().second;
|
double variance = momentStat.value().second;
|
||||||
double stdDev = sqrt(variance);
|
double stdDev = sqrt(variance);
|
||||||
double sigma = stdDev;
|
double sigma = stdDev;
|
||||||
double delta = sigma/mu2;
|
double delta = sigma/mu2;
|
||||||
|
|
||||||
|
|
||||||
//outf << avgCost << endl;
|
//outf << avgCost << endl;
|
||||||
//outf << _temp << endl;
|
outf << _temp << endl;
|
||||||
outf << prevAvgCost-delta << endl;
|
//outf << prevAvgCost-delta << endl;
|
||||||
|
|
||||||
|
|
||||||
accepted = generated = costs_sum = 0;
|
accepted = generated = costs_sum = 0;
|
||||||
//varStat.init(_solution);//TODON use next chain's first sol
|
//momentStat.init(_solution);//TODONE use next chain's first sol
|
||||||
//momStat.init(_solution);//TODONE use next chain's first sol
|
|
||||||
statIsInitialized = false;
|
statIsInitialized = false;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
@ -342,7 +341,7 @@ private:
|
||||||
bool reinitializing, terminated;
|
bool reinitializing, terminated;
|
||||||
|
|
||||||
//moFitnessVarianceStat<EOT> varStat;
|
//moFitnessVarianceStat<EOT> varStat;
|
||||||
moFitnessMomentsStat<EOT> momStat;
|
moFitnessMomentsStat<EOT> momentStat;
|
||||||
bool statIsInitialized;
|
bool statIsInitialized;
|
||||||
|
|
||||||
ofstream outf;
|
ofstream outf;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,16 @@ public:
|
||||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||||
* @param _coolingSchedule the cooling schedule
|
* @param _coolingSchedule the cooling schedule
|
||||||
*/
|
*/
|
||||||
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT>& _coolingSchedule) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
|
moSAexplorer (
|
||||||
|
Neighborhood& _neighborhood,
|
||||||
|
moEval<Neighbor>& _eval,
|
||||||
|
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||||
|
moCoolingSchedule<EOT>& _coolingSchedule
|
||||||
|
)
|
||||||
|
: moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval),
|
||||||
|
solNeighborComparator(_solNeighborComparator),
|
||||||
|
coolingSchedule(_coolingSchedule)
|
||||||
|
{
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
|
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@
|
||||||
#include <coolingSchedule/moDynSpanCoolingSchedule.h>
|
#include <coolingSchedule/moDynSpanCoolingSchedule.h>
|
||||||
#include <coolingSchedule/moSimpleCoolingSchedule.h>
|
#include <coolingSchedule/moSimpleCoolingSchedule.h>
|
||||||
#include <coolingSchedule/moDynSpanCoolingSchedule.h>
|
#include <coolingSchedule/moDynSpanCoolingSchedule.h>
|
||||||
|
#include <coolingSchedule/moTrikiCoolingSchedule.h>
|
||||||
|
|
||||||
#include <eval/moDummyEval.h>
|
#include <eval/moDummyEval.h>
|
||||||
#include <eval/moEval.h>
|
#include <eval/moEval.h>
|
||||||
|
|
@ -112,6 +113,7 @@
|
||||||
#include <eval/moFullEvalByCopy.h>
|
#include <eval/moFullEvalByCopy.h>
|
||||||
#include <eval/moFullEvalByModif.h>
|
#include <eval/moFullEvalByModif.h>
|
||||||
#include <eval/moDoubleIncrNeighborhoodEval.h>
|
#include <eval/moDoubleIncrNeighborhoodEval.h>
|
||||||
|
#include <eval/queenEval.h>
|
||||||
|
|
||||||
#include <explorer/moDummyExplorer.h>
|
#include <explorer/moDummyExplorer.h>
|
||||||
#include <explorer/moFirstImprHCexplorer.h>
|
#include <explorer/moFirstImprHCexplorer.h>
|
||||||
|
|
@ -207,5 +209,6 @@
|
||||||
#include <sampling/moRndRndFitnessCloudSampling.h>
|
#include <sampling/moRndRndFitnessCloudSampling.h>
|
||||||
#include <sampling/moSampling.h>
|
#include <sampling/moSampling.h>
|
||||||
#include <sampling/moStatistics.h>
|
#include <sampling/moStatistics.h>
|
||||||
|
#include <sampling/moStdDevEstimator.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
// (c) Thales group, 2010
|
|
||||||
/*
|
|
||||||
Authors:
|
|
||||||
Johann Dreo <johann.dreo@thalesgroup.com>
|
|
||||||
Caner Candan <caner.candan@thalesgroup.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _trikisa_
|
|
||||||
#define _trikisa_
|
|
||||||
|
|
||||||
#include "moRealNeighbor.h"
|
|
||||||
#include "moRealNeighborhood.h"
|
|
||||||
#include "moStdDevEstimator.h"
|
|
||||||
#include "moTrikiCoolingSchedule.h"
|
|
||||||
#include "moFitnessVarianceStat.h" // TODO rm
|
|
||||||
#include "moFitnessMomentsStat.h"
|
|
||||||
|
|
||||||
#endif // !_trikisa_
|
|
||||||
|
|
||||||
// Local Variables:
|
|
||||||
// mode: C++
|
|
||||||
// End:
|
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
//============================================================================
|
||||||
|
// Name : Trikitest.cpp
|
||||||
|
// Author :
|
||||||
|
// Version :
|
||||||
|
// Copyright : Your copyright notice
|
||||||
|
// Description : Hello World in C++, Ansi-style
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
//#define HAVE_GNUPLOT
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <mo>
|
||||||
|
#include <eo>
|
||||||
|
|
||||||
|
//Representation and initializer
|
||||||
|
#include <eoInt.h>
|
||||||
|
#include <eoInit.h>
|
||||||
|
#include <eoScalarFitness.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
// fitness function
|
||||||
|
#include <eval/queenEval.h>
|
||||||
|
#include <eval/moFullEvalByModif.h>
|
||||||
|
#include <eval/moFullEvalByCopy.h>
|
||||||
|
|
||||||
|
//Neighbors and Neighborhoods
|
||||||
|
#include <problems/permutation/moShiftNeighbor.h>
|
||||||
|
#include <neighborhood/moRndWithReplNeighborhood.h>
|
||||||
|
|
||||||
|
//Algorithm and its components
|
||||||
|
#include <coolingSchedule/moCoolingSchedule.h>
|
||||||
|
#include <algo/moSA.h>
|
||||||
|
|
||||||
|
//comparator
|
||||||
|
#include <comparator/moSolNeighborComparator.h>
|
||||||
|
|
||||||
|
//continuators
|
||||||
|
#include <continuator/moTrueContinuator.h>
|
||||||
|
#include <continuator/moCheckpoint.h>
|
||||||
|
#include <continuator/moFitnessStat.h>
|
||||||
|
#include <utils/eoFileMonitor.h>
|
||||||
|
#include <continuator/moCounterMonitorSaver.h>
|
||||||
|
*/
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
typedef eoInt<eoMinimizingFitness> Queen; //Permutation (Queen's problem representation)
|
||||||
|
|
||||||
|
typedef moShiftNeighbor<Queen> shiftNeighbor; //shift Neighbor
|
||||||
|
typedef moRndWithReplNeighborhood<shiftNeighbor> rndShiftNeighborhood; //rnd shift Neighborhood (Indexed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
|
||||||
|
//return 0;
|
||||||
|
|
||||||
|
unsigned vecSize = 8;
|
||||||
|
|
||||||
|
|
||||||
|
queenEval<Queen> fullEval;
|
||||||
|
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* Initilization of the solution
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
eoInitPermutation<Queen> init(vecSize);
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* evaluation of a neighbor solution
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
moFullEvalByCopy<shiftNeighbor> shiftEval(fullEval); /// by default
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* the neighborhood of a solution
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
rndShiftNeighborhood rndShiftNH((vecSize-1) * (vecSize-1));
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* the cooling schedule of the process
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* the local search algorithm
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
*
|
||||||
|
* execute the local search from random solution
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
|
Queen solution1;
|
||||||
|
|
||||||
|
init(solution1);
|
||||||
|
|
||||||
|
fullEval(solution1);
|
||||||
|
|
||||||
|
moStdDevEstimator<Queen, shiftNeighbor> initTemp (500, rndShiftNH, fullEval);
|
||||||
|
|
||||||
|
moTrueContinuator<shiftNeighbor> continuator;
|
||||||
|
moCheckpoint<shiftNeighbor> checkpoint(continuator);
|
||||||
|
moFitnessStat<Queen> fitStat;
|
||||||
|
checkpoint.add(fitStat);
|
||||||
|
eoFileMonitor monitor("triki.out", "");
|
||||||
|
eoGnuplot1DMonitor monitor2("trikignu.out", true);
|
||||||
|
moCounterMonitorSaver countMon(100, monitor);
|
||||||
|
checkpoint.add(countMon);
|
||||||
|
moCounterMonitorSaver gnuMon (1, monitor2);
|
||||||
|
checkpoint.add(gnuMon);
|
||||||
|
monitor.add(fitStat);
|
||||||
|
monitor2.add(fitStat);
|
||||||
|
//#ifdef HAVE_GNUPLOT
|
||||||
|
|
||||||
|
|
||||||
|
moTrikiCoolingSchedule<Queen, shiftNeighbor> coolingSchedule(rndShiftNH, shiftEval, initTemp(solution1));
|
||||||
|
moSA<shiftNeighbor> localSearch1(rndShiftNH, fullEval, coolingSchedule, shiftEval, checkpoint);
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "#########################################" << std::endl;
|
||||||
|
std::cout << "initial solution1: " << solution1 << std::endl ;
|
||||||
|
|
||||||
|
localSearch1(solution1);
|
||||||
|
|
||||||
|
std::cout << "final solution1: " << solution1 << std::endl ;
|
||||||
|
std::cout << "#########################################" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,8 +28,6 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
|
||||||
#include <es.h>
|
#include <es.h>
|
||||||
#include <edo>
|
#include <edo>
|
||||||
|
|
||||||
//#include <trikisa>
|
|
||||||
|
|
||||||
#include <edoBounderUniform.h>
|
#include <edoBounderUniform.h>
|
||||||
|
|
||||||
#include "neighborhood/moRealNeighbor.h"
|
#include "neighborhood/moRealNeighbor.h"
|
||||||
|
|
@ -40,10 +38,6 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
|
||||||
#include "coolingSchedule/moTrikiCoolingSchedule.h"
|
#include "coolingSchedule/moTrikiCoolingSchedule.h"
|
||||||
|
|
||||||
|
|
||||||
//#include "moRealInitTemperature.h"
|
|
||||||
|
|
||||||
//#include "do/make_real_init_temperature.h"
|
|
||||||
|
|
||||||
typedef eoReal< eoMinimizingFitness > EOT;
|
typedef eoReal< eoMinimizingFitness > EOT;
|
||||||
typedef moRealNeighbor< EOT > Neighbor;
|
typedef moRealNeighbor< EOT > Neighbor;
|
||||||
|
|
||||||
|
|
@ -52,9 +46,9 @@ double objective_function(const EOT & sol)
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
for ( size_t i = 0; i < sol.size(); ++i )
|
for ( size_t i = 0; i < sol.size(); ++i )
|
||||||
{
|
{
|
||||||
sum += sol[i] * sol[i];
|
sum += sol[i] * sol[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
@ -66,18 +60,10 @@ int main( int ac, char** av )
|
||||||
eoState state;
|
eoState state;
|
||||||
|
|
||||||
eoEvalFuncPtr< EOT, double > eval( objective_function );
|
eoEvalFuncPtr< EOT, double > eval( objective_function );
|
||||||
moFullEvalByCopy< Neighbor > fullEval( eval );
|
moFullEvalByCopy< Neighbor > neval( eval );
|
||||||
|
|
||||||
//moNeighborhood< Neighbor >* neighborhood;
|
|
||||||
|
|
||||||
int dimSize = 20;
|
int dimSize = 20;
|
||||||
|
|
||||||
//moRealInitTemperature< EOT >& real_init = do_make_real_init_temperature( parser, state, eval );
|
|
||||||
//moInitTemperature< EOT, Neighbor >& real_init = do_make_real_init_temperature( parser, state, eval, neval );
|
|
||||||
//moInitTemperature< EOT, Neighbor >& real_init = do_make_init_temperature<EOT, Neighbor>( parser, state, eval, neval, neighborhood );
|
|
||||||
//moStdDevEstimator< EOT, Neighbor >& real_init = do_make_init_temperature<EOT, Neighbor>( parser, state, eval, neval, neighborhood, dimSize );
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// Parameters
|
// Parameters
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
@ -87,7 +73,6 @@ int main( int ac, char** av )
|
||||||
unsigned int dimension_size = parser.getORcreateParam( (unsigned int)dimSize, "dimension-size", "Dimension size", 'd', section ).value();
|
unsigned int dimension_size = parser.getORcreateParam( (unsigned int)dimSize, "dimension-size", "Dimension size", 'd', section ).value();
|
||||||
double jump_bound = parser.getORcreateParam( (double)1, "jump-bound", "Bound of jump", '\0', section ).value();
|
double jump_bound = parser.getORcreateParam( (double)1, "jump-bound", "Bound of jump", '\0', section ).value();
|
||||||
unsigned int maxiter = parser.getORcreateParam( (unsigned int)10, "max-iter", "Maximum number of iterations", '\0', section ).value();
|
unsigned int maxiter = parser.getORcreateParam( (unsigned int)10, "max-iter", "Maximum number of iterations", '\0', section ).value();
|
||||||
//unsigned int ratio = parser.getORcreateParam( (unsigned int)1, "ratio", "Bounder ratio", '\0', section ).value(); // not used
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -102,13 +87,9 @@ int main( int ac, char** av )
|
||||||
|
|
||||||
edoSamplerUniform< EOT > sampler( bounder_search );
|
edoSamplerUniform< EOT > sampler( bounder_search );
|
||||||
|
|
||||||
//moRealNeighborhood< edoUniform< EOT >, Neighbor >* neighborhood = new moRealNeighborhood< edoUniform< EOT >, Neighbor >( *distrib, *sampler, *bounder_search );
|
|
||||||
moRealNeighborhood< edoUniform< EOT >, Neighbor > neighborhood( distrib, sampler, bounder_search );
|
moRealNeighborhood< edoUniform< EOT >, Neighbor > neighborhood( distrib, sampler, bounder_search );
|
||||||
//state.storeFunctor(neighborhood);state.storeFunctor(neighborhood);
|
|
||||||
|
|
||||||
//moStdDevEstimator< EOT, Neighbor >* init = new moStdDevEstimator< EOT, Neighbor >( *neighborhood, fullEval, eval, maxiter );
|
moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, eval );
|
||||||
//moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, fullEval, eval );
|
|
||||||
moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, fullEval );
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -130,56 +111,51 @@ int main( int ac, char** av )
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
//EOT solution(2, 5);
|
|
||||||
EOT solution(dimSize, 5);
|
EOT solution(dimSize, 5);
|
||||||
/*
|
|
||||||
real_init( solution );
|
|
||||||
|
|
||||||
std::cout << "do_make_real_init_temperature( parser, eval ): "
|
std::cout << "init temp: "
|
||||||
<< real_init.value()
|
<< init( solution )
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
*/
|
|
||||||
|
|
||||||
std::cout << "do_make_real_init_temperature( parser, eval ): "
|
|
||||||
<< init( solution )
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
moTrueContinuator<Neighbor> continuator;
|
moTrueContinuator<Neighbor> continuator;
|
||||||
moCheckpoint<Neighbor> checkpoint(continuator);
|
moCheckpoint<Neighbor> checkpoint(continuator);
|
||||||
moFitnessStat<EOT> fitStat;
|
moFitnessStat<EOT> fitStat;
|
||||||
checkpoint.add(fitStat);
|
checkpoint.add(fitStat);
|
||||||
eoFileMonitor monitor("triki.out", "");
|
eoFileMonitor monitor("triki.out", "");
|
||||||
//eoGnuplot1DMonitor monitor2("trikignu.out", true);
|
//eoGnuplot1DMonitor monitor2("trikignu.out", true);
|
||||||
moCounterMonitorSaver countMon(1, monitor);
|
moCounterMonitorSaver countMon(1, monitor);
|
||||||
checkpoint.add(countMon);
|
checkpoint.add(countMon);
|
||||||
//moCounterMonitorSaver gnuMon (1, monitor2);
|
//moCounterMonitorSaver gnuMon (1, monitor2);
|
||||||
//checkpoint.add(gnuMon);
|
//checkpoint.add(gnuMon);
|
||||||
monitor.add(fitStat);
|
monitor.add(fitStat);
|
||||||
//monitor2.add(fitStat);
|
//monitor2.add(fitStat);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
moTrikiCoolingSchedule<EOT, Neighbor> coolingSchedule (
|
moTrikiCoolingSchedule<EOT, Neighbor> coolingSchedule (
|
||||||
neighborhood, neval, init( solution ),
|
neighborhood, neval, init( solution ),
|
||||||
//50,
|
//50,
|
||||||
200, //150,
|
200, //150,
|
||||||
//100
|
//100
|
||||||
350 // 250
|
350 // 250
|
||||||
);
|
);
|
||||||
moSA<Neighbor> localSearch(*neighborhood, eval, fullEval, coolingSchedule, checkpoint);
|
//moSA<Neighbor> localSearch(neighborhood, eval, neval, coolingSchedule, checkpoint);
|
||||||
|
//moSA<Neighbor> localSearch(neighborhood, eval, neval);
|
||||||
|
//moSA<Neighbor> localSearch(neighborhood, eval, coolingSchedule, neval, checkpoint);
|
||||||
|
//moSA<Neighbor> localSearch(neighborhood, eval, coolingSchedule);
|
||||||
|
moSA<Neighbor> localSearch(neighborhood, eval, coolingSchedule, neval, checkpoint);
|
||||||
|
|
||||||
std::cout << "#########################################" << std::endl;
|
std::cout << "#########################################" << std::endl;
|
||||||
std::cout << "initial solution1: " << solution << std::endl ;
|
std::cout << "initial solution1: " << solution << std::endl ;
|
||||||
|
|
||||||
localSearch(solution);
|
localSearch(solution);
|
||||||
|
|
||||||
std::cout << "final solution1: " << solution << std::endl ;
|
std::cout << "final solution1: " << solution << std::endl ;
|
||||||
std::cout << "#########################################" << std::endl;
|
std::cout << "#########################################" << std::endl;
|
||||||
|
|
||||||
//delete neighborhood;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue