intermediate commit

This commit is contained in:
LPTK 2013-06-21 18:03:57 +02:00
commit 1e6240f9bf
9 changed files with 370 additions and 178 deletions

View file

@ -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;
}

View file

@ -28,8 +28,6 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
#include <es.h>
#include <edo>
//#include <trikisa>
#include <edoBounderUniform.h>
#include "neighborhood/moRealNeighbor.h"
@ -40,10 +38,6 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
#include "coolingSchedule/moTrikiCoolingSchedule.h"
//#include "moRealInitTemperature.h"
//#include "do/make_real_init_temperature.h"
typedef eoReal< eoMinimizingFitness > EOT;
typedef moRealNeighbor< EOT > Neighbor;
@ -52,9 +46,9 @@ double objective_function(const EOT & sol)
double sum = 0;
for ( size_t i = 0; i < sol.size(); ++i )
{
sum += sol[i] * sol[i];
}
{
sum += sol[i] * sol[i];
}
return sum;
}
@ -66,18 +60,10 @@ int main( int ac, char** av )
eoState state;
eoEvalFuncPtr< EOT, double > eval( objective_function );
moFullEvalByCopy< Neighbor > fullEval( eval );
//moNeighborhood< Neighbor >* neighborhood;
moFullEvalByCopy< Neighbor > neval( eval );
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
//-------------------------------------------------------
@ -87,8 +73,7 @@ int main( int ac, char** av )
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();
//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 );
//moRealNeighborhood< edoUniform< EOT >, Neighbor >* neighborhood = new moRealNeighborhood< edoUniform< EOT >, Neighbor >( *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, fullEval, eval );
moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, fullEval );
moStdDevEstimator< EOT, Neighbor > init( maxiter, neighborhood, eval );
//-------------------------------------------------------
@ -129,57 +110,52 @@ int main( int ac, char** av )
//-------------------------------------------------------
//EOT solution(2, 5);
EOT solution(dimSize, 5);
/*
real_init( solution );
std::cout << "do_make_real_init_temperature( parser, eval ): "
<< real_init.value()
<< std::endl;
*/
std::cout << "do_make_real_init_temperature( parser, eval ): "
<< init( solution )
<< std::endl;
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(1, monitor);
checkpoint.add(countMon);
//moCounterMonitorSaver gnuMon (1, monitor2);
//checkpoint.add(gnuMon);
monitor.add(fitStat);
//monitor2.add(fitStat);
moTrueContinuator<Neighbor> continuator;
moCheckpoint<Neighbor> checkpoint(continuator);
moFitnessStat<EOT> fitStat;
checkpoint.add(fitStat);
eoFileMonitor monitor("triki.out", "");
//eoGnuplot1DMonitor monitor2("trikignu.out", true);
moCounterMonitorSaver countMon(1, monitor);
checkpoint.add(countMon);
//moCounterMonitorSaver gnuMon (1, monitor2);
//checkpoint.add(gnuMon);
monitor.add(fitStat);
//monitor2.add(fitStat);
moTrikiCoolingSchedule<EOT, Neighbor> coolingSchedule (
neighborhood, neval, init( solution ),
//50,
200, //150,
//100
350 // 250
);
moSA<Neighbor> localSearch(*neighborhood, eval, fullEval, coolingSchedule, 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;
//delete neighborhood;
moTrikiCoolingSchedule<EOT, Neighbor> coolingSchedule (
neighborhood, neval, init( solution ),
//50,
200, //150,
//100
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;
}