Leçon 4 modifiée + ajout de moTimeContinuator

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1771 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-05-03 09:18:09 +00:00
commit 1e820da259
3 changed files with 139 additions and 33 deletions

View file

@ -0,0 +1,88 @@
/*
<moTimeContinuator.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
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 _moTimeContinuator_h
#define _moTimeContinuator_h
#include <moContinuator.h>
/**
* Termination condition until a running time is reached.
*/
template < class Neighbor >
class moTimeContinuator: public moContinuator<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
/**
* Ctor.
* @param _max maximum running time
*/
moTimeContinuator(time_t _max): max(_max){
start = time(NULL);
}
/**
* Returns false when the running time is reached.
* @param _sol the current solution
*/
virtual bool operator() (EOT& _sol)
{
time_t elapsed = (time_t) difftime(time(NULL), start);
if (elapsed >= max)
{
std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl;
return false;
}
return true;
}
/**
* Class name
*/
virtual std::string className(void) const
{
return "moTimeContinuator";
}
private:
/** maximum running time */
time_t max;
/** starting time */
time_t start;
};
#endif

View file

@ -69,6 +69,7 @@
#include <continuator/moCombinedContinuator.h>
#include <continuator/moFullEvalContinuator.h>
#include <continuator/moNeighborEvalContinuator.h>
#include <continuator/moTimeContinuator.h>
#include <eval/moEval.h>
#include <eval/moFullEvalByCopy.h>

View file

@ -22,27 +22,48 @@
using namespace std;
//-----------------------------------------------------------------------------
// fitness function
#include <eval/oneMaxEval.h>
#include <problems/bitString/moBitNeighbor.h>
//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>
#include <neighborhood/moOrderNeighborhood.h>
//Algorithm and its components
#include <coolingSchedule/moCoolingSchedule.h>
//#include <algo/moTS.h>
//comparator
#include <comparator/moSolNeighborComparator.h>
#include <comparator/moNeighborComparator.h>
//continuators
#include <continuator/moTrueContinuator.h>
#include <continuator/moCheckpoint.h>
#include <continuator/moFitnessStat.h>
#include <utils/eoFileMonitor.h>
#include <continuator/moCounterMonitorSaver.h>
//mo eval
#include <eval/moFullEvalByModif.h>
#include <eval/moFullEvalByCopy.h>
#include <mo>
#include <eval/moFullEvalByModif.h>
#include <eval/moFullEvalByCopy.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <continuator/moTrueContinuator.h>
#include <algo/moLocalSearch.h>
#include <explorer/moSimpleHCexplorer.h>
// REPRESENTATION
//-----------------------------------------------------------------------------
typedef eoBit<unsigned> Indi;
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
typedef eoInt<eoMinimizingFitness> Queen; //Permutation (Queen's problem representation)
typedef moShiftNeighbor<Queen> shiftNeighbor; //shift Neighbor
typedef moOrderNeighborhood<shiftNeighbor> orderShiftNeighborhood; //rnd shift Neighborhood (Indexed)
void main_function(int argc, char **argv)
{
@ -100,7 +121,7 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
oneMaxEval<Indi> fulleval;
queenEval<Queen> fullEval;
/* =========================================================
@ -109,9 +130,7 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
// a Indi random initializer
eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen);
eoInitPermutation<Queen> init(vecSize);
/* =========================================================
@ -120,30 +139,28 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
moFullEvalByModif<Neighbor> eval(fulleval);
moFullEvalByCopy<shiftNeighbor> shiftEval(fullEval);
//An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval);
/* =========================================================
*
* Comparator of neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* the neighborhood of a solution
*
* ========================================================= */
Neighborhood neighborhood(vecSize);
orderShiftNeighborhood rndShiftNH(pow(vecSize-1, 2));
/* =========================================================
*
* Comparator of neighbors
*
* ========================================================= */
moSolNeighborComparator<shiftNeighbor> solComparator;
moNeighborComparator<shiftNeighbor> comparator;
/* =========================================================
*
@ -151,11 +168,11 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
moSolVectorTabuList<Neighbor> tl(10,10);
moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp;
moTSexplorer<Neighbor> explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp);
moNeighborVectorTabuList<shiftNeighbor> tl(10,10);
moDummyIntensification<shiftNeighbor> inten;
moDummyDiversification<shiftNeighbor> div;
moBestImprAspiration<shiftNeighbor> asp;
moTSexplorer<shiftNeighbor> explorer(rndShiftNH, shiftEval, comparator, solComparator, tl, inten, div, asp);
/* =========================================================
@ -164,9 +181,9 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
moTrueContinuator<Neighbor> continuator;//always continue
moTrueContinuator<shiftNeighbor> continuator;//always continue
moLocalSearch<Neighbor> localSearch(explorer, continuator, fulleval);
moLocalSearch<shiftNeighbor> localSearch(explorer, continuator, fullEval);
/* =========================================================
*
@ -174,9 +191,9 @@ void main_function(int argc, char **argv)
*
* ========================================================= */
Indi solution;
Queen solution;
random(solution);
init(solution);
//Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution);