updated all mo tests

This commit is contained in:
LPTK 2013-07-19 13:49:02 +02:00
commit eec9e9fd56
8 changed files with 494 additions and 26 deletions

View file

@ -1,5 +1,30 @@
/*
(c) Thales group, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Lionel Parreaux <lionel.parreaux@gmail.com>
*/
//-----------------------------------------------------------------------------
// t-moFitnessNeighborStat.cpp
// t-moFitnessVarianceStat.cpp
//-----------------------------------------------------------------------------
#include <eo>
@ -13,12 +38,30 @@
typedef eoReal< eoMinimizingFitness > EOT;
typedef moRealNeighbor< EOT > Neighbor;
double objective_function(const EOT & sol)
{
double sum = 0;
for ( size_t i = 0; i < sol.size(); ++i )
{
sum += sol[i] * sol[i];
}
return sum;
}
int main(int ac, char** av)
{
//moNeighborhoodStat<Neighbor> nhStat
moFitnessVarianceStat<EOT> stat;
eoEvalFuncPtr< EOT, double > eval( objective_function );
EOT solution(2, 5);
eval(solution);
stat(solution);
//assert(stat.value() == 1);
std::cout << "ok " << stat.value() << std::endl;
solution[0] = solution[1] = 0;
solution.invalidate();
eval(solution);
stat(solution);
std::cout << "var: " << stat.value() << std::endl;
assert(stat.value() == 625);
std::cout << "[t-moFitnessNeighborStat] => OK" << std::endl;
}

View file

@ -1,5 +1,5 @@
/*
<t-moMetropolisHasting.cpp>
<t-moMetropolisHastings.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
@ -27,11 +27,15 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
// t-moMetropolisHastings.cpp
//-----------------------------------------------------------------------------
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <algo/moMetropolisHasting.h>
#include <algo/moMetropolisHastings.h>
#include "moTestClass.h"
#include <eval/oneMaxEval.h>
#include <continuator/moTrueContinuator.h>
@ -40,25 +44,24 @@ Contact: paradiseo-help@lists.gforge.inria.fr
int main() {
std::cout << "[t-moMetropolisHasting] => START" << std::endl;
std::cout << "[t-moMetropolisHastings] => START" << std::endl;
bitNeighborhood nh(4);
oneMaxEval<bitVector> fullEval;
evalOneMax eval(4);
moTrueContinuator<bitNeighbor> cont;
moSolNeighborComparator<bitNeighbor> sncomp;
moNeighborComparator<bitNeighbor> ncomp;
//test du 1er constructeur
moMetropolisHasting<bitNeighbor> test1(nh, fullEval, eval, 3);
moMetropolisHastings<bitNeighbor> test1(nh, fullEval, eval, 3);
//test du 2eme constructeur
moMetropolisHasting<bitNeighbor> test2(nh, fullEval, eval, 3, cont);
moMetropolisHastings<bitNeighbor> test2(nh, fullEval, eval, 3, cont);
//test du 3eme constructeur
moMetropolisHasting<bitNeighbor> test3(nh, fullEval, eval, 3, cont, ncomp, sncomp);
moMetropolisHastings<bitNeighbor> test3(nh, fullEval, eval, 3, cont, sncomp);
std::cout << "[t-moMetropolisHasting] => OK" << std::endl;
std::cout << "[t-moMetropolisHastings] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -1,5 +1,5 @@
/*
<t-moMetropolisHastingExplorer.cpp>
<t-moMetropolisHastingsExplorer.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
@ -27,7 +27,11 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <explorer/moMetropolisHastingExplorer.h>
//-----------------------------------------------------------------------------
// t-moSimpleMetropolisHastingsExplorer.cpp
//-----------------------------------------------------------------------------
#include <explorer/moSimpleMetropolisHastingsExplorer.h>
#include "moTestClass.h"
#include <iostream>
@ -36,7 +40,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
int main() {
std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl;
std::cout << "[t-moMetropolisHastingsExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
@ -45,8 +49,8 @@ int main() {
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moMetropolisHastingExplorer<bitNeighbor> test(nh, eval, ncomp, sncomp, 3);
moSimpleMetropolisHastingsExplorer<bitNeighbor> test(nh, eval, 3, sncomp);
//test de l'acceptation d'un voisin améliorant
test.initParam(sol);
@ -90,7 +94,7 @@ int main() {
test(sol);
assert(!test.accept(sol));
std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl;
std::cout << "[t-moMetropolisHastingsExplorer] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -51,12 +51,12 @@ int main() {
//test second constructor
moSimpleCoolingSchedule<bitVector> cool(10, 0.9, 100, 0.01);
moSA<bitNeighbor> test2(nh, fullEval, eval, cool);
moSA<bitNeighbor> test2(nh, fullEval, cool, eval);
//test third constructor
moTrueContinuator<bitNeighbor> cont;
moSolNeighborComparator<bitNeighbor> comp;
moSA<bitNeighbor> test3(nh, fullEval, eval, cool, comp, cont);
moSA<bitNeighbor> test3(nh, fullEval, cool, eval, cont, comp);
std::cout << "[t-moSA] => OK" << std::endl;

View file

@ -1,5 +1,5 @@
/*
<t-moSAexplorer.cpp>
<t-moSAExplorer.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
@ -32,12 +32,12 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cassert>
#include "moTestClass.h"
#include <explorer/moSAexplorer.h>
#include <explorer/moSAExplorer.h>
#include <coolingSchedule/moSimpleCoolingSchedule.h>
int main() {
std::cout << "[t-moSAexplorer] => START" << std::endl;
std::cout << "[t-moSAExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
@ -47,8 +47,8 @@ int main() {
moSolNeighborComparator<bitNeighbor> sncomp;
moSimpleCoolingSchedule<bitVector> cool(10,0.1,2,0.1);
moSAexplorer<bitNeighbor> test1(emptyNH, eval, sncomp, cool);
moSAexplorer<bitNeighbor> test2(nh, eval, sncomp, cool);
moSAExplorer<bitNeighbor> test1(emptyNH, eval, cool, sncomp);
moSAExplorer<bitNeighbor> test2(nh, eval, cool, sncomp);
//test d'un voisinage vide
test1.initParam(sol);
@ -80,7 +80,7 @@ int main() {
std::cout << "[t-moSAexplorer] => OK" << std::endl;
std::cout << "[t-moSAExplorer] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,86 @@
/*
(c) Thales group, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Lionel Parreaux <lionel.parreaux@gmail.com>
*/
//-----------------------------------------------------------------------------
// t-moStdDevEstimator.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include "es/eoReal.h"
#include "neighborhood/moRealNeighbor.h"
//Representation and initializer
#include <eoInt.h>
//#include <eoInit.h>
#include <eoScalarFitness.h>
// fitness function
#include <eval/queenEval.h>
//Neighbors and Neighborhoods
#include <problems/permutation/moShiftNeighbor.h>
#include <neighborhood/moRndWithReplNeighborhood.h>
//Sampling
#include <sampling/moStdDevEstimator.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)
//-----------------------------------------------------------------------------
typedef eoReal< eoMinimizingFitness > EOT;
typedef moRealNeighbor< EOT > Neighbor;
int main(int ac, char** av)
{
unsigned vecSize = 8;
queenEval<Queen> fullEval;
eoInitPermutation<Queen> init(vecSize);
rndShiftNeighborhood rndShiftNH((vecSize-1) * (vecSize-1));
Queen solution;
init(solution);
fullEval(solution);
moStdDevEstimator<Queen, shiftNeighbor> initTemp (500, rndShiftNH, fullEval);
double temp = initTemp(solution);
std::cout << "temp: " << temp << std::endl;
assert(temp >= 0);
}

View file

@ -0,0 +1,164 @@
//============================================================================
// Name : Trikitest.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
// FIXME proper header
//#define HAVE_GNUPLOT
#include <iostream>
using namespace std;
#include <mo>
#include <eo>
//Representation and initializer
#include <eoInt.h>
#include <eoInit.h>
#include <eoScalarFitness.h>
#include <eval/queenEval.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 solution;
init(solution);
fullEval(solution);
//moStdDevEstimator<Queen, ShiftNeighbor> stdDevEst (500, rndShiftNH, fullEval);
double stdDevEst = moStdDevEstimator<Queen, ShiftNeighbor>(500, rndShiftNH, fullEval)(solution);
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 (10, monitor2);
checkpoint.add(gnuMon);
monitor.add(fitStat);
monitor2.add(fitStat);
//#ifdef HAVE_GNUPLOT
//moTrikiCoolingSchedule<ShiftNeighbor> coolingSchedule(rndShiftNH, shiftEval, initTemp(solution1));
//moTrikiCoolingSchedule<Queen> coolingSchedule(initTemp(solution));
moTrikiCoolingSchedule<Queen> coolingSchedule(stdDevEst, stdDevEst);
moSA<ShiftNeighbor> localSearch(rndShiftNH, fullEval, coolingSchedule, shiftEval, checkpoint);
//moSA<ShiftNeighbor> localSearch(rndShiftNH, fullEval, shiftEval);
//moSA<ShiftNeighbor> localSearch(rndShiftNH, fullEval, coolingSchedule);
std::cout << "#########################################" << std::endl;
std::cout << "initial solution: " << solution << std::endl ;
localSearch(solution);
std::cout << "final solution: " << solution << std::endl ;
std::cout << "#########################################" << std::endl;
}

View file

@ -0,0 +1,168 @@
/*
(c) Thales group, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Lionel Parreaux <lionel.parreaux@gmail.com>
*/
#include <mo>
#include <eo>
#include <es.h>
#include <edo>
#include <edoBounderUniform.h>
#include "neighborhood/moRealNeighbor.h"
#include "neighborhood/moRealNeighborhood.h"
#include "sampling/moStdDevEstimator.h"
#include "coolingSchedule/moTrikiCoolingSchedule.h"
typedef eoReal< eoMinimizingFitness > EOT;
typedef moRealNeighbor< EOT > Neighbor;
double objective_function(const EOT & sol)
{
double sum = 0;
for ( size_t i = 0; i < sol.size(); ++i )
{
sum += sol[i] * sol[i];
}
return sum;
}
int main( int ac, char** av )
{
eoParser parser( ac, av );
eoState state;
eoEvalFuncPtr< EOT, double > eval( objective_function );
moFullEvalByCopy< Neighbor > neval( eval );
int dimSize = 15;
//-------------------------------------------------------
// Parameters
//-------------------------------------------------------
std::string section( "Temperature initialization paramaters" );
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();
unsigned int maxiter = parser.getORcreateParam( (unsigned int)10, "max-iter", "Maximum number of iterations", '\0', section ).value();
//-------------------------------------------------------
//-------------------------------------------------------
// Instanciate needed classes
//-------------------------------------------------------
edoUniform< EOT > distrib( EOT(dimension_size, -1 * jump_bound), EOT(dimension_size, 1 * jump_bound) );
edoBounder< EOT > bounder_search( EOT(dimension_size, -10), EOT(dimension_size, 10) );
edoSamplerUniform< EOT > sampler( bounder_search );
moRealNeighborhood< edoUniform< EOT >, Neighbor > neighborhood( distrib, sampler, bounder_search );
moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, eval );
//-------------------------------------------------------
//-------------------------------------------------------
// Help + Verbose routines
//-------------------------------------------------------
if (parser.userNeedsHelp())
{
parser.printHelp(std::cout);
exit(1);
}
make_help(parser);
//-------------------------------------------------------
EOT solution(dimSize, 5);
std::cout << "init temp: "
<< init( solution )
<< std::endl;
moTrueContinuator<Neighbor> continuator;
moCheckpoint<Neighbor> checkpoint(continuator);
moFitnessStat<EOT> 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);
double stdDevEst = init( solution );
moTrikiCoolingSchedule<EOT> coolingSchedule (
stdDevEst,
stdDevEst,
//50,
150,//200, //150,
//100
250//350 // 250
);
//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 << "initial solution1: " << solution << std::endl ;
localSearch(solution);
std::cout << "final solution1: " << solution << std::endl ;
std::cout << "#########################################" << std::endl;
return 0;
}