From 856830e4edd3a69a2b7947a40fc76ac33fdb189d Mon Sep 17 00:00:00 2001 From: jhumeau Date: Mon, 29 Mar 2010 09:44:48 +0000 Subject: [PATCH] Debut des travaux sur ILS git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1724 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/acceptCrit/moAcceptanceCriterion.h | 44 ++++ .../src/acceptCrit/moAlwaysAcceptCrit.h | 57 +++++ .../src/acceptCrit/moBetterAcceptCrit.h | 34 +++ .../paradiseo-mo/src/explorer/moILSexplorer.h | 169 +++++++++++++++ .../src/memory/moDummyDiversification.h | 23 +- .../src/memory/moDummyIntensification.h | 23 +- trunk/paradiseo-mo/src/memory/moDummyMemory.h | 67 ++++++ trunk/paradiseo-mo/src/mo.h | 9 + .../paradiseo-mo/src/perturb/moMonOpPerturb.h | 65 ++++++ .../src/perturb/moNeighborhoodPerturb.h | 34 +++ .../paradiseo-mo/src/perturb/moPertubation.h | 43 ++++ .../src/perturb/moRestartPerturb.h | 34 +++ trunk/paradiseo-mo/test/t-moILSexplorer.cpp | 43 ++++ .../oneMax/application/CMakeLists.txt | 4 +- .../tutorial/oneMax/application/testILS.cpp | 198 ++++++++++++++++++ 15 files changed, 804 insertions(+), 43 deletions(-) create mode 100644 trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h create mode 100644 trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h create mode 100644 trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h create mode 100644 trunk/paradiseo-mo/src/explorer/moILSexplorer.h create mode 100644 trunk/paradiseo-mo/src/memory/moDummyMemory.h create mode 100644 trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h create mode 100644 trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h create mode 100644 trunk/paradiseo-mo/src/perturb/moPertubation.h create mode 100644 trunk/paradiseo-mo/src/perturb/moRestartPerturb.h create mode 100644 trunk/paradiseo-mo/test/t-moILSexplorer.cpp create mode 100644 trunk/paradiseo-mo/tutorial/oneMax/application/testILS.cpp diff --git a/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h b/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h new file mode 100644 index 000000000..15d7ae7f5 --- /dev/null +++ b/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h @@ -0,0 +1,44 @@ +/* + +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 _moAcceptanceCriterion_h +#define _moAcceptanceCriterion_h + +#include +#include + +/** + * Abstract class for Acceptance criteria + */ +template< class Neighbor > +class moAcceptanceCriterion : public eoBF, virtual public moMemory{ + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h b/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h new file mode 100644 index 000000000..c4dc385cb --- /dev/null +++ b/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h @@ -0,0 +1,57 @@ +/* + +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 _moAlwaysAcceptCrit_h +#define _moAlwaysAcceptCrit_h + +#include +#include + +/** + * Acceptance Criterion for extreme diversification : always accept new solution + */ +template< class Neighbor > +class moAlwaysAcceptCrit : public moAcceptanceCriterion, public moDummyMemory{ + +public: + typedef typename Neighor::EOT EOT; + + /** + * Always accept the new solution + * @param _sol1 the previous solution + * @param _sol2 the new solution after local search + * @return always true + */ + bool operator()(EOT& _sol1, EOT& _sol2){ + return true; + } + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h b/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h new file mode 100644 index 000000000..def0a398e --- /dev/null +++ b/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h @@ -0,0 +1,34 @@ +/* + +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 _moBetterAcceptCrit_h +#define _moBetterAcceptCrit_h + + +#endif diff --git a/trunk/paradiseo-mo/src/explorer/moILSexplorer.h b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h new file mode 100644 index 000000000..2df3878f4 --- /dev/null +++ b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h @@ -0,0 +1,169 @@ +/* + + 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 use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 _moILSexplorer_h +#define _moILSexplorer_h + +#include +#include +#include +#include +#include +#include + +/** + * Explorer for an Iterated Local Search + */ +template< class NHE > +class moILSexplorer : public moNeighborhoodExplorer +{ +public: + typedef typename NHE::Neighborhood Neighborhood ; + typedef typename Neighborhood::EOT EOT ; + typedef typename Neighborhood::Neighbor Neighbor ; + + using moNeighborhoodExplorer::neighborhood; + using moNeighborhoodExplorer::eval; + + /** + * Constructor + * @param _ls a local search + * @param _perturb a perturbation operator + * @param _acceptCrit a acceptance criteria + */ + moILSexplorer(moLocalSearch& _ls, moPerturbation& _perturb, moAcceptanceCriterion& _acceptCrit) : ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit){ + firstIteration=true; + } + + /** + * Destructor + */ + ~moILSexplorer(){ + + } + + /** + * Init perturbation and acceptance criteria + * @param _solution the current solution + */ + virtual void initParam(EOT & _solution){ + firstIteration=true; + perturb.init(_solution); + acceptCrit.init(_solution); + }; + + /** + * Update perturbation and acceptance criteria + * @param _solution the current solution + */ + virtual void updateParam(EOT & _solution){ + if((*this).isMoved()){ + perturb.add(_solution,emptyNeighbor); + acceptCrit.add(_solution,emptyNeighbor); + } + perturb.update(_solution, emptyNeighbor); + acceptCrit.update(_solution, emptyNeighbor); + }; + + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & _solution){}; + + /** + * Explore the neighborhood of a solution + * @param _solution + */ + virtual void operator()(EOT & _solution){ + //copy the solution to perform new local search + current=_solution; + + //perturb solution exept at the first iteration + if(!firstIteration) + perturb(current); + else + firstIteration=false; + + //apply the local search on the copy + ls(current); + + }; + + /** + * Always continue + * @param _solution the solution + * @return always true + */ + virtual bool isContinue(EOT & _solution) { + return true; + }; + + /** + * move the solution with the best neighbor + * @param _solution the solution to move + */ + virtual void move(EOT & _solution) { + _solution=current; + }; + + /** + * accept test if an ameliorated neighbor was be found + * @param _solution the solution + * @return true if acceptance criteria is verified + */ + virtual bool accept(EOT & _solution) { + return acceptCrit(_solution, current); + }; + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moILSexplorer"; + } + +private: + //Usefull to use the momory of tabuSearch + Neighbor emptyNeighbor; + EOT current; + moLocalSearch& ls; + moPerturbation & perturb; + moAcceptanceCriterion& acceptCrit; + + bool firstIteration; +}; + + +#endif diff --git a/trunk/paradiseo-mo/src/memory/moDummyDiversification.h b/trunk/paradiseo-mo/src/memory/moDummyDiversification.h index f66d8193e..c7fb32bbf 100644 --- a/trunk/paradiseo-mo/src/memory/moDummyDiversification.h +++ b/trunk/paradiseo-mo/src/memory/moDummyDiversification.h @@ -2,36 +2,17 @@ #define _moDummyDiversification_h #include +#include /** * Dummy diversification strategy */ template< class Neighbor > -class moDummyDiversification : public moDiversification +class moDummyDiversification : public moDiversification, public moDummyMemory { public: typedef typename Neighbor::EOT EOT; - /** - * Init : NOTHIING TO DO - */ - void init(EOT & _sol) {} - - /** - * Add : NOTHIING TO DO - */ - void add(EOT & _sol, Neighbor & _neighbor) {} - - /** - * Update : NOTHIING TO DO - */ - void update(EOT & _sol, Neighbor & _neighbor) {} - - /** - * ClearMemory : NOTHIING TO DO - */ - void clearMemory() {} - /** * @return always false */ diff --git a/trunk/paradiseo-mo/src/memory/moDummyIntensification.h b/trunk/paradiseo-mo/src/memory/moDummyIntensification.h index 76a16dca5..85a1311f1 100644 --- a/trunk/paradiseo-mo/src/memory/moDummyIntensification.h +++ b/trunk/paradiseo-mo/src/memory/moDummyIntensification.h @@ -2,36 +2,17 @@ #define _moDummyIntensification_h #include +#include /** * Dummy intensification strategy */ template< class Neighbor > -class moDummyIntensification : public moIntensification +class moDummyIntensification : public moIntensification, public moDummyMemory { public: typedef typename Neighbor::EOT EOT; - /** - * Init : NOTHIING TO DO - */ - void init(EOT & _sol) {} - - /** - * Add : NOTHIING TO DO - */ - void add(EOT & _sol, Neighbor & _neighbor) {} - - /** - * Update : NOTHIING TO DO - */ - void update(EOT & _sol, Neighbor & _neighbor) {} - - /** - * ClearMemory : NOTHIING TO DO - */ - void clearMemory() {} - /** * @return always false */ diff --git a/trunk/paradiseo-mo/src/memory/moDummyMemory.h b/trunk/paradiseo-mo/src/memory/moDummyMemory.h new file mode 100644 index 000000000..40b6c8918 --- /dev/null +++ b/trunk/paradiseo-mo/src/memory/moDummyMemory.h @@ -0,0 +1,67 @@ +/* + +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 _moDummyMemory_h +#define _moDummyMemory_h + +#include + +/** + * Dummy memory to make an empty memory + */ +template< class Neighbor > +class moDummyMemory : virtual public moMemory{ + +public: + typedef typename Neighbor::EOT EOT; + + /** + * Init : NOTHIING TO DO + */ + void init(EOT & _sol) {} + + /** + * Add : NOTHIING TO DO + */ + void add(EOT & _sol, Neighbor & _neighbor) {} + + /** + * Update : NOTHIING TO DO + */ + void update(EOT & _sol, Neighbor & _neighbor) {} + + /** + * ClearMemory : NOTHIING TO DO + */ + void clearMemory() {} + +}; + + +#endif diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index a275a4466..b4944977b 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -72,10 +72,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -94,6 +96,13 @@ #include #include +#include +#include + +#include +#include + + //#include //#include //#include diff --git a/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h b/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h new file mode 100644 index 000000000..d9e4c2644 --- /dev/null +++ b/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h @@ -0,0 +1,65 @@ +/* + +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 _moMonOpPerturb_h +#define _moMonOpPerturb_h + +#include +#include + +/** + * Perturbation operator using only a eoMonOp + */ +template< class Neighbor > +class moMonOpPerturb : public moPerturbation, public moDummyMemory { + +public: + typedef typename Neighbor::EOT EOT; + + /** + * Default Constructor + * @param _monOp an eoMonOp (pertubation operator) + */ + moMonOpPerturb(eoMonOp& _monOp):monOp(_monOp){} + + /** + * Apply monOp on the solution + * @param _solution to perturb + * @return value of monOp + */ + bool operator()(EOT& _solution){ + return monOp(_solution); + } + +private: + /** monOp */ + eoMonOp& monOp; +}; + +#endif diff --git a/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h new file mode 100644 index 000000000..a3ba1b73d --- /dev/null +++ b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h @@ -0,0 +1,34 @@ +/* + +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 _moNeighborhoodPerturb_h +#define _moNeighborhoodPerturb_h + + +#endif diff --git a/trunk/paradiseo-mo/src/perturb/moPertubation.h b/trunk/paradiseo-mo/src/perturb/moPertubation.h new file mode 100644 index 000000000..7802e342e --- /dev/null +++ b/trunk/paradiseo-mo/src/perturb/moPertubation.h @@ -0,0 +1,43 @@ +/* + +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 _moPertubation_h +#define _moPertubation_h + +#include +#include + +/** + * Abstract class for Perturbation operator + */ +template< class Neighbor > +class moPerturbation : public eoMonOp, virtual public moMemory { +}; + +#endif diff --git a/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h new file mode 100644 index 000000000..955e244c0 --- /dev/null +++ b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h @@ -0,0 +1,34 @@ +/* + +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 _moRestartPerturb_h +#define _moRestartPerturb_h + + +#endif diff --git a/trunk/paradiseo-mo/test/t-moILSexplorer.cpp b/trunk/paradiseo-mo/test/t-moILSexplorer.cpp new file mode 100644 index 000000000..6928aa5ab --- /dev/null +++ b/trunk/paradiseo-mo/test/t-moILSexplorer.cpp @@ -0,0 +1,43 @@ +/* + +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 +*/ + +#include +#include +#include + +int main(){ + + std::cout << "[t-moILSexplorer] => START" << std::endl; + + + std::cout << "[t-moILSexplorer] => OK" << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/oneMax/application/CMakeLists.txt index 8fcb64abd..00093aef8 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/CMakeLists.txt +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/CMakeLists.txt @@ -13,6 +13,7 @@ ADD_EXECUTABLE(testMetropolisHasting testMetropolisHasting.cpp) #ADD_EXECUTABLE(testWithMove testWithMove.cpp) ADD_EXECUTABLE(testSimpleTS testSimpleTS.cpp) ADD_EXECUTABLE(testRandomNeutralWalk testRandomNeutralWalk.cpp) +ADD_EXECUTABLE(testILS testILS.cpp) TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo) TARGET_LINK_LIBRARIES(testFirstImpr eoutils ga eo) @@ -22,6 +23,7 @@ TARGET_LINK_LIBRARIES(testHCneutral eoutils ga eo) TARGET_LINK_LIBRARIES(testMetropolisHasting eoutils ga eo) #TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo) TARGET_LINK_LIBRARIES(testSimpleTS eoutils ga eo) -TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo) +TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo) +TARGET_LINK_LIBRARIES(testILS eoutils ga eo) \ No newline at end of file diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testILS.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testILS.cpp new file mode 100644 index 000000000..bbf6cd2bd --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testILS.cpp @@ -0,0 +1,198 @@ +//----------------------------------------------------------------------------- +/** testILS.cpp + * + * SV - 12/01/10 + * + */ +//----------------------------------------------------------------------------- + +// standard includes +#define HAVE_SSTREAM + +#include // runtime_error +#include // cout +#include // ostrstream, istrstream +#include +#include + +// the general include for eo +#include +#include + +using namespace std; + +//----------------------------------------------------------------------------- +// fitness function +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// REPRESENTATION +//----------------------------------------------------------------------------- +typedef eoBit Indi; +typedef moBitNeighbor Neighbor ; // incremental evaluation +typedef moOrderNeighborhood Neighborhood ; + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + FuncOneMax eval(vecSize); + + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); + + + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ + + moFullEvalByModif fulleval(eval); + + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); + + + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ + + Neighborhood neighborhood(vecSize); + + + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, fulleval, comparator, solComparator); + + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + + moTrueContinuator continuator;//always continue + + moLocalSearch< moSimpleHCexplorer > localSearch(explorer, continuator, eval); + + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ + + Indi solution; + + random(solution); + + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); + + std::cout << "initial: " << solution << std::endl ; + + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; + +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; +}