Compare commits
No commits in common. "master" and "v3.0.0" have entirely different histories.
158 changed files with 685 additions and 2336 deletions
16
.github/workflows/build_ubuntu_debug.yml
vendored
16
.github/workflows/build_ubuntu_debug.yml
vendored
|
|
@ -1,5 +1,10 @@
|
|||
name: Build Debug (Ubuntu)
|
||||
on: [push, pull_request]
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
|
|
@ -16,15 +21,8 @@ jobs:
|
|||
compiler: [g++-10, g++-9, g++-8, g++-7, clang-6, clang-7, clang-8, clang-9, clang-10, clang-11, clang-12]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Caching objects
|
||||
id: cache-objects
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/ccache
|
||||
key: ${{ runner.os }}-${{env.BUILD_TYPE}}-${{ matrix.compiler }}-objects
|
||||
|
||||
- name: Install Dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
|
|
|
|||
33
AUTHORS
33
AUTHORS
|
|
@ -1,52 +1,41 @@
|
|||
Current maintainers
|
||||
===================
|
||||
|
||||
Arnaud Liefooghe <arnaud.liefooghe@univ-lille1.fr>
|
||||
Clive Canape <clive.canape@inria.fr>
|
||||
Johann Dreo <johann@dreo.fr>
|
||||
Sébastien Verel <sebastien.verel@inria.fr>
|
||||
|
||||
Active developpers
|
||||
==================
|
||||
Alexandre Quemy <alexandre.quemy@inria.fr>
|
||||
Benjamin Bouvier <bnjbouv@gmail.com>
|
||||
Caner Candan <caner@candan.fr>
|
||||
Pierre Savéant <pierre.saveant@thalesgroup.com>
|
||||
|
||||
Past contributors
|
||||
=================
|
||||
|
||||
atantar
|
||||
Alesandro Sidero
|
||||
Alexandre Quemy
|
||||
Alix Zheng
|
||||
Amine Aziz-Alaoui
|
||||
Arnaud Liefooghe
|
||||
Benjamin Bouvier
|
||||
Bahri
|
||||
Caner Candan
|
||||
Clive Canape
|
||||
fatene
|
||||
Gustavo Romero Lopez
|
||||
jboisson
|
||||
Jeroen Eggermont
|
||||
Jochen Küpper
|
||||
Joost
|
||||
Joost <joost@dsj.nl>
|
||||
Juan Julian Merelo Guervos
|
||||
Jérémie Humeau
|
||||
Jxtopher
|
||||
Karima Boufaras
|
||||
legillono
|
||||
Leo Bertheas
|
||||
legillon
|
||||
Louis Da Costa
|
||||
Loïc Jean David Arjanen
|
||||
Maarten Keijzer
|
||||
Mammar Amara
|
||||
Manu
|
||||
Marc Schoenauer
|
||||
Marie-Éleonore
|
||||
Mostepha Khouadjia
|
||||
Olivier König
|
||||
Pierre Savéant
|
||||
Pedro Angel Castillo Valdivieso
|
||||
Potalas
|
||||
Ronald Pinho
|
||||
Steve Madere
|
||||
Sébastien Cahon
|
||||
Sébastien Verel
|
||||
Thomas Legrand
|
||||
Thibault Lasnier
|
||||
Victor Manuel Rivas Santos
|
||||
wcancino
|
||||
xohm
|
||||
|
|
|
|||
|
|
@ -13,24 +13,13 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
|||
|
||||
## Name
|
||||
project("ParadisEO"
|
||||
VERSION 3.1.3
|
||||
VERSION 3.0.0
|
||||
DESCRIPTION "Evolutionary optimization framework"
|
||||
LANGUAGES C CXX)
|
||||
|
||||
## Language
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
## ccache
|
||||
find_program(CCACHE_PROGRAM ccache)
|
||||
|
||||
if (CCACHE_PROGRAM)
|
||||
message(NOTICE "-- ccache is enabled (found here: ${CCACHE_PROGRAM})")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "\"${CCACHE_PROGRAM}\"")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "\"${CCACHE_PROGRAM}\"")
|
||||
else ()
|
||||
message(NOTICE "-- ccache has not been found")
|
||||
endif ()
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Check dependencies
|
||||
|
|
@ -93,7 +82,7 @@ set(MPI "false" CACHE BOOL "Build the MPI module")
|
|||
|
||||
## EO Module
|
||||
set(MODULE_NAME "Paradiseo")
|
||||
set(DOXYGEN_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
|
||||
set(DOXYGEN_CONFIG_DIR ${CMAKE_SOURCE_DIR}/doxygen)
|
||||
# set(EO_MODULE_NAME "Evolving Objects")
|
||||
set(CMAKE_SOURCE_DIR ${EO_SRC_DIR})
|
||||
add_subdirectory(${EO_SRC_DIR})
|
||||
|
|
|
|||
12
INSTALL.md
12
INSTALL.md
|
|
@ -2,8 +2,7 @@
|
|||
Summary
|
||||
=======
|
||||
|
||||
As Paradiseo is a development framework, you do not really need to install it on all your systems.
|
||||
Just put it somewhere on your development computer, compile it from here and indicate where to find it to your favorite build system.
|
||||
As Paradiseo is a development framework, you do not really need to install it on all your systems. Just put it somewhere on your development computer, compile it from here and indicate where to find it to your favorite build system.
|
||||
|
||||
|
||||
Build
|
||||
|
|
@ -19,11 +18,6 @@ Paradiseo use the CMake build system, so building it should be as simple as:
|
|||
mkdir build ; cd build ; cmake -DEDO=ON .. && make -j
|
||||
```
|
||||
|
||||
The file `howto_build_paradiseo.apptainer.def` shows you how to install and build from scratch.
|
||||
It is a definition file for the [Apptainer](https://apptainer.org/) container system,
|
||||
which is often used on HPC clusters.
|
||||
|
||||
|
||||
Develop
|
||||
-------
|
||||
|
||||
|
|
@ -193,13 +187,13 @@ Examples and lessons are generated when `ENABLE_CMAKE_EXAMPLE` is set.
|
|||
If you want to build a specific lesson or example, you can check the list of available targets with `make help`.
|
||||
|
||||
All lessons are build on the same pattern: `<module>Lesson<number>`.
|
||||
For instance, make `moLesson4` will build the Lesson 4 from the MO module.
|
||||
For instance, make `moLesson4` will build the Lesson 4 from the MO module.
|
||||
Easy, isn't it ?
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
By performing tests, you can check your installation.
|
||||
By performing tests, you can check your installation.
|
||||
Testing is disable by default, except if you build with the full install type.
|
||||
To enable testing, define `ENABLE_CMAKE_TESTING` when you run cmake.
|
||||
|
||||
|
|
|
|||
35
README.md
35
README.md
|
|
@ -168,7 +168,7 @@ It is, for instance, easy to start with a simple local search, then add multi-ob
|
|||
|
||||
Paradiseo is mainly developed under Linux operating systems, where its dependencies and the C++ toolchain are easy to install. Recent versions have been tested with gcc and clang compilers.
|
||||
|
||||
Stable versions should however work on Windows and any Unix-like operating system with a standard-conforming C++ development system.
|
||||
Stable versions should however work on Windows and any Unix-like operating system with a standard-conforming C++ development system.
|
||||
|
||||
|
||||
# Code
|
||||
|
|
@ -195,7 +195,7 @@ The build chain uses the classical workflow of CMake. The recommended method is
|
|||
|
||||
Under Linux, the default is make, and a build command is straitghtforward: `mkdir build ; cd build ; cmake .. && make -j`.
|
||||
|
||||
There is, however, several build options which you may want to switch. To see them, we recommend the use of a CMake gui, like ccmake or cmake-gui. On the command line, you can see the available options with: `cmake -LH ..` . Those options can be set with the `-D<option>=<value>` argument to cmake.
|
||||
There is, however, several build options which you may want to switch. To see them, we recommend the use of a CMake gui, like ccmake or cmake-gui . On the command line, you can see the available options with: `cmake -LH ..` . Those options can be set with the `-D<option>=<value>` argument to cmake.
|
||||
|
||||
**The first option to consider is `CMAKE_BUILD_TYPE`, which you most probably want to set to `Debug` (during development/tests) or `Release` (for production/validation).**
|
||||
|
||||
|
|
@ -211,9 +211,6 @@ If you `ENABLE_CMAKE_EXAMPLE`, it will also build the examples.
|
|||
If may want to make build scripts more verbose (especially when building the
|
||||
doc) by enabling `CMAKE_VERBOSE_MAKEFILE`.
|
||||
|
||||
If `ccache` installed in your environment, it will try its best to re-use other compilations,
|
||||
which may speed-up your builds if you manage several compatible builds at the same time.
|
||||
To clear all cached objects, execute `ccache -C`.
|
||||
|
||||
## Licenses
|
||||
|
||||
|
|
@ -239,35 +236,11 @@ For academic articles, books, more tutorials, presentations slides,
|
|||
real life example of solvers and contact information,
|
||||
please see the web site (available in `paradiseo/website/index.html`).
|
||||
|
||||
There is also an [online wiki](https://gitlab.inria.fr/paradiseo/paradiseo/-/wikis/home)
|
||||
|
||||
# Citing Paradiseo
|
||||
|
||||
If you use Paradiseo, please cite the following publication:
|
||||
|
||||
Johann Dreo, Arnaud Liefooghe, Sébastien Verel, Marc Schoenauer, Juan J. Merelo, Alexandre Quemy, Benjamin Bouvier, and Jan Gmys, [Paradiseo: from a modular framework for evolutionary computation to the automated design of metaheuristics —22 years of Paradiseo—](https://doi.org/10.1145/3449726.3463276), GECCO'21: Proceedings of the Genetic and Evolutionary Computation Conference Companion, 1522–1530 (2021).
|
||||
|
||||
BiBTeX entry:
|
||||
|
||||
```
|
||||
@inproceedings{Dreo-al_2021_Paradiseo,
|
||||
author = {Dreo, Johann and Liefooghe, Arnaud and Verel, S\'{e}bastien and Schoenauer, Marc and Merelo, Juan J. and Quemy, Alexandre and Bouvier, Benjamin and Gmys, Jan},
|
||||
title = {Paradiseo: From a Modular Framework for Evolutionary Computation to the Automated Design of Metaheuristics: 22 Years of Paradiseo},
|
||||
year = {2021},
|
||||
isbn = {9781450383516},
|
||||
publisher = {Association for Computing Machinery},
|
||||
address = {Online conference},
|
||||
url = {https://doi.org/10.1145/3449726.3463276},
|
||||
booktitle = {Proceedings of the Genetic and Evolutionary Computation Conference Companion},
|
||||
pages = {1522–1530},
|
||||
numpages = {9}
|
||||
}
|
||||
```
|
||||
|
||||
# Contact
|
||||
|
||||
For further information about ParadisEO, help or to report any
|
||||
problem, you can either:
|
||||
|
||||
- Chat with us on our Matrix chatroom: https://app.element.io/#/room/#paradiseo:matrix.org
|
||||
- Post an issue: https://github.com/nojhan/paradiseo/issues
|
||||
problem, you can send an e-mail to: `paradiseo-help@lists.gforge.inria.fr`
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
# set(DOC_SMP "")
|
||||
# endif()
|
||||
# if(MPI)
|
||||
# set(DOC_MPI "make doc-mpi")
|
||||
# set(DOC_MPI "make doc-mpi")
|
||||
# else()
|
||||
# set(DOC_MPI "")
|
||||
# endif()
|
||||
|
|
@ -78,7 +78,7 @@ if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
COMMAND make doc-eo
|
||||
COMMAND make doc-mo
|
||||
COMMAND make doc-moeo
|
||||
# COMMAND make doc-mpi
|
||||
COMMAND make doc-mpi
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
COMMAND make doc-mo
|
||||
COMMAND make doc-moeo
|
||||
COMMAND make doc-smp
|
||||
# COMMAND make doc-mpi
|
||||
COMMAND make doc-mpi
|
||||
)
|
||||
endif()
|
||||
if(EDO AND NOT SMP AND MPI)
|
||||
|
|
@ -98,7 +98,7 @@ if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
COMMAND make doc-mo
|
||||
COMMAND make doc-moeo
|
||||
COMMAND make doc-edo
|
||||
# COMMAND make doc-mpi
|
||||
COMMAND make doc-mpi
|
||||
)
|
||||
endif()
|
||||
if(EDO AND SMP AND NOT MPI)
|
||||
|
|
@ -119,7 +119,7 @@ if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
COMMAND make doc-moeo
|
||||
COMMAND make doc-edo
|
||||
COMMAND make doc-smp
|
||||
# COMMAND make doc-mpi
|
||||
COMMAND make doc-mpi
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ endif(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
|
|||
######################################################################################
|
||||
|
||||
if(PROFILING)
|
||||
find_program(LCOV
|
||||
find_program(LCOV
|
||||
NAMES lcov
|
||||
PATHS
|
||||
"/usr/local/bin /usr/bin [HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder] [HKEY_CURRENT_USER\\Software]"
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@
|
|||
|
||||
<div id="Why_efficiency">
|
||||
<h3>Efficient</h3>
|
||||
<p class="excerpt"><em class="logo">Paradis<span class="logo_eo">eo</span></em> is <em>the fastest</em> framework on the market, which is a crucial feature for modern and robust approach to solver <em>design and validation</em> (especially on combinatorial problems).</p>
|
||||
<p class="excerpt"><em class="logo">Paradis<span class="logo_eo">eo</span></em> is <em>the fastest</em> framework on the market, which is a crucial feature for modern and robust approach to solver <em>design and validation</em>.</p>
|
||||
</div>
|
||||
|
||||
<div id="Why_efficiency_details">
|
||||
|
|
@ -311,7 +311,6 @@
|
|||
<p>Another classical criticism against <em class="logo">Paradis<span class="logo_eo">eo</span></em> is that C++ is hard and that a fast language is useless because speed is not a concern when your objective function is dominating all the runtime.</p>
|
||||
<p>However, we argue that:
|
||||
<ul>
|
||||
<li>The numerical optimization community often sees objective functions as monolithic “black-box”, but in combinatorial opimization, it is very often the case that the objective function can be only partially evaluated on neighbor solutions, which allows for (tremendous) speed gains. The Paradiseo-mo module is architectured around that idea, a feature that is not so often found in other frameworks.</li>
|
||||
<li>During the design phase of your solver, you will need to estimate its performance against synthetic benchmarks that are fast to compute. In that case, fast computation means fast design iterations. And it's even more true if you plan to use automated design to find the best solver for your problem.</li>
|
||||
<li>Modern C++ makes use of the very same high-level abstractions you would find in more accepted languages like Python. Sure, the syntax is cumbersome, but you will not see it after a while, given that you will work at the algorithm level.</li>
|
||||
<li>C++ provides full type checking and the largest set of tooling for any modern language, which are your first line of defense against long-term bugs. Sure, it sometimes gives you the impression that you fight against the compiler, but chasing subtle interface bugs across a complex Python code is even harder.</li>
|
||||
|
|
@ -828,7 +827,7 @@
|
|||
<font color="#da4939"><b>year</b></font> = {2021},<br>
|
||||
<font color="#da4939"><b>isbn</b></font> = {9781450383516},<br>
|
||||
<font color="#da4939"><b>publisher</b></font> = {Association for Computing Machinery},<br>
|
||||
<font color="#da4939"><b>address</b></font> = {Online conference},<br>
|
||||
<font color="#da4939"><b>address</b></font> = {New York, NY, USA},<br>
|
||||
<font color="#da4939"><b>url</b></font> = {<a href="https://doi.org/10.1145/3449726.3463276},">https://doi.org/10.1145/3449726.3463276},</a><br>
|
||||
<font color="#da4939"><b>booktitle</b></font> = {Proceedings of the Genetic and Evolutionary Computation Conference Companion},<br>
|
||||
<font color="#da4939"><b>pages</b></font> = {1522–1530},<br>
|
||||
|
|
@ -927,31 +926,10 @@ ISBN: 978-0-470-27858-1</blockquote>
|
|||
<ul class="publications">
|
||||
</ul>
|
||||
|
||||
<h3>Accelerator Physics</h3>
|
||||
<ul>
|
||||
<li>E. Valetov, G. Dal Maso, P-R. Kettle, A. Knecht, A. Papa, on behalf of the HIMB Project. <a href="https://doi.org/10.3390/particles7030039">Beamline Optimisation for High-Intensity Muon Beams at PSI Using the Heterogeneous Island Model</a>. <i>Particles</i> (2024), <i>7</i>, 683-691.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Bioinformatics</h3>
|
||||
<ul>
|
||||
<li> Emile Zakiev, Johann Dreo, Mara Santarelli, Benno Schwikowski, <a href="https://hal.science/hal-04110700">Statistical Discovery of Transcriptomic Cancer Signatures using Multimodal Local Search</a>, <i>PGMO Days</i> (2022).</li>
|
||||
</ul>
|
||||
|
||||
<h3>Metaheuristics Design</h3>
|
||||
<ul>
|
||||
<li>Johann Dreo, Carola Doerr, Amine Aziz-Alaoui, Alix Zheng, <a href="https://hal.science/hal-04110704/document">Using irace, paradiseo and iohprofiler for large-scale algorithm configuration</a>, <i>8th COnfiguration and SElection of ALgorithms (COSEAL) workshop</i> (2021).</li>
|
||||
<li>Amine Aziz-Alaoui, Carola Doerr, Johann Dreo, <a href="https://arxiv.org/abs/2102.06435">Towards large scale automated algorithm design by integrating modular benchmarking frameworks</a>, <i>Proceedings of the Genetic and Evolutionary Computation Conference Companion</i> (2021).</li>
|
||||
<li>Johann Dréo, Carola Doerr, Yann Semet, <a href="https://hal.sorbonne-universite.fr/hal-02179604/document">Coupling the design of benchmark with algorithm in landscape-aware solver design</a>, <i>Proceedings of the Genetic and Evolutionary Computation Conference Companion</i> (2019).</li>
|
||||
<li>Johann Dreo, <a href="https://dl.acm.org/doi/10.1145/1570256.1570301">Using Performance Fronts for Parameter Setting of Stochastic Metaheuristics</a>, <i>Genetic and Evolutionary Computation Conference</i>, (2009).</li>
|
||||
</ul>
|
||||
|
||||
<h3>Automated Planning</h3>
|
||||
<ul>
|
||||
<li>Mostepha Redouane Khouadjia, Marc Schoenauer, Vincent Vidal, Johann Dreo, Pierre Savéant, <a href="https://arxiv.org/abs/1305.2265v1">Quality measures of parameter tuning for aggregated multi-objective temporal planning</a>, <i>7th International Conference on Learning and Intelligent Optimization (LION 7)</i> (2013).</li>
|
||||
<li>Mostepha Redouane Khouadjia, Marc Schoenauer, Vincent Vidal, Johann Dreo, Pierre Savéant, <a href="https://arxiv.org/abs/1305.1169v1">Multi-Objective AI Planning: Comparing Aggregation and Pareto Approaches</a>, <i>Conference on Evolutionary Computation in Combinatorial Optimization (EvoCOP)</i> (2013).</li>
|
||||
<li>Mostepha Redouane Khouadjia, Marc Schoenauer, Vincent Vidal, Johann Dreo, Pierre Savéant, <a href="https://arxiv.org/abs/1212.5276">Multi-Objective AI Planning: Evaluating DAE-YAHSP on a Tunable Benchmark</a>, <i>7th International Conference on Evolutionary Multi-Criterion Optimization</i> (2013).</li>
|
||||
<li>Jacques Bibaï, Pierre Savéant, Marc Schoenauer, Vincent Vidal, <a href="http://www.aaai.org/ocs/index.php/ICAPS/ICAPS10/paper/view/1414">An Evolutionary Metaheuristic Based on State Decomposition for Domain-Independent Satisficing Planning</a>, <i>Twentieth International Conference on Automated Planning and Scheduling </i> (2010). <strong>Winner of the International Planning Competition</strong></li>
|
||||
<li>Jacques Bibaï, Pierre Savéant, Marc Schoenauer, Vincent Vidal, <a href="">An Evolutionary Metaheuristic for Domain-Independent Satisficing Planning</a>, <i>Genetic and Evolutionary Computation Conference</i> (2010). <strong>Silver Medal at the Human-Competitive Competition</strong></li>
|
||||
<li>Jacques Bibaï, Pierre Savéant, Marc Schoenauer, Vincent Vidal, <a href="">An Evolutionary Metaheuristic for Domain-Independent Satisficing Planning</a>, <i>Genetic and Evolutionary Computation Conference</i> (2010). <strong>Silver Medal at the Human-Competitive Competition</strong></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
|
@ -1015,6 +993,11 @@ undiscovered knowledge.
|
|||
physics/0603108 (2006)</a>.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Metaheuristics Design</h3>
|
||||
<ul>
|
||||
<li>Johann Dreo, <a href="https://dl.acm.org/doi/10.1145/1570256.1570301">Using Performance Fronts for Parameter Setting of Stochastic Metaheuristics</a>, <i>Genetic and Evolutionary Computation Conference</i>, (2009).</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -1169,7 +1152,7 @@ undiscovered knowledge.
|
|||
<div id="Downloads">
|
||||
<h2><a name="Downloads"></a>Downloads</h2>
|
||||
|
||||
<p>The current stable release is version: <a href="https://github.com/nojhan/paradiseo/releases">Paradiseo 3.1.3</a>. Some other releases (older or newer) can be found on <a href="https://github.com/nojhan/paradiseo/tags">GitHub/paradiseo/releases</a>.</p>
|
||||
<p>The current stable release is version: <a href="https://github.com/nojhan/paradiseo/releases">Paradiseo 3.0.0-beta</a>. Some other releases (older or newer) can be found on <a href="https://github.com/nojhan/paradiseo/tags">GitHub/paradiseo/releases</a>.</p>
|
||||
|
||||
<p> You can obtain the latest stable and beta version directly via the Git repository:
|
||||
<code class="command">git clone https://github.com/jdreo/paradiseo.git</code>.
|
||||
|
|
@ -1221,7 +1204,7 @@ undiscovered knowledge.
|
|||
</p>
|
||||
|
||||
<p>There is, however, several build options which you may want to switch.
|
||||
To see them, we recommend the use of a CMake gui, like <code>ccmake</code> (available through the <code>cmake-curses-gui</code> package in Debian/Ubuntu) or <a href="https://cmake.org/cmake/help/latest/guide/user-interaction/index.html#cmake-gui-tool">cmake-gui</a>.
|
||||
To see them, we recommend the use of a CMake gui, like <code>ccmake</code> or <code>cmake-gui</code>.
|
||||
On the command line, you can see the available options with: <code class="command">cmake -LH ..</code>.
|
||||
Those options can be set with the <code>-D<option>=<value></code> argument to cmake.
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class edoEstimatorAdaptive : public edoEstimator<D>
|
|||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoEstimatorAdaptive( D& distrib ) : _distrib(distrib) {}
|
||||
edoEstimatorAdaptive<D>( D& distrib ) : _distrib(distrib) {}
|
||||
|
||||
// virtual D operator() ( eoPop< EOT >& )=0 (provided by eoUF< A1, R >)
|
||||
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ class edoEstimatorAdaptiveReset : public edoEstimatorAdaptive<D>
|
|||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoEstimatorAdaptiveReset( D& distrib ) :
|
||||
edoEstimatorAdaptiveReset<D>( D& distrib ) :
|
||||
edoEstimatorAdaptive<D>(distrib),
|
||||
_dim(0)
|
||||
{ }
|
||||
|
||||
edoEstimatorAdaptiveReset( D& distrib, size_t dim ) :
|
||||
edoEstimatorAdaptiveReset<D>( D& distrib, size_t dim ) :
|
||||
edoEstimatorAdaptive<D>(distrib),
|
||||
_dim(dim)
|
||||
{ }
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ class edoEstimatorCombinedAdaptive : public edoEstimatorAdaptive<D>, public std:
|
|||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoEstimatorCombinedAdaptive( D& distrib, edoEstimator<D>& estim) :
|
||||
edoEstimatorCombinedAdaptive<D>( D& distrib, edoEstimator<D>& estim) :
|
||||
edoEstimatorAdaptive<D>(distrib),
|
||||
std::vector<edoEstimator<D>*>(1,&estim)
|
||||
{}
|
||||
|
||||
edoEstimatorCombinedAdaptive( D& distrib, std::vector<edoEstimator<D>*> estims) :
|
||||
edoEstimatorCombinedAdaptive<D>( D& distrib, std::vector<edoEstimator<D>*> estims) :
|
||||
edoEstimatorAdaptive<D>(distrib),
|
||||
std::vector<edoEstimator<D>*>(estims)
|
||||
{}
|
||||
|
|
@ -78,11 +78,11 @@ class edoEstimatorCombinedStateless : public edoEstimatorCombinedAdaptive<D>
|
|||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoEstimatorCombinedStateless( edoEstimator<D>& estim ) :
|
||||
edoEstimatorCombinedStateless<D>( edoEstimator<D>& estim ) :
|
||||
edoEstimatorCombinedAdaptive<D>(*(new D), estim)
|
||||
{}
|
||||
|
||||
edoEstimatorCombinedStateless( std::vector<edoEstimator<D>*> estims) :
|
||||
edoEstimatorCombinedStateless<D>( std::vector<edoEstimator<D>*> estims) :
|
||||
edoEstimatorCombinedAdaptive<D>(*(new D), estims)
|
||||
{}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ template < typename EOT >
|
|||
class edoRepairerModulo: public edoRepairerApplyBinary<EOT>
|
||||
{
|
||||
public:
|
||||
edoRepairerModulo( double denominator ) : edoRepairerApplyBinary<EOT>( std::fmod, denominator ) {}
|
||||
edoRepairerModulo<EOT>( double denominator ) : edoRepairerApplyBinary<EOT>( std::fmod, denominator ) {}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ edoFileSnapshot::edoFileSnapshot(std::string dirname,
|
|||
s = " ";
|
||||
}
|
||||
|
||||
(void)/*ignore returned*/ system(s.c_str());
|
||||
int dummy;
|
||||
dummy = system(s.c_str());
|
||||
// all done
|
||||
|
||||
_descOfFiles = new std::ofstream( std::string(dirname + "/list_of_files.txt").c_str() );
|
||||
|
|
|
|||
|
|
@ -108,12 +108,7 @@ public:
|
|||
if (is) {
|
||||
virus.resize(bits.size());
|
||||
std::transform(bits.begin(), bits.end(), virus.begin(),
|
||||
#if __cplusplus >= 201103L
|
||||
std::bind(std::equal_to<char>(), std::placeholders::_1, '1'));
|
||||
#else
|
||||
// Deprecated since C++11.
|
||||
std::bind2nd(std::equal_to<char>(), '1'));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
27
eo/src/EO.h
27
eo/src/EO.h
|
|
@ -64,8 +64,6 @@ template<class F = double> class EO: public eoObject, public eoPersistent
|
|||
public:
|
||||
typedef F Fitness;
|
||||
|
||||
static constexpr const char* invalidTag = "INVALID";
|
||||
|
||||
/** Default constructor.
|
||||
*/
|
||||
EO(): repFitness(Fitness()), invalidFitness(true) { }
|
||||
|
|
@ -126,21 +124,25 @@ public:
|
|||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw eoInvalidFitnessError If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is)
|
||||
{
|
||||
virtual void readFrom(std::istream& _is) {
|
||||
|
||||
// the new version of the reafFrom function.
|
||||
// It can distinguish between valid and invalid fitness values.
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
|
||||
if (fitness_str == invalidTag)
|
||||
if (fitness_str == "INVALID")
|
||||
{
|
||||
invalidFitness = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
invalidFitness = false;
|
||||
std::istringstream iss(fitness_str);
|
||||
iss >> repFitness;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFitness;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,11 +150,12 @@ public:
|
|||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const
|
||||
{
|
||||
if (invalid())
|
||||
{
|
||||
_os << invalidTag << ' ';
|
||||
virtual void printOn(std::ostream& _os) const {
|
||||
|
||||
|
||||
// the latest version of the code. Very similar to the old code
|
||||
if (invalid()) {
|
||||
_os << "INVALID ";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
|
|||
|
||||
#ifndef _MSC_VER
|
||||
// the CtrlC monitoring interception
|
||||
eoSignal<EOT> *mon_ctrlCCont = nullptr;
|
||||
eoSignal<EOT> *mon_ctrlCCont;
|
||||
eoValueParam<bool>& mon_ctrlCParam = _parser.createParam(false, "monitor-with-CtrlC", "Monitor current generation upon Ctrl C",0, "Stopping criterion");
|
||||
if (mon_ctrlCParam.value())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -224,11 +224,6 @@
|
|||
#include "utils/eoLogger.h"
|
||||
#include "utils/eoParallel.h"
|
||||
|
||||
#include "eoInt.h"
|
||||
#include "eoRealToIntMonOp.h"
|
||||
#include "eoRealToIntQuadOp.h"
|
||||
#include "eoRealToIntInit.h"
|
||||
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
|||
|
|
@ -174,18 +174,18 @@ protected:
|
|||
// if the flight does not need to be used, use the dummy flight instance
|
||||
class eoDummyFlight:public eoFlight < POT >
|
||||
{
|
||||
public:
|
||||
eoDummyFlight () {}
|
||||
void operator() (POT &) override {}
|
||||
} dummyFlight;
|
||||
public:
|
||||
eoDummyFlight () {}
|
||||
void operator () (POT &) {}
|
||||
}dummyFlight;
|
||||
|
||||
// if the initializer does not need to be used, use the dummy one instead
|
||||
class eoDummyInitializer:public eoInitializerBase < POT >
|
||||
{
|
||||
public:
|
||||
eoDummyInitializer () {}
|
||||
void operator() () override {}
|
||||
} dummyInit;
|
||||
public:
|
||||
eoDummyInitializer () {}
|
||||
void operator () (POT &) {}
|
||||
}dummyInit;
|
||||
|
||||
};
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -71,6 +71,13 @@ public:
|
|||
i_repl(foundry.replacements.index())
|
||||
{ }
|
||||
|
||||
protected:
|
||||
const size_t i_cont;
|
||||
const size_t i_cros;
|
||||
const size_t i_muta;
|
||||
const size_t i_sele;
|
||||
const size_t i_repl;
|
||||
|
||||
public:
|
||||
|
||||
/** Decode the high-level problem encoding as an array of indices.
|
||||
|
|
@ -149,13 +156,6 @@ protected:
|
|||
eoAlgoFoundryEA<SUB>& _foundry;
|
||||
const typename EOT::Fitness _penalization;
|
||||
const size_t _pop_size;
|
||||
|
||||
const size_t i_cont;
|
||||
const size_t i_cros;
|
||||
const size_t i_muta;
|
||||
const size_t i_sele;
|
||||
const size_t i_repl;
|
||||
|
||||
};
|
||||
|
||||
/** Helper function to instanciate an eoEvalFoundryEA without having to indicate the template for the sub-problem encoding.
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ Authors:
|
|||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#if !defined(_POSIX_VERSION) && !defined(__unix__) && !defined(_WINDOWS)
|
||||
#if !defined(__unix__) && !defined(_WINDOWS)
|
||||
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX (defining 'rusage' in 'sys/resource.h') or Win32 (defining 'GetProcessTimes' in 'WinBase.h') systems, contributions for other systems are welcomed."
|
||||
#else // defined(_POSIX_VERSION) || defined(__unix__) || defined(_WINDOWS)
|
||||
#else //!defined(__unix__) && !defined(_WINDOWS)
|
||||
|
||||
#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
#define __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
|
|
@ -40,7 +40,7 @@ Johann Dréo <johann.dreo@thalesgroup.com>
|
|||
|
||||
#include "eoExceptions.h"
|
||||
|
||||
#if defined(_POSIX_VERSION) || defined(__unix__)
|
||||
#ifdef __unix__
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
|
@ -106,6 +106,6 @@ protected:
|
|||
};
|
||||
|
||||
#endif // _WINDOWS
|
||||
#endif // defined(_POSIX_VERSION) || defined(__unix__)
|
||||
#endif //__unix__
|
||||
#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
#endif //!defined(_POSIX_VERSION) && !defined(__unix__) && !defined(_WINDOWS)
|
||||
#endif //!defined(__unix__) && !defined(_WINDOWS)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public:
|
|||
|
||||
const char* what() const throw()
|
||||
{
|
||||
return _msg.c_str();
|
||||
return message().c_str();
|
||||
}
|
||||
|
||||
~eoException() throw() {}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <string>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
// In case you want to debug arguments captured in tuples:
|
||||
// template<typename Type, unsigned N, unsigned Last>
|
||||
|
|
@ -75,7 +74,6 @@ class eoForgeInterface
|
|||
{
|
||||
public:
|
||||
virtual Itf& instantiate(bool no_cache = true) = 0;
|
||||
virtual std::shared_ptr<Itf> instantiate_ptr(bool no_cache = true) = 0;
|
||||
virtual ~eoForgeInterface() {}
|
||||
};
|
||||
|
||||
|
|
@ -114,7 +112,6 @@ class eoForgeOperator : public eoForgeInterface<Itf>
|
|||
template<class ...Args2>
|
||||
eoForgeOperator(Args2... args) :
|
||||
_args(std::forward<Args2>(args)...),
|
||||
_instantiated_ptr(nullptr),
|
||||
_instantiated(nullptr)
|
||||
{ }
|
||||
|
||||
|
|
@ -126,9 +123,9 @@ class eoForgeOperator : public eoForgeInterface<Itf>
|
|||
*
|
||||
* @param no_cache If false, will enable caching previous instances.
|
||||
*/
|
||||
Itf& instantiate(bool no_cache = true) override
|
||||
Itf& instantiate(bool no_cache = true)
|
||||
{
|
||||
if(no_cache or _instantiated == nullptr) {
|
||||
if(no_cache or not _instantiated) {
|
||||
if(_instantiated) {
|
||||
delete _instantiated;
|
||||
}
|
||||
|
|
@ -137,19 +134,7 @@ class eoForgeOperator : public eoForgeInterface<Itf>
|
|||
return *_instantiated;
|
||||
}
|
||||
|
||||
std::shared_ptr<Itf> instantiate_ptr(bool no_cache = true) override
|
||||
{
|
||||
if(no_cache or _instantiated == nullptr) {
|
||||
// if(_instantiated) {
|
||||
// delete _instantiated;
|
||||
// }
|
||||
_instantiated_ptr = op_constructor_ptr(_args);
|
||||
// _instantiated = op_constructor(_args);
|
||||
}
|
||||
return _instantiated_ptr;
|
||||
}
|
||||
|
||||
virtual ~eoForgeOperator() override
|
||||
virtual ~eoForgeOperator()
|
||||
{
|
||||
delete _instantiated;
|
||||
}
|
||||
|
|
@ -165,16 +150,9 @@ class eoForgeOperator : public eoForgeInterface<Itf>
|
|||
// FIXME double-check that the copy-constructor is a good idea to make_from_tuple with dynamic storage duration.
|
||||
return new Op(std::make_from_tuple<Op>(args));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<Op> op_constructor_ptr(T& args)
|
||||
{
|
||||
return std::make_shared<Op>( std::make_from_tuple<Op>(args) );
|
||||
}
|
||||
/** @} */
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Itf> _instantiated_ptr;
|
||||
Itf* _instantiated;
|
||||
};
|
||||
|
||||
|
|
@ -185,13 +163,12 @@ class eoForgeOperator<Itf,Op> : public eoForgeInterface<Itf>
|
|||
{
|
||||
public:
|
||||
eoForgeOperator() :
|
||||
_instantiated_ptr(nullptr),
|
||||
_instantiated(nullptr)
|
||||
{ }
|
||||
|
||||
Itf& instantiate( bool no_cache = true ) override
|
||||
Itf& instantiate( bool no_cache = true )
|
||||
{
|
||||
if(no_cache or _instantiated == nullptr) {
|
||||
if(no_cache or not _instantiated) {
|
||||
if(_instantiated) {
|
||||
delete _instantiated;
|
||||
}
|
||||
|
|
@ -200,21 +177,12 @@ class eoForgeOperator<Itf,Op> : public eoForgeInterface<Itf>
|
|||
return *_instantiated;
|
||||
}
|
||||
|
||||
std::shared_ptr<Itf> instantiate_ptr( bool no_cache = true ) override
|
||||
{
|
||||
if(no_cache or _instantiated == nullptr) {
|
||||
_instantiated_ptr = std::shared_ptr<Op>();
|
||||
}
|
||||
return _instantiated_ptr;
|
||||
}
|
||||
|
||||
virtual ~eoForgeOperator() override
|
||||
virtual ~eoForgeOperator()
|
||||
{
|
||||
delete _instantiated;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Itf> _instantiated_ptr;
|
||||
Itf* _instantiated;
|
||||
};
|
||||
|
||||
|
|
@ -273,7 +241,7 @@ class eoForgeVector : public std::vector<eoForgeInterface<Itf>*>
|
|||
|
||||
/** instantiate the operator managed at the given index.
|
||||
*/
|
||||
Itf& instantiate_from(double index)
|
||||
Itf& instantiate(double index)
|
||||
{
|
||||
double frac_part, int_part;
|
||||
frac_part = std::modf(index, &int_part);
|
||||
|
|
@ -281,33 +249,9 @@ class eoForgeVector : public std::vector<eoForgeInterface<Itf>*>
|
|||
eo::log << eo::errors << "there is a fractional part in the given index (" << index << ")" << std::endl;
|
||||
assert(frac_part != 0);
|
||||
}
|
||||
return instantiate(index);
|
||||
}
|
||||
|
||||
std::shared_ptr<Itf> instantiate_ptr_from(double index)
|
||||
{
|
||||
double frac_part, int_part;
|
||||
frac_part = std::modf(index, &int_part);
|
||||
if(frac_part != 0) {
|
||||
eo::log << eo::errors << "there is a fractional part in the given index (" << index << ")" << std::endl;
|
||||
assert(frac_part != 0);
|
||||
}
|
||||
return instantiate_ptr(index);
|
||||
}
|
||||
|
||||
/** instantiate the operator managed at the given index.
|
||||
*/
|
||||
Itf& instantiate(size_t index)
|
||||
{
|
||||
return this->at(static_cast<size_t>(index))->instantiate(_no_cache);
|
||||
}
|
||||
|
||||
std::shared_ptr<Itf> instantiate_ptr(size_t index)
|
||||
{
|
||||
return this->at(static_cast<size_t>(index))->instantiate_ptr(_no_cache);
|
||||
}
|
||||
|
||||
|
||||
/** Add an operator to the list.
|
||||
*
|
||||
* @warning When passing a reference (as it is often the case within ParadisEO),
|
||||
|
|
|
|||
|
|
@ -114,12 +114,7 @@ eoFunctorBase::procedure_tag functor_category(const eoF<R>&)
|
|||
result_type
|
||||
**/
|
||||
template <class A1, class R>
|
||||
#if __cplusplus >= 201103L
|
||||
class eoUF : public eoFunctorBase, public std::function<R(A1)>
|
||||
#else
|
||||
// Deprecated in C++11
|
||||
class eoUF : public eoFunctorBase, public std::unary_function<A1, R>
|
||||
#endif
|
||||
{
|
||||
public :
|
||||
|
||||
|
|
@ -156,12 +151,7 @@ eoFunctorBase::unary_function_tag functor_category(const eoUF<A1, R>&)
|
|||
result_type
|
||||
**/
|
||||
template <class A1, class A2, class R>
|
||||
#if __cplusplus >= 201103L
|
||||
class eoBF : public eoFunctorBase, public std::function<R(A1, A2)>
|
||||
#else
|
||||
// Deprecated in C++11
|
||||
class eoBF : public eoFunctorBase, public std::binary_function<A1, A2, R>
|
||||
#endif
|
||||
{
|
||||
public :
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
|
|
|
|||
|
|
@ -29,12 +29,11 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <random>
|
||||
|
||||
#include "eoOp.h"
|
||||
#include "eoSTLFunctor.h"
|
||||
#include "utils/eoRndGenerators.h"
|
||||
// #include "utils/rnd_generators.h" // for shuffle method
|
||||
#include "utils/rnd_generators.h" // for shuffle method
|
||||
#include "eoExceptions.h"
|
||||
|
||||
|
||||
|
|
@ -198,8 +197,7 @@ class eoInitPermutation: public eoInit<EOT> // FIXME inherit from eoInitWithDim
|
|||
chrom[idx] = idx+startFrom;
|
||||
}
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
UF_random_generator<unsigned int> gen(chrom.size());
|
||||
std::shuffle(chrom.begin(), chrom.end(), gen);
|
||||
chrom.invalidate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,12 +36,9 @@
|
|||
*
|
||||
* @ingroup Representations
|
||||
*/
|
||||
template <class FitT, class T = size_t>
|
||||
class eoInt: public eoVector<FitT, T>
|
||||
template <class FitT, class T = size_t> class eoInt: public eoVector<FitT, T>
|
||||
{
|
||||
public:
|
||||
using AtomType = size_t;
|
||||
using FitnessType = FitT;
|
||||
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ public:
|
|||
|
||||
// replace if necessary
|
||||
for(i = 0; i < i1; i++) {
|
||||
while (p1[ _solution1[i] ] != -1) // FIXME as an unsigned int, p1 cannot hold negative values!
|
||||
while (p1[ _solution1[i] ] != -1)
|
||||
_solution1[i] = p1[_solution1[i]];
|
||||
while (p2[ _solution2[i] ] != -1) // FIXME as an unsigned int, p2 cannot hold negative values!
|
||||
while (p2[ _solution2[i] ] != -1)
|
||||
_solution2[i] = p2[_solution2[i]];
|
||||
}
|
||||
|
||||
|
|
@ -96,9 +96,9 @@ public:
|
|||
|
||||
// replace if necessary
|
||||
for(i = i2 + 1; i < _solution1.size(); i++) {
|
||||
while (p1[ _solution1[i] ] != -1) // FIXME as an unsigned int, p1 cannot hold negative values!
|
||||
while (p1[ _solution1[i] ] != -1)
|
||||
_solution1[i] = p1[_solution1[i]];
|
||||
while (p2[ _solution2[i] ] != -1) // FIXME as an unsigned int, p2 cannot hold negative values!
|
||||
while (p2[ _solution2[i] ] != -1)
|
||||
_solution2[i] = p2[_solution2[i]];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ Authors:
|
|||
#include "eoOp.h" // for eoInit
|
||||
#include "eoPersistent.h"
|
||||
#include "eoInit.h"
|
||||
// #include "utils/rnd_generators.h" // for shuffle method
|
||||
#include "utils/rnd_generators.h" // for shuffle method
|
||||
#include "eoExceptions.h"
|
||||
|
||||
/** A std::vector of EO object, to be used in all algorithms
|
||||
|
|
|
|||
|
|
@ -68,12 +68,16 @@ public:
|
|||
}
|
||||
assert(not _pop[0].invalid());
|
||||
|
||||
const typename EOT::Fitness min_fit
|
||||
= std::min_element( std::begin(_pop), std::end(_pop) )
|
||||
->fitness();
|
||||
|
||||
cumulative.clear();
|
||||
cumulative.push_back(_pop[0].fitness() );
|
||||
cumulative.push_back(_pop[0].fitness() - min_fit);
|
||||
|
||||
for (unsigned i = 1; i < _pop.size(); ++i) {
|
||||
assert(not _pop[i].invalid());
|
||||
cumulative.push_back(cumulative.back() + _pop[i].fitness());
|
||||
cumulative.push_back(cumulative.back() + _pop[i].fitness() - min_fit);
|
||||
}
|
||||
assert(cumulative.size() == _pop.size());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,73 +40,73 @@ template <class EOT>
|
|||
class eoRanking : public eoPerf2Worth<EOT> // false: do not cache fitness
|
||||
{
|
||||
public:
|
||||
|
||||
using eoPerf2Worth<EOT>::value;
|
||||
|
||||
/* Ctor:
|
||||
@param _p selective pressure (in (1,2]
|
||||
@param _e exponent (1 == linear)
|
||||
*/
|
||||
eoRanking(double _p = 2.0, double _e = 1.0) : pressure(_p), exponent(_e)
|
||||
{
|
||||
assert(1 < pressure and pressure <= 2);
|
||||
}
|
||||
/* Ctor:
|
||||
@param _p selective pressure (in (1,2]
|
||||
@param _e exponent (1 == linear)
|
||||
*/
|
||||
eoRanking(double _p=2.0, double _e=1.0):
|
||||
pressure(_p), exponent(_e) {}
|
||||
|
||||
/* helper function: finds index in _pop of _eo, an EOT * */
|
||||
int lookfor(const EOT *_eo, const eoPop<EOT> &_pop)
|
||||
/* helper function: finds index in _pop of _eo, an EOT * */
|
||||
int lookfor(const EOT *_eo, const eoPop<EOT>& _pop)
|
||||
{
|
||||
typename eoPop<EOT>::const_iterator it;
|
||||
for (it = _pop.begin(); it < _pop.end(); it++)
|
||||
typename eoPop<EOT>::const_iterator it;
|
||||
for (it=_pop.begin(); it<_pop.end(); it++)
|
||||
{
|
||||
if (_eo == &(*it))
|
||||
return it - _pop.begin();
|
||||
if (_eo == &(*it))
|
||||
return it-_pop.begin();
|
||||
}
|
||||
throw eoException("Not found in eoLinearRanking");
|
||||
throw eoException("Not found in eoLinearRanking");
|
||||
}
|
||||
|
||||
/* COmputes the ranked fitness: fitnesses range in [m,M]
|
||||
with m=2-pressure/popSize and M=pressure/popSize.
|
||||
in between, the progression depstd::ends on exponent (linear if 1).
|
||||
*/
|
||||
virtual void operator()(const eoPop<EOT> &_pop)
|
||||
/* COmputes the ranked fitness: fitnesses range in [m,M]
|
||||
with m=2-pressure/popSize and M=pressure/popSize.
|
||||
in between, the progression depstd::ends on exponent (linear if 1).
|
||||
*/
|
||||
virtual void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
std::vector<const EOT *> rank;
|
||||
_pop.sort(rank);
|
||||
unsigned pSize = _pop.size();
|
||||
unsigned int pSizeMinusOne = pSize - 1;
|
||||
std::vector<const EOT *> rank;
|
||||
_pop.sort(rank);
|
||||
unsigned pSize =_pop.size();
|
||||
unsigned int pSizeMinusOne = pSize-1;
|
||||
|
||||
if (pSize <= 1)
|
||||
throw eoPopSizeException(pSize, "cannot do ranking with population of size <= 1");
|
||||
if (pSize <= 1)
|
||||
throw eoPopSizeException(pSize,"cannot do ranking with population of size <= 1");
|
||||
|
||||
// value() refers to the std::vector of worthes (we're in an eoParamvalue)
|
||||
value().resize(pSize);
|
||||
// value() refers to the std::vector of worthes (we're in an eoParamvalue)
|
||||
value().resize(pSize);
|
||||
|
||||
double beta = (2 - pressure) / pSize;
|
||||
if (exponent == 1.0) // no need for exponential then
|
||||
double beta = (2-pressure)/pSize;
|
||||
if (exponent == 1.0) // no need for exponetial then
|
||||
{
|
||||
double alpha = (2 * pressure - 2) / (pSize * pSizeMinusOne);
|
||||
for (unsigned i = 0; i < pSize; i++)
|
||||
double alpha = (2*pressure-2)/(pSize*pSizeMinusOne);
|
||||
for (unsigned i=0; i<pSize; i++)
|
||||
{
|
||||
int which = lookfor(rank[i], _pop);
|
||||
value()[which] = alpha * (pSize - i) + beta; // worst -> 1/[P(P-1)/2]
|
||||
int which = lookfor(rank[i], _pop);
|
||||
value()[which] = alpha*(pSize-i)+beta; // worst -> 1/[P(P-1)/2]
|
||||
}
|
||||
}
|
||||
else // exponent != 1
|
||||
else // exponent != 1
|
||||
{
|
||||
double gamma = (2 * pressure - 2) / pSize;
|
||||
for (unsigned i = 0; i < pSize; i++)
|
||||
double gamma = (2*pressure-2)/pSize;
|
||||
for (unsigned i=0; i<pSize; i++)
|
||||
{
|
||||
int which = lookfor(rank[i], _pop);
|
||||
// value is in [0,1]
|
||||
double tmp = ((double)(pSize - i)) / pSize;
|
||||
// to the exponent, and back to [m,M]
|
||||
value()[which] = gamma * pow(tmp, exponent) + beta;
|
||||
int which = lookfor(rank[i], _pop);
|
||||
// value in in [0,1]
|
||||
double tmp = ((double)(pSize-i))/pSize;
|
||||
// to the exponent, and back to [m,M]
|
||||
value()[which] = gamma*pow(tmp, exponent)+beta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
double pressure; // selective pressure
|
||||
double exponent;
|
||||
private:
|
||||
double pressure; // selective pressure
|
||||
double exponent;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoRankingCached.h
|
||||
(c) Maarten Keijzer, Marc Schoenauer, 2001
|
||||
|
||||
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; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
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: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoRankingCached_h
|
||||
#define eoRankingCached_h
|
||||
|
||||
#include "eoPerf2Worth.h"
|
||||
|
||||
/**
|
||||
* @class eoRankingCached
|
||||
* @brief Cached version of eoRanking that stores precomputed values for better performance
|
||||
*
|
||||
* This class implements the same ranking algorithm as eoRanking but adds a caching layer
|
||||
* that stores frequently used values when the population size remains constant between
|
||||
* calls. This optimization is particularly useful in steady-state evolution where the
|
||||
* population size typically doesn't change between selection operations.
|
||||
*
|
||||
* The caching mechanism stores:
|
||||
* - Population size related values (pSize, pSizeMinusOne)
|
||||
* - Precomputed coefficients (alpha, beta, gamma)
|
||||
*
|
||||
* @warning This optimization should only be used when the population size remains constant
|
||||
* between calls to the operator. For dynamic population sizes, use the standard eoRanking.
|
||||
*
|
||||
* @ingroup Selectors
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoRankingCached : public eoPerf2Worth<EOT>
|
||||
{
|
||||
public:
|
||||
using eoPerf2Worth<EOT>::value;
|
||||
|
||||
/* Ctor:
|
||||
@param _p selective pressure (in (1,2]
|
||||
@param _e exponent (1 == linear)
|
||||
*/
|
||||
eoRankingCached(double _p = 2.0, double _e = 1.0) : pressure(_p), exponent(_e), cached_pSize(0)
|
||||
{
|
||||
assert(1 < pressure and pressure <= 2);
|
||||
}
|
||||
|
||||
/*
|
||||
Computes the ranked fitness with caching optimization
|
||||
Fitnesses range in [m,M] where:
|
||||
- m = 2-pressure/popSize
|
||||
- M = pressure/popSize
|
||||
The progression between m and M depends on the exponent (linear when exponent=1)
|
||||
|
||||
@param _pop The population to rank
|
||||
*/
|
||||
virtual void operator()(const eoPop<EOT> &_pop)
|
||||
{
|
||||
unsigned pSize = _pop.size();
|
||||
|
||||
if (pSize <= 1)
|
||||
throw eoPopSizeException(pSize, "cannot do ranking with population of size <= 1");
|
||||
|
||||
// value() refers to the std::vector of worthes (we're in an eoParamvalue)
|
||||
value().resize(pSize);
|
||||
|
||||
// Cache population-size dependent values only when population size changes
|
||||
if (pSize != cached_pSize)
|
||||
{
|
||||
cached_pSize = pSize;
|
||||
cached_pSizeMinusOne = pSize - 1;
|
||||
cached_beta = (2 - pressure) / pSize;
|
||||
cached_gamma = (2 * pressure - 2) / pSize;
|
||||
cached_alpha = (2 * pressure - 2) / (pSize * cached_pSizeMinusOne);
|
||||
}
|
||||
|
||||
std::vector<const EOT *> rank;
|
||||
_pop.sort(rank);
|
||||
|
||||
// map of indices for the population
|
||||
std::unordered_map<const EOT *, unsigned> indexMap;
|
||||
for (unsigned i = 0; i < pSize; ++i)
|
||||
{
|
||||
indexMap[&_pop[i]] = i;
|
||||
}
|
||||
|
||||
if (exponent == 1.0) // no need for exponential then (linear case)
|
||||
{
|
||||
for (unsigned i = 0; i < pSize; i++)
|
||||
{
|
||||
const EOT *indiv = rank[i];
|
||||
int which = indexMap[indiv];
|
||||
value()[which] = cached_alpha * (pSize - i) + cached_beta;
|
||||
}
|
||||
}
|
||||
else // non-linear case (exponent != 1)
|
||||
{
|
||||
for (unsigned i = 0; i < pSize; i++)
|
||||
{
|
||||
const EOT *indiv = rank[i];
|
||||
int which = indexMap[indiv];
|
||||
// value is in [0,1]
|
||||
double tmp = ((double)(pSize - i)) / pSize;
|
||||
// to the exponent, and back to [m,M]
|
||||
value()[which] = cached_gamma * pow(tmp, exponent) + cached_beta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
double pressure; // selective pressure (1 < pressure <= 2)
|
||||
double exponent; // exponent (1 = linear)
|
||||
|
||||
// Cached values (recomputed only when population size changes)
|
||||
unsigned cached_pSize; // last seen population size
|
||||
unsigned cached_pSizeMinusOne; // pSize - 1
|
||||
double cached_alpha; // linear scaling coefficient
|
||||
double cached_beta; // base value coefficient
|
||||
double cached_gamma; // non-linear scaling coefficient
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
#ifndef eoRealToIntInit_h_INCLUDED
|
||||
#define eoRealToIntInit_h_INCLUDED
|
||||
|
||||
#include "es/eoReal.h"
|
||||
#include "utils/eoIntBounds.h"
|
||||
|
||||
template<class EOTINT, class EOTREAL = eoReal<typename EOTINT::FitnessType>>
|
||||
class eoRealToIntInit : public eoInit<EOTINT>
|
||||
{
|
||||
public:
|
||||
|
||||
using EOTreal = EOTREAL;
|
||||
|
||||
enum Repair {
|
||||
folds,
|
||||
truncate
|
||||
};
|
||||
|
||||
eoRealToIntInit( eoInit<EOTreal>& init ) :
|
||||
_whenout(Repair::truncate),
|
||||
_nobounds(),
|
||||
_bounds(_nobounds),
|
||||
_init(init)
|
||||
{ }
|
||||
|
||||
eoRealToIntInit( eoInit<EOTreal>& init, eoIntBounds& bounds, Repair whenout = Repair::truncate ) :
|
||||
_whenout(whenout),
|
||||
_nobounds(),
|
||||
_bounds(bounds),
|
||||
_init(init)
|
||||
{ }
|
||||
|
||||
virtual void operator()(EOTINT& intsol) override
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
for(size_t i=0; i < intsol.size(); ++i) {
|
||||
assert(_bounds.isInBounds(intsol[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
EOTreal floatsol;
|
||||
std::copy( std::begin(intsol), std::end(intsol), std::back_inserter(floatsol) );
|
||||
|
||||
_init(floatsol);
|
||||
|
||||
intsol.resize(floatsol.size());
|
||||
|
||||
for(size_t i=0; i < floatsol.size(); ++i) {
|
||||
typename EOTreal::AtomType rounded = std::round(floatsol[i]);
|
||||
if( not _bounds.isInBounds(rounded) ) {
|
||||
switch(_whenout) {
|
||||
case Repair::truncate:
|
||||
_bounds.truncate(rounded);
|
||||
break;
|
||||
case Repair::folds:
|
||||
_bounds.foldsInBounds(rounded);
|
||||
break;
|
||||
}
|
||||
}
|
||||
intsol[i] = static_cast<typename EOTINT::AtomType>(rounded);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Repair _whenout;
|
||||
eoIntNoBounds _nobounds;
|
||||
|
||||
eoIntBounds& _bounds;
|
||||
eoInit<EOTreal>& _init;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // eoRealToIntInit_h_INCLUDED
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#ifndef eoRealToIntMonOp_h_INCLUDED
|
||||
#define eoRealToIntMonOp_h_INCLUDED
|
||||
|
||||
#include "es/eoReal.h"
|
||||
#include "utils/eoIntBounds.h"
|
||||
|
||||
template<class EOTINT, class EOTREAL = eoReal<typename EOTINT::FitnessType>>
|
||||
class eoRealToIntMonOp : public eoMonOp<EOTINT>
|
||||
{
|
||||
public:
|
||||
|
||||
using EOTreal = EOTREAL;
|
||||
|
||||
enum Repair {
|
||||
folds,
|
||||
truncate
|
||||
};
|
||||
|
||||
eoRealToIntMonOp( eoMonOp<EOTreal>& monop ) :
|
||||
_whenout(Repair::truncate),
|
||||
_nobounds(),
|
||||
_bounds(_nobounds),
|
||||
_monop(monop)
|
||||
{ }
|
||||
|
||||
eoRealToIntMonOp( eoMonOp<EOTreal>& monop, eoIntBounds& bounds, Repair whenout = Repair::truncate ) :
|
||||
_whenout(whenout),
|
||||
_nobounds(),
|
||||
_bounds(bounds),
|
||||
_monop(monop)
|
||||
{ }
|
||||
|
||||
bool operator()(EOTINT& intsol)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
for(size_t i=0; i < intsol.size(); ++i) {
|
||||
assert(_bounds.isInBounds(intsol[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
EOTreal floatsol;
|
||||
std::copy( std::begin(intsol), std::end(intsol), std::back_inserter(floatsol) );
|
||||
|
||||
bool changed = _monop(floatsol);
|
||||
|
||||
if(changed) {
|
||||
for(size_t i=0; i < floatsol.size(); ++i) {
|
||||
typename EOTreal::AtomType rounded = std::round(floatsol[i]);
|
||||
if( not _bounds.isInBounds(rounded) ) {
|
||||
switch(_whenout) {
|
||||
case Repair::truncate:
|
||||
_bounds.truncate(rounded);
|
||||
break;
|
||||
case Repair::folds:
|
||||
_bounds.foldsInBounds(rounded);
|
||||
break;
|
||||
}
|
||||
}
|
||||
intsol[i] = static_cast<typename EOTINT::AtomType>(rounded);
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
protected:
|
||||
Repair _whenout;
|
||||
eoIntNoBounds _nobounds;
|
||||
|
||||
eoIntBounds& _bounds;
|
||||
eoMonOp<EOTreal>& _monop;
|
||||
};
|
||||
|
||||
#endif // eoRealToIntMonOp_h_INCLUDED
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
#ifndef eoRealToIntQuadOp_h_INCLUDED
|
||||
#define eoRealToIntQuadOp_h_INCLUDED
|
||||
|
||||
#include "es/eoReal.h"
|
||||
#include "utils/eoIntBounds.h"
|
||||
|
||||
template<class EOTINT, class EOTREAL = eoReal<typename EOTINT::FitnessType>>
|
||||
class eoRealToIntQuadOp : public eoQuadOp<EOTINT>
|
||||
{
|
||||
public:
|
||||
|
||||
using EOTreal = EOTREAL;
|
||||
|
||||
enum Repair {
|
||||
folds,
|
||||
truncate
|
||||
};
|
||||
|
||||
eoRealToIntQuadOp( eoQuadOp<EOTreal>& quadop ) :
|
||||
_whenout(Repair::truncate),
|
||||
_nobounds(),
|
||||
_bounds(_nobounds),
|
||||
_quadop(quadop)
|
||||
{ }
|
||||
|
||||
eoRealToIntQuadOp( eoQuadOp<EOTreal>& quadop, eoIntBounds& bounds, Repair whenout = Repair::truncate ) :
|
||||
_whenout(whenout),
|
||||
_nobounds(),
|
||||
_bounds(bounds),
|
||||
_quadop(quadop)
|
||||
{ }
|
||||
|
||||
bool operator()(EOTINT& intsol1, EOTINT& intsol2)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
for(size_t i=0; i < intsol1.size(); ++i) {
|
||||
assert(_bounds.isInBounds(intsol1[i]));
|
||||
}
|
||||
for(size_t i=0; i < intsol2.size(); ++i) {
|
||||
assert(_bounds.isInBounds(intsol2[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
EOTreal floatsol1;
|
||||
std::copy( std::begin(intsol1), std::end(intsol1), std::back_inserter(floatsol1) );
|
||||
|
||||
EOTreal floatsol2;
|
||||
std::copy( std::begin(intsol2), std::end(intsol2), std::back_inserter(floatsol2) );
|
||||
|
||||
bool changed = _quadop(floatsol1, floatsol2);
|
||||
|
||||
if(changed) {
|
||||
for(size_t i=0; i < floatsol1.size(); ++i) {
|
||||
typename EOTreal::AtomType rounded = std::round(floatsol1[i]);
|
||||
if( not _bounds.isInBounds(rounded) ) {
|
||||
switch(_whenout) {
|
||||
case Repair::truncate:
|
||||
_bounds.truncate(rounded);
|
||||
break;
|
||||
case Repair::folds:
|
||||
_bounds.foldsInBounds(rounded);
|
||||
break;
|
||||
}
|
||||
}
|
||||
intsol1[i] = static_cast<typename EOTINT::AtomType>(rounded);
|
||||
}
|
||||
for(size_t i=0; i < floatsol2.size(); ++i) {
|
||||
typename EOTreal::AtomType rounded = std::round(floatsol2[i]);
|
||||
if( not _bounds.isInBounds(rounded) ) {
|
||||
switch(_whenout) {
|
||||
case Repair::truncate:
|
||||
_bounds.truncate(rounded);
|
||||
break;
|
||||
case Repair::folds:
|
||||
_bounds.foldsInBounds(rounded);
|
||||
break;
|
||||
}
|
||||
}
|
||||
intsol2[i] = static_cast<typename EOTINT::AtomType>(rounded);
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
protected:
|
||||
Repair _whenout;
|
||||
eoIntNoBounds _nobounds;
|
||||
|
||||
eoIntBounds& _bounds;
|
||||
eoQuadOp<EOTreal>& _quadop;
|
||||
};
|
||||
|
||||
|
||||
#endif // eoRealToIntQuadOp_h_INCLUDED
|
||||
|
|
@ -79,12 +79,7 @@ void eoSTLF<void>::operator()(void)
|
|||
respectively
|
||||
*/
|
||||
template <class A1, class R>
|
||||
#if __cplusplus >= 201103L
|
||||
class eoSTLUF : public std::function<R(A1)>
|
||||
#else
|
||||
// Deprecated since C++11
|
||||
class eoSTLUF : public std::unary_function<A1, R>
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
eoSTLUF(eoUF<A1,R>& _f) : f(_f) {}
|
||||
|
|
@ -107,12 +102,7 @@ class eoSTLUF : public std::unary_function<A1, R>
|
|||
respectively
|
||||
*/
|
||||
template <class A1, class A2, class R>
|
||||
#if __cplusplus >= 201103L
|
||||
class eoSTLBF : public std::function<R(A1, A2)>
|
||||
#else
|
||||
// Deprecated since C++11
|
||||
class eoSTLBF : public std::binary_function<A1, A2, R>
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
eoSTLBF(eoUF<A1,R>& _f) : f(_f) {}
|
||||
|
|
|
|||
|
|
@ -230,25 +230,27 @@ protected:
|
|||
|
||||
// if the eval does not need to be used, use the dummy eval instance
|
||||
class eoDummyEval : public eoEvalFunc<POT>
|
||||
{
|
||||
{
|
||||
public:
|
||||
void operator()(POT &) override {}
|
||||
} dummyEval;
|
||||
void operator()(POT &)
|
||||
{}
|
||||
}
|
||||
dummyEval;
|
||||
|
||||
class eoDummyFlight:public eoFlight < POT >
|
||||
class eoDummyFlight:public eoFlight < POT >
|
||||
{
|
||||
public:
|
||||
eoDummyFlight () {}
|
||||
void operator() (POT &) override {}
|
||||
} dummyFlight;
|
||||
public:
|
||||
eoDummyFlight () {}
|
||||
void operator () (POT &) {}
|
||||
}dummyFlight;
|
||||
|
||||
// if the initializer does not need to be used, use the dummy one instead
|
||||
class eoDummyInitializer:public eoInitializerBase < POT >
|
||||
{
|
||||
public:
|
||||
eoDummyInitializer () {}
|
||||
void operator() () override {}
|
||||
} dummyInit;
|
||||
public:
|
||||
eoDummyInitializer () {}
|
||||
void operator () (POT &) {}
|
||||
}dummyInit;
|
||||
|
||||
};
|
||||
/** @example t-eoSyncEasyPSO.cpp
|
||||
|
|
|
|||
|
|
@ -113,19 +113,16 @@ CMAParams::CMAParams(eoParser& parser, unsigned dimensionality) {
|
|||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = mu - i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
weights = 1.;
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = log(mu+1.)-log(i+1.);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
template <class FitT> class eoReal: public eoVector<FitT, double>
|
||||
{
|
||||
public:
|
||||
using AtomType = double;
|
||||
using FitnessType = FitT;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -361,10 +361,10 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
|||
{
|
||||
if (chrom1[i] != chrom2[i] && eo::rng.flip(preference))
|
||||
{
|
||||
bool tmp = chrom1[i];
|
||||
chrom1[i]=chrom2[i];
|
||||
chrom2[i] = tmp;
|
||||
// std::swap(chrom1[i], chrom2[i]);
|
||||
// bool tmp = chrom1[i];
|
||||
// chrom1[i]=chrom2[i];
|
||||
// chrom2[i] = tmp;
|
||||
std::swap(chrom1[i], chrom2[i]);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,7 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
|
|||
protected:
|
||||
// a binary predicate for sorting
|
||||
// hopefully this will work with M$VC++ 6.0
|
||||
#if __cplusplus >= 201103L
|
||||
struct lt_arity:public std::function<bool(Node,Node)>
|
||||
#else
|
||||
struct lt_arity:public std::binary_function<Node,Node,bool>
|
||||
#endif
|
||||
{
|
||||
bool operator()(const Node &_node1, const Node &_node2) { return (_node1.arity() < _node2.arity());};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -468,11 +468,8 @@ private :
|
|||
switch(new_arity)
|
||||
{
|
||||
case 3 : args[2].copy(s.args[2]); args[2].parent = this; // no break!
|
||||
[[fallthrough]];
|
||||
case 2 : args[1].copy(s.args[1]); args[1].parent = this;
|
||||
[[fallthrough]];
|
||||
case 1 : args[0].copy(s.args[0]); args[0].parent = this;
|
||||
[[fallthrough]];
|
||||
case 0 : break;
|
||||
default :
|
||||
{
|
||||
|
|
@ -526,9 +523,7 @@ private :
|
|||
switch(arity())
|
||||
{
|
||||
case 3 : args[2].parent = 0; // no break!
|
||||
[[fallthrough]];
|
||||
case 2 : args[1].parent = 0;
|
||||
[[fallthrough]];
|
||||
case 1 : args[0].parent = 0; break;
|
||||
case 0 : break;
|
||||
default :
|
||||
|
|
@ -547,9 +542,7 @@ private :
|
|||
switch(arity())
|
||||
{
|
||||
case 3 : args[2].parent = this; // no break!
|
||||
[[fallthrough]];
|
||||
case 2 : args[1].parent = this;
|
||||
[[fallthrough]];
|
||||
case 1 : args[0].parent = this; break;
|
||||
case 0 : break;
|
||||
default :
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ Authors:
|
|||
# include "../eoFunctor.h"
|
||||
# include "../eoExceptions.h"
|
||||
|
||||
# include "mpi/implMpi.h"
|
||||
# include "eoMpiNode.h"
|
||||
# include "eoMpiAssignmentAlgorithm.h"
|
||||
|
||||
|
|
@ -670,7 +669,7 @@ namespace eo
|
|||
timerStat.start("master_wait_for_all_responses");
|
||||
while( assignmentAlgo.availableWorkers() != totalWorkers )
|
||||
{
|
||||
eo::mpi::status status = comm.probe( eo::mpi::any_source, eo::mpi::Channel::Messages );
|
||||
bmpi::status status = comm.probe( bmpi::any_source, eo::mpi::Channel::Messages );
|
||||
int wrkRank = status.source();
|
||||
that.handleResponse( wrkRank );
|
||||
comm.send( wrkRank, Channel::Commands, Message::Finish );
|
||||
|
|
@ -687,7 +686,7 @@ namespace eo
|
|||
AssignmentAlgorithm& assignmentAlgo;
|
||||
Job< JobData > & that;
|
||||
|
||||
eo::mpi::communicator & comm;
|
||||
bmpi::communicator & comm;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -714,7 +713,7 @@ namespace eo
|
|||
{
|
||||
eo::log << eo::debug << "[M" << comm.rank() << "] Waitin' for node..." << std::endl;
|
||||
|
||||
eo::mpi::status status = comm.probe( eo::mpi::any_source, eo::mpi::Channel::Messages );
|
||||
bmpi::status status = comm.probe( bmpi::any_source, eo::mpi::Channel::Messages );
|
||||
int wrkRank = status.source();
|
||||
|
||||
eo::log << eo::debug << "[M" << comm.rank() << "] Node " << wrkRank << " just terminated." << std::endl;
|
||||
|
|
@ -798,7 +797,7 @@ namespace eo
|
|||
AssignmentAlgorithm& assignmentAlgo;
|
||||
int masterRank;
|
||||
const int workerStopCondition;
|
||||
eo::mpi::communicator& comm;
|
||||
bmpi::communicator& comm;
|
||||
|
||||
JobStore<JobData>& store;
|
||||
SendTaskFunction<JobData> & sendTask;
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ namespace eo
|
|||
{
|
||||
void Node::init( int argc, char** argv )
|
||||
{
|
||||
static eo::mpi::environment env( argc, argv );
|
||||
static bmpi::environment env( argc, argv );
|
||||
}
|
||||
|
||||
eo::mpi::communicator& Node::comm()
|
||||
bmpi::communicator& Node::comm()
|
||||
{
|
||||
return _comm;
|
||||
}
|
||||
|
||||
eo::mpi::communicator Node::_comm;
|
||||
bmpi::communicator Node::_comm;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ Authors:
|
|||
# define __MPI_NODE_H__
|
||||
|
||||
# include "implMpi.h"
|
||||
// namespace bmpi = mpi;
|
||||
namespace bmpi = mpi;
|
||||
|
||||
namespace eo
|
||||
{
|
||||
|
|
@ -54,10 +54,10 @@ namespace eo
|
|||
/**
|
||||
* @brief Returns the global mpi::communicator
|
||||
*/
|
||||
static eo::mpi::communicator& comm();
|
||||
static bmpi::communicator& comm();
|
||||
|
||||
protected:
|
||||
static eo::mpi::communicator _comm;
|
||||
static bmpi::communicator _comm;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace eo
|
|||
typedef eoUF< eoPop<EOT>&, void> ResetAlgo;
|
||||
|
||||
MultiStartData(
|
||||
eo::mpi::communicator& _comm,
|
||||
bmpi::communicator& _comm,
|
||||
eoAlgo<EOT>& _algo,
|
||||
int _masterRank,
|
||||
ResetAlgo & _resetAlgo )
|
||||
|
|
@ -87,7 +87,7 @@ namespace eo
|
|||
/**
|
||||
* @brief Communicator, used to send and retrieve messages.
|
||||
*/
|
||||
eo::mpi::communicator& comm;
|
||||
bmpi::communicator& comm;
|
||||
|
||||
/**
|
||||
* @brief Algorithm which will be performed by the worker.
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ namespace eo
|
|||
std::vector<EOT> tempArray;
|
||||
|
||||
int masterRank;
|
||||
eo::mpi::communicator& comm;
|
||||
bmpi::communicator& comm;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ Authors:
|
|||
*/
|
||||
#include "implMpi.h"
|
||||
|
||||
namespace eo
|
||||
{
|
||||
namespace mpi
|
||||
{
|
||||
const int any_source = MPI_ANY_SOURCE;
|
||||
|
|
@ -161,9 +159,8 @@ namespace mpi
|
|||
MPI_Barrier( MPI_COMM_WORLD );
|
||||
}
|
||||
|
||||
void broadcast( communicator & /*comm*/, int value, int root )
|
||||
void broadcast( communicator & comm, int value, int root )
|
||||
{
|
||||
MPI_Bcast( &value, 1, MPI_INT, root, MPI_COMM_WORLD );
|
||||
}
|
||||
} // namespace mpi
|
||||
} // namespace eo
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Authors:
|
|||
#ifndef __EO_IMPL_MPI_HPP__
|
||||
#define __EO_IMPL_MPI_HPP__
|
||||
|
||||
#include <mpi.h>
|
||||
#include "eoMpi.h"
|
||||
#include "../serial/eoSerial.h"
|
||||
|
||||
/**
|
||||
|
|
@ -41,290 +41,282 @@ Authors:
|
|||
* The entities are here shortly described, if you need further details, don't hesitate
|
||||
* to visit the boost URL.
|
||||
*/
|
||||
namespace eo
|
||||
|
||||
namespace mpi
|
||||
{
|
||||
namespace mpi
|
||||
/**
|
||||
* @ingroup Parallel
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Constant indicating that a message can come from any process.
|
||||
*/
|
||||
extern const int any_source;
|
||||
|
||||
/**
|
||||
* @brief Constant indicating that a message can come from any tag (channel).
|
||||
*/
|
||||
extern const int any_tag;
|
||||
|
||||
/**
|
||||
* @brief Wrapper class to have a MPI environment.
|
||||
*
|
||||
* Instead of calling MPI_Init and MPI_Finalize, it is only necessary to instantiate
|
||||
* this class once, in the global context.
|
||||
*/
|
||||
class environment
|
||||
{
|
||||
/**
|
||||
* @ingroup Parallel
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Constant indicating that a message can come from any process.
|
||||
*/
|
||||
extern const int any_source;
|
||||
|
||||
/**
|
||||
* @brief Constant indicating that a message can come from any tag (channel).
|
||||
*/
|
||||
extern const int any_tag;
|
||||
|
||||
/**
|
||||
* @brief Wrapper class to have a MPI environment.
|
||||
*
|
||||
* Instead of calling MPI_Init and MPI_Finalize, it is only necessary to instantiate
|
||||
* this class once, in the global context.
|
||||
*/
|
||||
class environment
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Inits MPI context.
|
||||
*
|
||||
* @param argc Number of params in command line (same as one in main)
|
||||
* @param argv Strings containing params (same as one in main)
|
||||
*/
|
||||
environment(int argc, char **argv);
|
||||
|
||||
/**
|
||||
* @brief Closes MPI context.
|
||||
*/
|
||||
~environment();
|
||||
};
|
||||
|
||||
/* struct MPI_Status
|
||||
{
|
||||
int count;
|
||||
int cancelled;
|
||||
int MPI_SOURCE;
|
||||
int MPI_TAG;
|
||||
int MPI_ERROR;
|
||||
}; */
|
||||
|
||||
/**
|
||||
* @brief Wrapper class for MPI_Status
|
||||
* @brief Inits MPI context.
|
||||
*
|
||||
* Consists only in a C++ wrapper class, giving getters on status attributes.
|
||||
* @param argc Number of params in command line (same as one in main)
|
||||
* @param argv Strings containing params (same as one in main)
|
||||
*/
|
||||
class status
|
||||
{
|
||||
environment(int argc, char**argv);
|
||||
|
||||
/**
|
||||
* @brief Closes MPI context.
|
||||
*/
|
||||
~environment();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Wrapper class for MPI_Status
|
||||
*
|
||||
* Consists only in a C++ wrapper class, giving getters on status attributes.
|
||||
*/
|
||||
class status
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Converts a MPI_Status into a status.
|
||||
*/
|
||||
status(const MPI_Status &s);
|
||||
|
||||
/**
|
||||
* @brief Returns the tag of the associated communication.
|
||||
*/
|
||||
int tag() { return _tag; }
|
||||
/**
|
||||
* @brief Converts a MPI_Status into a status.
|
||||
*/
|
||||
status( const MPI_Status & s );
|
||||
|
||||
/**
|
||||
* @brief Indicates which error number we obtained in the associated communication.
|
||||
*/
|
||||
int error() { return _error; }
|
||||
/**
|
||||
* @brief Returns the tag of the associated communication.
|
||||
*/
|
||||
int tag() { return _tag; }
|
||||
|
||||
/**
|
||||
* @brief Returns the MPI rank of the source of the associated communication.
|
||||
*/
|
||||
int source() { return _source; }
|
||||
/**
|
||||
* @brief Indicates which error number we obtained in the associated communication.
|
||||
*/
|
||||
int error() { return _error; }
|
||||
|
||||
/**
|
||||
* @brief Returns the MPI rank of the source of the associated communication.
|
||||
*/
|
||||
int source() { return _source; }
|
||||
|
||||
private:
|
||||
int _source;
|
||||
int _tag;
|
||||
int _error;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Main object, used to send / receive messages, get informations about the rank and the size of the world,
|
||||
* etc.
|
||||
*/
|
||||
class communicator
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Main object, used to send / receive messages, get informations about the rank and the size of the world,
|
||||
* etc.
|
||||
* Creates the communicator, using the whole world as a MPI_Comm.
|
||||
*
|
||||
* @todo Allow the user to precise which MPI_Comm to use
|
||||
*/
|
||||
class communicator
|
||||
communicator( );
|
||||
|
||||
~communicator();
|
||||
|
||||
/**
|
||||
* @brief Returns the MPI rank of the current process.
|
||||
*/
|
||||
int rank();
|
||||
|
||||
/**
|
||||
* @brief Returns the size of the MPI cluster.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/*
|
||||
* SEND / RECV INT
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends an integer to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param n The integer to send
|
||||
*/
|
||||
void send( int dest, int tag, int n );
|
||||
|
||||
/*
|
||||
* @brief Receives an integer from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param n Where to save the received integer
|
||||
*/
|
||||
void recv( int src, int tag, int& n );
|
||||
|
||||
/*
|
||||
* SEND / RECV STRING
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends a string to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param str The std::string to send
|
||||
*/
|
||||
void send( int dest, int tag, const std::string& str );
|
||||
|
||||
/*
|
||||
* @brief Receives a string from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param std::string Where to save the received string
|
||||
*/
|
||||
void recv( int src, int tag, std::string& str );
|
||||
|
||||
/*
|
||||
* SEND / RECV Objects
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends an eoserial::Persistent to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param persistent The object to send (it must absolutely implement eoserial::Persistent)
|
||||
*/
|
||||
void send( int dest, int tag, const eoserial::Persistent & persistent );
|
||||
|
||||
/**
|
||||
* @brief Sends an array of eoserial::Persistent to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param table The array of eoserial::Persistent objects
|
||||
* @param size The number of elements to send (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template< class T >
|
||||
void send( int dest, int tag, T* table, int size )
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates the communicator, using the whole world as a MPI_Comm.
|
||||
*
|
||||
* @todo Allow the user to precise which MPI_Comm to use
|
||||
*/
|
||||
communicator();
|
||||
// Puts all the values into an array
|
||||
eoserial::Array* array = new eoserial::Array;
|
||||
|
||||
~communicator();
|
||||
|
||||
/**
|
||||
* @brief Returns the MPI rank of the current process.
|
||||
*/
|
||||
int rank();
|
||||
|
||||
/**
|
||||
* @brief Returns the size of the MPI cluster.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/*
|
||||
* SEND / RECV INT
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends an integer to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param n The integer to send
|
||||
*/
|
||||
void send(int dest, int tag, int n);
|
||||
|
||||
/*
|
||||
* @brief Receives an integer from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param n Where to save the received integer
|
||||
*/
|
||||
void recv(int src, int tag, int &n);
|
||||
|
||||
/*
|
||||
* SEND / RECV STRING
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends a string to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param str The std::string to send
|
||||
*/
|
||||
void send(int dest, int tag, const std::string &str);
|
||||
|
||||
/*
|
||||
* @brief Receives a string from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param std::string Where to save the received string
|
||||
*/
|
||||
void recv(int src, int tag, std::string &str);
|
||||
|
||||
/*
|
||||
* SEND / RECV Objects
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sends an eoserial::Persistent to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param persistent The object to send (it must absolutely implement eoserial::Persistent)
|
||||
*/
|
||||
void send(int dest, int tag, const eoserial::Persistent &persistent);
|
||||
|
||||
/**
|
||||
* @brief Sends an array of eoserial::Persistent to dest on channel "tag".
|
||||
*
|
||||
* @param dest MPI rank of the receiver
|
||||
* @param tag MPI tag of message
|
||||
* @param table The array of eoserial::Persistent objects
|
||||
* @param size The number of elements to send (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template <class T>
|
||||
void send(int dest, int tag, T *table, int size)
|
||||
for( int i = 0; i < size; ++i )
|
||||
{
|
||||
// Puts all the values into an array
|
||||
eoserial::Array *array = new eoserial::Array;
|
||||
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
array->push_back(table[i].pack());
|
||||
}
|
||||
|
||||
// Encapsulates the array into an object
|
||||
eoserial::Object *obj = new eoserial::Object;
|
||||
obj->add("array", array);
|
||||
std::stringstream ss;
|
||||
obj->print(ss);
|
||||
delete obj;
|
||||
|
||||
// Sends the object as a string
|
||||
send(dest, tag, ss.str());
|
||||
array->push_back( table[i].pack() );
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Receives an eoserial::Persistent object from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param persistent Where to unpack the serialized object?
|
||||
*/
|
||||
void recv(int src, int tag, eoserial::Persistent &persistent);
|
||||
// Encapsulates the array into an object
|
||||
eoserial::Object* obj = new eoserial::Object;
|
||||
obj->add( "array", array );
|
||||
std::stringstream ss;
|
||||
obj->print( ss );
|
||||
delete obj;
|
||||
|
||||
/*
|
||||
* @brief Receives an array of eoserial::Persistent from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param table The table in which we're saving the received objects. It must have been allocated by the user,
|
||||
* as no allocation is performed here.
|
||||
* @param size The number of elements to receive (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template <class T>
|
||||
void recv(int src, int tag, T *table, int size)
|
||||
// Sends the object as a string
|
||||
send( dest, tag, ss.str() );
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Receives an eoserial::Persistent object from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param persistent Where to unpack the serialized object?
|
||||
*/
|
||||
void recv( int src, int tag, eoserial::Persistent & persistent );
|
||||
|
||||
/*
|
||||
* @brief Receives an array of eoserial::Persistent from src on channel "tag".
|
||||
*
|
||||
* @param src MPI rank of the sender
|
||||
* @param tag MPI tag of message
|
||||
* @param table The table in which we're saving the received objects. It must have been allocated by the user,
|
||||
* as no allocation is performed here.
|
||||
* @param size The number of elements to receive (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template< class T >
|
||||
void recv( int src, int tag, T* table, int size )
|
||||
{
|
||||
// Receives the string which contains the object
|
||||
std::string asText;
|
||||
recv( src, tag, asText );
|
||||
|
||||
// Parses the object and retrieves the table
|
||||
eoserial::Object* obj = eoserial::Parser::parse( asText );
|
||||
eoserial::Array* array = static_cast<eoserial::Array*>( (*obj)["array"] );
|
||||
|
||||
// Retrieves all the values from the array
|
||||
for( int i = 0; i < size; ++i )
|
||||
{
|
||||
// Receives the string which contains the object
|
||||
std::string asText;
|
||||
recv(src, tag, asText);
|
||||
|
||||
// Parses the object and retrieves the table
|
||||
eoserial::Object *obj = eoserial::Parser::parse(asText);
|
||||
eoserial::Array *array = static_cast<eoserial::Array *>((*obj)["array"]);
|
||||
|
||||
// Retrieves all the values from the array
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
eoserial::unpackObject(*array, i, table[i]);
|
||||
}
|
||||
delete obj;
|
||||
eoserial::unpackObject( *array, i, table[i] );
|
||||
}
|
||||
delete obj;
|
||||
}
|
||||
|
||||
/*
|
||||
* Other methods
|
||||
*/
|
||||
/*
|
||||
* Other methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Wrapper for MPI_Probe
|
||||
*
|
||||
* Waits for a message to come from process having rank src, on the channel
|
||||
* tag.
|
||||
*
|
||||
* @param src MPI rank of the sender (any_source if it can be any sender)
|
||||
* @param tag MPI tag of the expected message (any_tag if it can be any tag)
|
||||
*/
|
||||
status probe(int src = any_source, int tag = any_tag);
|
||||
/**
|
||||
* @brief Wrapper for MPI_Probe
|
||||
*
|
||||
* Waits for a message to come from process having rank src, on the channel
|
||||
* tag.
|
||||
*
|
||||
* @param src MPI rank of the sender (any_source if it can be any sender)
|
||||
* @param tag MPI tag of the expected message (any_tag if it can be any tag)
|
||||
*/
|
||||
status probe( int src = any_source, int tag = any_tag );
|
||||
|
||||
/**
|
||||
* @brief Wrapper for MPI_Barrier
|
||||
*
|
||||
*
|
||||
*/
|
||||
void barrier();
|
||||
/**
|
||||
* @brief Wrapper for MPI_Barrier
|
||||
*
|
||||
*
|
||||
*/
|
||||
void barrier();
|
||||
|
||||
private:
|
||||
int _rank;
|
||||
int _size;
|
||||
|
||||
char *_buf; // temporary buffer for sending and receiving strings. Avoids reallocations
|
||||
char* _buf; // temporary buffer for sending and receiving strings. Avoids reallocations
|
||||
int _bufsize; // size of the above temporary buffer
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Wrapper for MPI_Bcast
|
||||
*
|
||||
* Broadcasts an integer value on the communicator comm, from the process having the MPI rank root.
|
||||
*
|
||||
* @param comm The communicator on which to broadcast
|
||||
* @param value The integer value to send
|
||||
* @param root The MPI rank of the broadcaster
|
||||
*
|
||||
* @todo Actually comm isn't used and broadcast is performed on the whole MPI_COMM_WORLD. TODO: Use comm instead
|
||||
*/
|
||||
void broadcast(communicator &comm, int value, int root);
|
||||
/**
|
||||
* @brief Wrapper for MPI_Bcast
|
||||
*
|
||||
* Broadcasts an integer value on the communicator comm, from the process having the MPI rank root.
|
||||
*
|
||||
* @param comm The communicator on which to broadcast
|
||||
* @param value The integer value to send
|
||||
* @param root The MPI rank of the broadcaster
|
||||
*
|
||||
* @todo Actually comm isn't used and broadcast is performed on the whole MPI_COMM_WORLD. TODO: Use comm instead
|
||||
*/
|
||||
void broadcast( communicator & comm, int value, int root );
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
} // namespace mpi
|
||||
} // namespace eo
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
} // namespace mpi
|
||||
|
||||
#endif //__EO_IMPL_MPI_HPP__
|
||||
# endif //__EO_IMPL_MPI_HPP__
|
||||
|
|
|
|||
|
|
@ -56,24 +56,22 @@ eoGnuplot::~eoGnuplot()
|
|||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GNUPLOT
|
||||
|
||||
void eoGnuplot::gnuplotCommand(const char *_command)
|
||||
{
|
||||
#ifdef HAVE_GNUPLOT
|
||||
if(gpCom) {
|
||||
PipeComSend( gpCom, _command );
|
||||
PipeComSend( gpCom, "\n" );
|
||||
}
|
||||
}
|
||||
#else
|
||||
void eoGnuplot::gnuplotCommand(const char *)
|
||||
{ }
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_GNUPLOT
|
||||
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||
{
|
||||
#ifdef HAVE_GNUPLOT
|
||||
std::ostringstream os;
|
||||
os << "250x150-0+" << 170 * numWindow++;
|
||||
char *args[6];
|
||||
|
|
@ -91,12 +89,8 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
|||
PipeComSend( gpCom, _extra.c_str() );
|
||||
PipeComSend( gpCom, "\n" );
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
void eoGnuplot::initGnuPlot(std::string, std::string)
|
||||
{ }
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,10 +39,8 @@ eoParallel::eoParallel() :
|
|||
_nthreads( 0, "parallelize-nthreads", "Define the number of threads you want to use, nthreads = 0 means you want to use all threads available", '\0' ),
|
||||
_enableResults( false, "parallelize-enable-results", "Enable the generation of results", '\0' ),
|
||||
_doMeasure( false, "parallelize-do-measure", "Do some measures during execution", '\0' ),
|
||||
_packetSize( 1U, "parallelize-packet-size", "Number of elements which should be sent in a single message during a parallel evaluation based on message passing.", '\0')
|
||||
#ifdef _OPENMP
|
||||
, _t_start(0)
|
||||
#endif
|
||||
_packetSize( 1U, "parallelize-packet-size", "Number of elements which should be sent in a single message during a parallel evaluation based on message passing.", '\0'),
|
||||
_t_start(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,9 +71,7 @@ private:
|
|||
eoValueParam<bool> _enableResults;
|
||||
eoValueParam<bool> _doMeasure;
|
||||
eoValueParam<unsigned int> _packetSize;
|
||||
#ifdef _OPENMP
|
||||
double _t_start;
|
||||
#endif
|
||||
};
|
||||
|
||||
void make_parallel(eoParser&);
|
||||
|
|
|
|||
|
|
@ -42,16 +42,16 @@ int Check( PCom *com )
|
|||
}
|
||||
|
||||
|
||||
PCom * PipeComOpen( const char *prog )
|
||||
PCom * PipeComOpen( char *prog )
|
||||
{
|
||||
char *args[2];
|
||||
args[0] = strdup( prog );
|
||||
args[0] = prog;
|
||||
args[1] = NULL;
|
||||
return PipeComOpenArgv( prog, args );
|
||||
}
|
||||
|
||||
|
||||
PCom * PipeComOpenArgv( const char *prog, char *argv[] )
|
||||
PCom * PipeComOpenArgv( char *prog, char *argv[] )
|
||||
{
|
||||
int toFils[2];
|
||||
int toPere[2];
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ typedef struct PipeCommunication {
|
|||
} PCom;
|
||||
|
||||
|
||||
extern PCom *PipeComOpen( const char *prog );
|
||||
extern PCom *PipeComOpenArgv( const char *prog, char *argv[] );
|
||||
extern PCom *PipeComOpen( char *prog );
|
||||
extern PCom *PipeComOpenArgv( char *prog, char *argv[] );
|
||||
|
||||
extern int PipeComSend( PCom *to, const char *line );
|
||||
extern int PipeComSendn( PCom *to, const char *data, int n );
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ inline bool random_generator<bool>::operator()(void)
|
|||
function (see eoPop::shuffle): its operator() takes an unsigned argument m
|
||||
and must return an unsigned uniformly distributed in [0,m}
|
||||
*/
|
||||
// FIXME this is probably deprecated by the new STL way of managing random generators.
|
||||
template <class T = uint32_t>
|
||||
class UF_random_generator
|
||||
{
|
||||
|
|
@ -135,11 +134,11 @@ class UF_random_generator
|
|||
: _max(max), _random(_rng)
|
||||
{}
|
||||
|
||||
T operator()() const { return _random.random(_max); }
|
||||
T operator()(T m) const { return _random.random(m); }
|
||||
T operator()() { return _random.random(_max); }
|
||||
T operator()(T m) { return _random.random(m); }
|
||||
|
||||
T min() const { return 0; }
|
||||
T max() const { return _max; }
|
||||
T min() { return 0; }
|
||||
T max() { return _max; }
|
||||
|
||||
private :
|
||||
T _max;
|
||||
|
|
|
|||
|
|
@ -179,8 +179,7 @@ double sum_fitness(const eoPop<EOT>& _pop)
|
|||
template <class EOT>
|
||||
double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
||||
{
|
||||
// double rawTotal = 0;
|
||||
double scaledTotal;
|
||||
double rawTotal, scaledTotal;
|
||||
|
||||
typename eoPop<EOT>::const_iterator it = _pop.begin();
|
||||
|
||||
|
|
@ -194,7 +193,7 @@ double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
|||
_minmax.first = std::min(_minmax.first, v);
|
||||
_minmax.second = std::max(_minmax.second, v);
|
||||
|
||||
// rawTotal += v;
|
||||
rawTotal += v;
|
||||
}
|
||||
|
||||
if (minimizing_fitness<EOT>())
|
||||
|
|
|
|||
|
|
@ -80,9 +80,6 @@ set (TEST_LIST
|
|||
t-forge-FastGA
|
||||
t-eoFoundryFastGA
|
||||
t-eoAlgoFoundryFastGA
|
||||
t-eoRealToIntMonOp
|
||||
t-eoRealToIntQuadOp
|
||||
t-eoRankingCached
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ class Experiment : public eoserial::Persistent
|
|||
|
||||
void run()
|
||||
{
|
||||
communicator& comm = eo::mpi::Node::comm();
|
||||
mpi::communicator& comm = eo::mpi::Node::comm();
|
||||
// reinits every objects
|
||||
eo::rng.reseed( _seed );
|
||||
eo::rng.clearCache(); // trick for repeatable sequences of normal numbers, cf eo::rng
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
|
||||
/***** Crossovers ****/
|
||||
foundry.crossovers.add< eo1PtBitXover<EOT> >();
|
||||
// foundry.crossovers.add< eoUBitXover<EOT> >(0.5); // preference over 1
|
||||
foundry.crossovers.add< eoUBitXover<EOT> >(0.5); // preference over 1
|
||||
for(size_t i=1; i < 11; i+=4) {
|
||||
foundry.crossovers.add< eoNPtsBitXover<EOT> >(i); // nb of points
|
||||
}
|
||||
|
|
@ -43,9 +43,9 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
std::ref(foundry.mutation_selectors) }) {
|
||||
|
||||
ops.add< eoRandomSelect<EOT> >();
|
||||
// ops.add< eoStochTournamentSelect<EOT> >(0.5);
|
||||
// ops.add< eoSequentialSelect<EOT> >();
|
||||
// ops.add< eoProportionalSelect<EOT> >();
|
||||
ops.add< eoStochTournamentSelect<EOT> >(0.5);
|
||||
ops.add< eoSequentialSelect<EOT> >();
|
||||
ops.add< eoProportionalSelect<EOT> >();
|
||||
for(size_t i=2; i < 10; i+=4) {
|
||||
ops.add< eoDetTournamentSelect<EOT> >(i);
|
||||
}
|
||||
|
|
@ -53,16 +53,16 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
|
||||
/***** Replacements ****/
|
||||
foundry.replacements.add< eoCommaReplacement<EOT> >();
|
||||
// foundry.replacements.add< eoPlusReplacement<EOT> >();
|
||||
// foundry.replacements.add< eoSSGAWorseReplacement<EOT> >();
|
||||
// foundry.replacements.add< eoSSGAStochTournamentReplacement<EOT> >(0.51);
|
||||
foundry.replacements.add< eoPlusReplacement<EOT> >();
|
||||
foundry.replacements.add< eoSSGAWorseReplacement<EOT> >();
|
||||
foundry.replacements.add< eoSSGAStochTournamentReplacement<EOT> >(0.51);
|
||||
for(size_t i=2; i < 10; i+=4) {
|
||||
foundry.replacements.add< eoSSGADetTournamentReplacement<EOT> >(i);
|
||||
}
|
||||
|
||||
/***** Continuators ****/
|
||||
for(size_t i=3; i < 5; i+=1 ) {
|
||||
foundry.continuators.add< eoGenContinue<EOT> >(i);
|
||||
for(size_t i=10; i < 30; i+=10 ) {
|
||||
foundry.continuators.add< eoSteadyFitContinue<EOT> >(10,i);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ public :
|
|||
int the_main(int argc, char **argv)
|
||||
{ // ok, we have a command line parser and a state
|
||||
|
||||
typedef eoBit<float> Chrom;
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// Define Parameters
|
||||
|
|
|
|||
|
|
@ -1,219 +0,0 @@
|
|||
#include <apply.h>
|
||||
#include <eo>
|
||||
#include <eoRanking.h>
|
||||
#include <eoRankingCached.h>
|
||||
#include <es/eoReal.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include "real_value.h"
|
||||
|
||||
class RankingTest
|
||||
{
|
||||
public:
|
||||
RankingTest(eoParser &parser, eoEvalFuncCounter<eoReal<double>> &_eval, unsigned size = 100)
|
||||
: rng(0),
|
||||
popSize(size),
|
||||
seedParam(parser.createParam(uint32_t(time(0)), "seed", "Random seed", 'S')),
|
||||
pressureParam(parser.createParam(1.5, "pressure", "Selective pressure", 'p')),
|
||||
exponentParam(parser.createParam(1.0, "exponent", "Ranking exponent", 'e')),
|
||||
eval(_eval)
|
||||
{
|
||||
rng.reseed(seedParam.value());
|
||||
initPopulation();
|
||||
}
|
||||
|
||||
void initPopulation()
|
||||
{
|
||||
pop.clear();
|
||||
for (unsigned i = 0; i < popSize; ++i)
|
||||
{
|
||||
eoReal<double> ind;
|
||||
ind.resize(1);
|
||||
ind[0] = rng.uniform();
|
||||
pop.push_back(ind);
|
||||
}
|
||||
apply<eoReal<double>>(eval, pop);
|
||||
}
|
||||
|
||||
const unsigned popSize;
|
||||
eoPop<eoReal<double>> pop;
|
||||
eoRng rng;
|
||||
double pressure() const { return pressureParam.value(); }
|
||||
double exponent() const { return exponentParam.value(); }
|
||||
|
||||
private:
|
||||
eoValueParam<uint32_t> &seedParam;
|
||||
eoValueParam<double> &pressureParam;
|
||||
eoValueParam<double> &exponentParam;
|
||||
eoEvalFuncCounter<eoReal<double>> eval;
|
||||
};
|
||||
|
||||
// Test case 1: Verify both implementations produce identical results
|
||||
void test_Consistency(eoParser &parser)
|
||||
{
|
||||
eoEvalFuncPtr<eoReal<double>, double, const std::vector<double> &> mainEval(real_value);
|
||||
eoEvalFuncCounter<eoReal<double>> eval(mainEval);
|
||||
RankingTest fixture(parser, eval);
|
||||
|
||||
eoRanking<eoReal<double>> ranking(fixture.pressure(), fixture.exponent());
|
||||
eoRankingCached<eoReal<double>> rankingCached(fixture.pressure(), fixture.exponent());
|
||||
|
||||
ranking(fixture.pop);
|
||||
rankingCached(fixture.pop);
|
||||
|
||||
const std::vector<double> &values = ranking.value();
|
||||
const std::vector<double> &cachedValues = rankingCached.value();
|
||||
|
||||
for (unsigned i = 0; i < fixture.pop.size(); ++i)
|
||||
{
|
||||
if (abs(values[i] - cachedValues[i]) > 1e-9)
|
||||
{
|
||||
throw std::runtime_error("Inconsistent ranking values between implementations");
|
||||
}
|
||||
}
|
||||
std::clog << "Test 1 passed: Both implementations produce identical results" << std::endl;
|
||||
}
|
||||
|
||||
// Test case 2: Test edge case with minimum population size
|
||||
void test_MinPopulationSize(eoParser &parser)
|
||||
{
|
||||
eoPop<eoReal<double>> smallPop;
|
||||
eoReal<double> ind1, ind2;
|
||||
ind1.resize(1);
|
||||
ind1[0] = 0.5;
|
||||
ind2.resize(1);
|
||||
ind2[0] = 1.0;
|
||||
smallPop.push_back(ind1);
|
||||
smallPop.push_back(ind2);
|
||||
eoEvalFuncPtr<eoReal<double>, double, const std::vector<double> &> mainEval(real_value);
|
||||
eoEvalFuncCounter<eoReal<double>> eval(mainEval);
|
||||
|
||||
RankingTest fixture(parser, eval, 2); // Use fixture to get parameters
|
||||
eoRanking<eoReal<double>> ranking(fixture.pressure(), fixture.exponent());
|
||||
eoRankingCached<eoReal<double>> rankingCached(fixture.pressure(), fixture.exponent());
|
||||
|
||||
apply<eoReal<double>>(eval, smallPop);
|
||||
|
||||
ranking(smallPop);
|
||||
rankingCached(smallPop);
|
||||
|
||||
if (ranking.value()[0] >= ranking.value()[1] ||
|
||||
rankingCached.value()[0] >= rankingCached.value()[1])
|
||||
{
|
||||
throw std::runtime_error("Invalid ranking for population size 2");
|
||||
}
|
||||
std::clog << "Test 2 passed: Minimum population size handled correctly" << std::endl;
|
||||
}
|
||||
|
||||
// Test case 3: Verify caching actually works
|
||||
void test_CachingEffectiveness(eoParser &parser)
|
||||
{
|
||||
eoEvalFuncPtr<eoReal<double>, double, const std::vector<double> &> mainEval(real_value);
|
||||
eoEvalFuncCounter<eoReal<double>> eval(mainEval);
|
||||
RankingTest fixture(parser, eval, 50); // Fixed size for cache test
|
||||
|
||||
eoRankingCached<eoReal<double>> rankingCached(fixture.pressure(), fixture.exponent());
|
||||
|
||||
// First run - should compute all values
|
||||
rankingCached(fixture.pop);
|
||||
const auto firstValues = rankingCached.value();
|
||||
|
||||
// Modify fitness values but keep same population size
|
||||
for (auto &ind : fixture.pop)
|
||||
{
|
||||
ind[0] = fixture.rng.uniform();
|
||||
}
|
||||
|
||||
apply<eoReal<double>>(eval, fixture.pop);
|
||||
|
||||
// Second run - should use cached coefficients
|
||||
rankingCached(fixture.pop);
|
||||
|
||||
// Add one individual to invalidate cache
|
||||
eoReal<double> newInd;
|
||||
newInd.resize(1);
|
||||
newInd[0] = fixture.rng.uniform();
|
||||
fixture.pop.push_back(newInd);
|
||||
|
||||
apply<eoReal<double>>(eval, fixture.pop);
|
||||
|
||||
// Third run - should recompute coefficients
|
||||
rankingCached(fixture.pop);
|
||||
|
||||
std::clog << "Test 3 passed: Caching mechanism properly invalidated" << std::endl;
|
||||
}
|
||||
|
||||
// Helper function to test constructor assertions
|
||||
bool testRankingConstructor(double pressure, double exponent)
|
||||
{
|
||||
try
|
||||
{
|
||||
eoRanking<eoReal<double>> ranking(pressure, exponent);
|
||||
return true; // Constructor succeeded
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false; // Assertion failed
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to test constructor assertions
|
||||
bool testRankingCachedConstructor(double pressure, double exponent)
|
||||
{
|
||||
try
|
||||
{
|
||||
eoRankingCached<eoReal<double>> ranking(pressure, exponent);
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Test case 4: Verify assertions on invalid parameters
|
||||
void test_Assertions(eoParser &parser)
|
||||
{
|
||||
// Test valid parameters (should succeed)
|
||||
bool valid_ok = true;
|
||||
valid_ok &= testRankingConstructor(1.1, 1.0); // Valid pressure
|
||||
valid_ok &= testRankingCachedConstructor(1.1, 1.0); // Valid pressure
|
||||
|
||||
// Test invalid parameters (should fail)
|
||||
bool invalid_ok = true;
|
||||
invalid_ok &= !testRankingConstructor(1.0, 1.0); // pressure = 1 (invalid)
|
||||
invalid_ok &= !testRankingConstructor(0.5, 1.0); // pressure < 1 (invalid)
|
||||
invalid_ok &= !testRankingConstructor(2.1, 1.0); // pressure > 2 (invalid)
|
||||
invalid_ok &= !testRankingCachedConstructor(1.0, 1.0); // pressure = 1 (invalid)
|
||||
invalid_ok &= !testRankingCachedConstructor(0.5, 1.0); // pressure < 1 (invalid)
|
||||
invalid_ok &= !testRankingCachedConstructor(2.1, 1.0); // pressure > 2 (invalid)
|
||||
|
||||
if (!valid_ok)
|
||||
{
|
||||
throw std::runtime_error("Valid parameter tests failed");
|
||||
}
|
||||
|
||||
if (!invalid_ok)
|
||||
{
|
||||
throw std::runtime_error("Invalid parameter tests failed - some invalid values were accepted");
|
||||
}
|
||||
|
||||
std::clog << "Test 4 passed: All parameter assertions working correctly\n";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv);
|
||||
test_Consistency(parser);
|
||||
test_MinPopulationSize(parser);
|
||||
test_CachingEffectiveness(parser);
|
||||
// test_Assertions(parser);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
std::clog << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
eoIntInterval bounds(1,5);
|
||||
|
||||
using Chrom = eoInt<double>;
|
||||
using MutWrapper = eoRealToIntMonOp<Chrom>;
|
||||
|
||||
eoDetUniformMutation< typename MutWrapper::EOTreal > mutreal(/*range*/6, /*nb*/5);
|
||||
|
||||
MutWrapper mutint(mutreal, bounds);
|
||||
|
||||
Chrom sol({1,2,3,4,5});
|
||||
|
||||
bool changed = mutint(sol);
|
||||
assert(changed);
|
||||
|
||||
for(auto& x : sol) {
|
||||
assert(bounds.isInBounds(x));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
eoIntInterval intbounds(1,5);
|
||||
eoRealInterval rb(1,5);
|
||||
eoRealVectorBounds realbounds(5, rb);
|
||||
|
||||
using Chrom = eoInt<double>;
|
||||
using CrossWrapper = eoRealToIntQuadOp<Chrom>;
|
||||
|
||||
eoSegmentCrossover< typename CrossWrapper::EOTreal > crossreal(realbounds, /*alpha*/0);
|
||||
|
||||
CrossWrapper crossint(crossreal, intbounds);
|
||||
|
||||
Chrom sol1({1,2,3,4,5});
|
||||
Chrom sol2({1,2,3,4,5});
|
||||
|
||||
bool changed = crossint(sol1, sol2);
|
||||
assert(changed);
|
||||
|
||||
for(auto& x : sol1) {
|
||||
assert(intbounds.isInBounds(x));
|
||||
}
|
||||
for(auto& x : sol2) {
|
||||
assert(intbounds.isInBounds(x));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
}
|
||||
|
||||
// hard-coded directory name ...
|
||||
(void) system("mkdir ResSelect");
|
||||
system("mkdir ResSelect");
|
||||
std::cout << "Testing the Selections\nParents size = " << pSize
|
||||
<< ", offspring rate = " << oRate;
|
||||
std::cout << " and putting rsulting files in dir ResSelect" << std::endl;
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
std::cout << "The resulting file (in dir ResSelect), contains \n";
|
||||
std::cout << " the empirical proba. for each indi to be selected." << std::endl;
|
||||
(void) system("mkdir ResSelect");
|
||||
system("mkdir ResSelect");
|
||||
|
||||
// initialize parent population
|
||||
parentsOrg.resize(pSize);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ struct Dummy : public EO<double>
|
|||
int the_main(int argc, char **argv)
|
||||
{ // ok, we have a command line parser and a state
|
||||
|
||||
typedef eoBit<float> Chrom;
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// Define Parameters
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
eoBooleanGenerator gen(0.5);
|
||||
eoInitFixedLength<EOT> init(dim, gen);
|
||||
|
||||
eoGenContinue<EOT> common_cont(5);
|
||||
eoGenContinue<EOT> common_cont(100);
|
||||
|
||||
eoForgeVector< eoContinue<EOT> > continuators;
|
||||
continuators.add< eoSteadyFitContinue<EOT> >(10,10);
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
Bootstrap: docker
|
||||
From: ubuntu:24.04
|
||||
|
||||
%post
|
||||
# Update the available packages list.
|
||||
apt -y update
|
||||
# And add the "universe" repository (allow to install many more software).
|
||||
apt -y install software-properties-common
|
||||
add-apt-repository universe
|
||||
apt -y update
|
||||
# Update the operating systems (install last versions with bugfixes).
|
||||
apt -y dist-upgrade
|
||||
|
||||
# Install dependencies for your project.
|
||||
apt -y install git g++ cmake ccache make libeigen3-dev libopenmpi-dev doxygen graphviz libgnuplot-iostream-dev
|
||||
|
||||
# Download sources.
|
||||
git clone --branch master --single-branch --recurse-submodules https://github.com/nojhan/paradiseo
|
||||
cd paradiseo
|
||||
|
||||
# Build directory that holds built binaries and cache.
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
# Example of minimum build:
|
||||
# Use that if you want the minimal set of libraries needed to build a simple solver.
|
||||
# cmake -DCMAKE_BUILD_TYPE=Release -DEDO=ON .. && make
|
||||
|
||||
# Example of trying to build everything:
|
||||
# Use that to test if everything can be built with your setup,
|
||||
# or if you modified something in Paradiseo and want to test it.
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DEDO=ON -DENABLE_CMAKE_EXAMPLE=ON -DENABLE_CMAKE_TESTING=ON -DENABLE_GNUPLOT=ON -DENABLE_OPENMP=ON -DMPI=ON -DSMP=ON .. && make
|
||||
|
||||
# You may run the tests, to check if everything works:
|
||||
ctest
|
||||
|
||||
# Make the documentation:
|
||||
make doc
|
||||
|
||||
# Clean-up of the APT cache (will lighten the container).
|
||||
apt -y purge software-properties-common git g++ cmake ccache make libeigen3-dev libopenmpi-dev doxygen graphviz libgnuplot-iostream-dev
|
||||
apt -y --purge autoremove
|
||||
apt -y autoclean
|
||||
apt clean
|
||||
|
||||
%environment
|
||||
|
||||
%runscript
|
||||
# When executing the container, this will be called,
|
||||
# and pass all the command line arguments.
|
||||
./paradiseo/build/edo/application/cmaes/cmaes $*
|
||||
|
||||
%labels
|
||||
Author Johann Dreo
|
||||
|
|
@ -79,20 +79,6 @@ public:
|
|||
explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Constructor without cooling schedule, but with a continuator.
|
||||
*
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _fullEval the full evaluation function
|
||||
* @param _eval neighbor's evaluation function
|
||||
* @param _cont an external continuator
|
||||
*/
|
||||
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||
defaultCool(0, 0, 0, 0),
|
||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool)
|
||||
{}
|
||||
|
||||
/**
|
||||
* General constructor for a simulated annealing
|
||||
* @param _neighborhood the neighborhood
|
||||
|
|
|
|||
|
|
@ -54,11 +54,7 @@ public:
|
|||
* @param _maxFullEval number maximum of iterations
|
||||
* @param _restartCounter if true the counter of number of evaluations restarts to "zero" at initialization, if false, the number is cumulative
|
||||
*/
|
||||
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval, bool _restartCounter = true):
|
||||
eval(_eval),
|
||||
restartCounter(_restartCounter),
|
||||
maxFullEval(_maxFullEval)
|
||||
{
|
||||
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval, bool _restartCounter = true): eval(_eval), maxFullEval(_maxFullEval), restartCounter(_restartCounter) {
|
||||
nbEval_start = eval.value();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ public :
|
|||
|
||||
if (nb > 1) {
|
||||
sd = 0;
|
||||
for(unsigned i = 0; i < nb; i++)
|
||||
for(int i = 0; i < nb; i++)
|
||||
sd += (neighborFitness[i] - mean) * (neighborFitness[i] - mean) ;
|
||||
sd = sqrt( sd / (nb - 1.0) ); // becareful: could be infinite when large values
|
||||
//sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); // becareful: could be negative due to approximation of large values
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public :
|
|||
* Set the first and the third quartile of fitness in the neighborhood
|
||||
* @param _sol the first solution
|
||||
*/
|
||||
virtual void init(EOT & /*_sol*/) {
|
||||
virtual void init(EOT & _sol) {
|
||||
value().first = nhStat.getQ1();
|
||||
value().second = nhStat.getQ3();
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ public :
|
|||
* Set the first and the third quartile fitness in the neighborhood
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & /*_sol*/) {
|
||||
virtual void operator()(EOT & _sol) {
|
||||
value().first = nhStat.getQ1();
|
||||
value().second = nhStat.getQ3();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,10 +184,6 @@
|
|||
#include <problems/permutation/moTwoOptExNeighbor.h>
|
||||
#include <problems/permutation/moTwoOptExNeighborhood.h>
|
||||
|
||||
#include <problems/partition/moBinaryPartition.h>
|
||||
#include <problems/partition/moBinaryPartitionSwapNeighbor.h>
|
||||
#include <problems/partition/moBinaryPartitionSwapNeighborhood.h>
|
||||
|
||||
//#include <problems/eval/moMaxSATincrEval.h>
|
||||
//#include <problems/eval/moOneMaxIncrEval.h>
|
||||
//#include <problems/eval/moQAPIncrEval.h>
|
||||
|
|
@ -197,6 +193,7 @@
|
|||
//#include <problems/eval/moUBQPBitsIncrEval.h>
|
||||
//#include <problems/eval/moNKlandscapesIncrEval.h>
|
||||
|
||||
|
||||
#include <sampling/moAdaptiveWalkSampling.h>
|
||||
#include <sampling/moAutocorrelationSampling.h>
|
||||
#include <sampling/moDensityOfStatesSampling.h>
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public:
|
|||
* @param _neighbor the neighbor to assign
|
||||
* @return a neighbor equal to the other
|
||||
*/
|
||||
moNeighbor<EOT, Fitness>& operator=(
|
||||
virtual moNeighbor<EOT, Fitness>& operator=(
|
||||
const moNeighbor<EOT, Fitness>& _neighbor) {
|
||||
if (!(_neighbor.invalid()))
|
||||
fitness(_neighbor.fitness());
|
||||
|
|
@ -93,7 +93,7 @@ public:
|
|||
* @param _neighbor a neighbor
|
||||
* @return if _neighbor and this one are equals
|
||||
*/
|
||||
bool equals(moNeighbor<EOT, Fitness> & /*_neighbor*/) {
|
||||
virtual bool equals(moNeighbor<EOT, Fitness> & /*_neighbor*/) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public:
|
|||
/**
|
||||
* Default constructor with first search heuristics
|
||||
*
|
||||
* @param _firstLS first local search
|
||||
* @param _firstLS first local search
|
||||
* @param _firstShake first heuristic which perturbs the solution
|
||||
* @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop.
|
||||
*/
|
||||
|
|
@ -67,7 +67,7 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* test if there is still some heuristics
|
||||
* test if there is still some heuristics
|
||||
*
|
||||
* @param _solution the current solution
|
||||
* @return true if there is some heuristics
|
||||
|
|
@ -83,17 +83,11 @@ public:
|
|||
*/
|
||||
virtual void init(EOT& /*_solution*/) {
|
||||
if(order.size() == 0)
|
||||
for(unsigned int i = 0; i < LSvector.size(); i++) {
|
||||
order.push_back(i); }
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::shuffle(order.begin(), order.end(), gen);
|
||||
#else
|
||||
for(unsigned int i = 0; i < LSvector.size(); i++)
|
||||
order.push_back(i);
|
||||
|
||||
UF_random_generator<unsigned int> gen(order.size());
|
||||
std::random_shuffle(order.begin(), order.end(), gen);
|
||||
#endif
|
||||
|
||||
currentOrder = 0;
|
||||
current = order[currentOrder];
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ private:
|
|||
nonSig = 0;
|
||||
|
||||
unsigned int n = 1;
|
||||
for(unsigned j = 0; j < nk.K + 1; j++) {
|
||||
for(int j = 0; j < nk.K + 1; j++) {
|
||||
if (_solution[ nk.links[i][j] ] == 1)
|
||||
sig = sig | n;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,218 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <eo>
|
||||
|
||||
/** A partition of a binary space.
|
||||
*
|
||||
* This data structure defines a grouping of the elements of a multi-dimensional
|
||||
* set in a space of boolean numbers.
|
||||
* \f[
|
||||
* \mathrm{1}^n = \bigcup_{i=1}^n \{0,1\}_i
|
||||
* \f]
|
||||
* Elements of the set may be either "selected" (in the set S) or "rejected" (in the set R).
|
||||
* \f[
|
||||
* (S \in \mathrm{1}^m) \cup (R \in \mathrm{1}^k) \in \mathrm{1}^n,\; n=m+k
|
||||
* \f]
|
||||
* Elements are referred to by their index in the set (hereby named "atoms").
|
||||
*
|
||||
* This representation is useful if your problem can be defined has selecting
|
||||
* a subset of elements that optimize some objective function.
|
||||
*
|
||||
* The core data structures are two ordered sets of unique atoms,
|
||||
* the union of which is guaranteed to have the correct dimension.
|
||||
*/
|
||||
template<class FitT>
|
||||
class moBinaryPartition : public EO<FitT>
|
||||
{
|
||||
public:
|
||||
/** The type for indices. */
|
||||
using AtomType = size_t;
|
||||
|
||||
/** The data structures holding the indices. */
|
||||
using ContainerType = std::set<AtomType>;
|
||||
|
||||
/** The set of selected atoms. */
|
||||
ContainerType selected;
|
||||
|
||||
/** The set of not-selected atoms. */
|
||||
ContainerType rejected;
|
||||
|
||||
/** Consistent constructor
|
||||
*
|
||||
* Put all `total_nb_atoms` indices in the @ref rejected set.
|
||||
* Indices starts at zero and fill the set in increasing order.
|
||||
*
|
||||
* @param total_nb_atoms Total number of possible atoms from whith to select.
|
||||
*/
|
||||
moBinaryPartition( const size_t total_nb_atoms )
|
||||
{
|
||||
// Fill the rejected list with all possible gene indices,
|
||||
// starting from zero.
|
||||
for(size_t i = 0; i < total_nb_atoms; ++i) {
|
||||
rejected.insert(i);
|
||||
}
|
||||
// None selected.
|
||||
}
|
||||
|
||||
/** Empty constructor
|
||||
*
|
||||
* Do not fill the @ref rejected set.
|
||||
* You are responsible for making it consistent after instantiation.
|
||||
*
|
||||
* @warning If you do not fill at least the @ref rejected set,
|
||||
* errors will be raised when trying to @ref select or @ref reject.
|
||||
*/
|
||||
moBinaryPartition()
|
||||
{ }
|
||||
|
||||
/** Move one atom in the @ref selected set.
|
||||
*
|
||||
* That is: erase the atom from @ref rejected,
|
||||
* insert it in @ref selected.
|
||||
*
|
||||
* @note In debug mode, double check that elements were actually moved.
|
||||
*/
|
||||
void select(const size_t atom) {
|
||||
#if __cplusplus >= 202002L
|
||||
assert(not selected.contains(atom));
|
||||
#else
|
||||
assert(selected.count(atom) == 0);
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
size_t has_erased =
|
||||
#endif
|
||||
this->rejected.erase(atom);
|
||||
assert(has_erased == 1);
|
||||
|
||||
#ifndef NDEBUG
|
||||
auto [where, has_inserted] =
|
||||
#endif
|
||||
this->selected.insert(atom);
|
||||
assert(has_inserted);
|
||||
}
|
||||
|
||||
/** Move one atom in the @ref rejected set.
|
||||
*
|
||||
* That is: insert the atom in @ref rejected,
|
||||
* erase it from @ref selected.
|
||||
*
|
||||
* @note In debug mode, double check that elements were actually moved.
|
||||
*/
|
||||
void reject(const size_t atom) {
|
||||
#if __cplusplus >= 202002L
|
||||
assert(not rejected.contains(atom));
|
||||
#else
|
||||
assert(rejected.count(atom) == 0);
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
size_t has_erased =
|
||||
#endif
|
||||
this->selected.erase(atom);
|
||||
assert(has_erased == 1);
|
||||
|
||||
#ifndef NDEBUG
|
||||
auto [where, has_inserted] =
|
||||
#endif
|
||||
this->rejected.insert(atom);
|
||||
assert(has_inserted);
|
||||
}
|
||||
|
||||
/** Serialization of the `selected`.
|
||||
*
|
||||
* Output a string of the form (spaces replaced with period here, to show their count):
|
||||
* `<fitness>..<nb_selected>..<sel_0>…<sel_n>`
|
||||
*/
|
||||
virtual void printSelectedOn(std::ostream& out) const
|
||||
{
|
||||
EO<FitT>::printOn(out); // Fitness.
|
||||
// Trailing space already inserted.
|
||||
out << " " << selected.size() << " "; // Size.
|
||||
std::copy(std::begin(selected), std::end(selected),
|
||||
std::ostream_iterator<AtomType>(out, " ")); // Values.
|
||||
}
|
||||
|
||||
//! Convenience function to only render the fitness and the selected atoms (and not the rejected ones).
|
||||
std::string str() const
|
||||
{
|
||||
std::ostringstream msg;
|
||||
this->printSelectedOn(msg);
|
||||
return msg.str();
|
||||
}
|
||||
|
||||
/** Serialization of the `selected` and `rejected` atoms.
|
||||
*
|
||||
* Output a string of the form (spaces replaced with period here, to show their count):
|
||||
* `<fitness>..<nb_selected>..<sel_0>…<sel_n>...<nb_rejected>..<rej_0>…<rej_m>`
|
||||
*/
|
||||
virtual void printOn(std::ostream& out) const override
|
||||
{
|
||||
this->printSelectedOn(out);
|
||||
// Printing the rejected atom should not be necessary,
|
||||
// as this is the complementary set of the selected.
|
||||
// out << " ";
|
||||
// out << rejected.size() << " "; // Size.
|
||||
// std::copy(std::begin(rejected), std::end(rejected),
|
||||
// std::ostream_iterator<AtomType>(out, " ")); // Values.
|
||||
}
|
||||
|
||||
/** Deserialization of the `selected` and `rejected` atoms.
|
||||
*
|
||||
* Expects a string of the form (spaces replaced with period here, to show their count):
|
||||
* `<fitness>..<nb_selected>..<sel_0>…<sel_n>...<nb_rejected>..<rej_0>…<rej_m>`
|
||||
*/
|
||||
virtual void readFrom(std::istream& in) override
|
||||
{
|
||||
EO<FitT>::readFrom(in); // Fitness.
|
||||
unsigned size;
|
||||
in >> size; // Size.
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
AtomType atom;
|
||||
in >> atom; // Value.
|
||||
selected.insert(atom);
|
||||
}
|
||||
assert(selected.size() == size);
|
||||
in >> size; // Size.
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
AtomType atom;
|
||||
in >> atom; // Value.
|
||||
rejected.insert(atom);
|
||||
}
|
||||
assert(rejected.size() == size);
|
||||
}
|
||||
|
||||
/** Returns true if all sets are equals. */
|
||||
bool operator==(const moBinaryPartition& other) {
|
||||
return this->selected == other.selected
|
||||
and this->rejected == other.rejected;
|
||||
}
|
||||
|
||||
//! Class name for state management.
|
||||
virtual std::string className() const override
|
||||
{
|
||||
return "moBinaryPartition";
|
||||
}
|
||||
|
||||
// //! Accessor to set fitness.
|
||||
// virtual void fitness(const FitT& fit) override
|
||||
// {
|
||||
// // std::clog << "Fitness assignment -- solution: " << *this << " gets fitness: " << fit << std::endl;
|
||||
// EO<FitT>::fitness(fit);
|
||||
// }
|
||||
|
||||
// //! Accessor to get fitness.
|
||||
// virtual const FitT& fitness() const override
|
||||
// {
|
||||
// return EO<FitT>::fitness();
|
||||
// }
|
||||
|
||||
// //! Accessor to invalidate fitness.
|
||||
// virtual void invalidate() override
|
||||
// {
|
||||
// // this->fitness().clear();
|
||||
// EO<FitT>::invalidate();
|
||||
// }
|
||||
};
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <mo>
|
||||
#include "moBinaryPartition.h"
|
||||
|
||||
/** Stable neighbor for a binary partition.
|
||||
*
|
||||
* Models how to move from a solution to a neighbor,
|
||||
* by swaping one selected atom for one rejected atom.
|
||||
* The number of selected atoms is thus guaranteed to be stable.
|
||||
*
|
||||
* The core data structure is two atoms:
|
||||
* - the selected one,
|
||||
* - the rejected one.
|
||||
*/
|
||||
template<class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moBinaryPartitionSwapNeighbor :
|
||||
public moBackableNeighbor<EOT,Fitness>//,
|
||||
// public moIndexNeighbor<EOT,double> // FIXME see if we can model that.
|
||||
{
|
||||
public:
|
||||
/** Shortcut for Atom’s type. */
|
||||
using AtomType = typename EOT::AtomType;
|
||||
|
||||
/** Shortcut for container’s type. */
|
||||
using ContainerType = typename EOT::ContainerType;
|
||||
|
||||
/** Shortcut for fitness. */
|
||||
using moBackableNeighbor<EOT, Fitness>::fitness;
|
||||
|
||||
// using moIndexNeighbor<EOT, Fitness>::key;
|
||||
// using moIndexNeighbor<EOT, Fitness>::index;
|
||||
|
||||
/** Consistent constructor.
|
||||
*
|
||||
* Will ensure that the dimension of the partition does not change.
|
||||
*
|
||||
* @param _selected_nb Number of selected atoms to maintain.
|
||||
*/
|
||||
moBinaryPartitionSwapNeighbor( const size_t _selected_nb ) :
|
||||
selected_nb(_selected_nb)
|
||||
#ifndef NDEBUG
|
||||
, is_set(false)
|
||||
#endif
|
||||
{
|
||||
assert(selected_nb > 0);
|
||||
}
|
||||
|
||||
/** Default constructor.
|
||||
*
|
||||
* Will NOT ensure that the dimension of the partition does not change.
|
||||
*/
|
||||
moBinaryPartitionSwapNeighbor() :
|
||||
selected_nb(0)
|
||||
#ifndef NDEBUG
|
||||
, is_set(false)
|
||||
#endif
|
||||
{
|
||||
// Invalid fitness by default.
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
*/
|
||||
moBinaryPartitionSwapNeighbor( const moBinaryPartitionSwapNeighbor<EOT>& other) :
|
||||
selected_nb(other.selected_nb),
|
||||
select(other.select),
|
||||
reject(other.reject)
|
||||
#ifndef NDEBUG
|
||||
, is_set(other.is_set)
|
||||
#endif
|
||||
{
|
||||
this->fitness(other.fitness());
|
||||
}
|
||||
|
||||
/** Default assignment operator.
|
||||
*/
|
||||
moBinaryPartitionSwapNeighbor<EOT>& operator=(
|
||||
const moBinaryPartitionSwapNeighbor<EOT>& other)
|
||||
{
|
||||
this->selected_nb = other.selected_nb;
|
||||
this->select = other.select;
|
||||
this->reject = other.reject;
|
||||
#ifndef NDEBUG
|
||||
this->is_set = other.is_set;
|
||||
#endif
|
||||
this->fitness(other.fitness());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Apply the currently stored move.
|
||||
*
|
||||
* That is: reject one atom and select one other.
|
||||
*/
|
||||
virtual void move(EOT& solution) override {
|
||||
assert(is_set);
|
||||
// Swap the two atoms.
|
||||
solution.reject(this->reject);
|
||||
solution.select(this->select);
|
||||
assert(solution.selected.size() == this->selected_nb);
|
||||
// this->fitness( Fitness(solution.fitness()) ); // For the cache.
|
||||
solution.invalidate();
|
||||
}
|
||||
|
||||
/** Apply the opposite of the currently stored move.
|
||||
*
|
||||
* That is: reject the selected atom, and select the rejected one.
|
||||
*/
|
||||
virtual void moveBack(EOT& solution) override {
|
||||
assert(is_set);
|
||||
solution.reject(this->select);
|
||||
solution.select(this->reject);
|
||||
assert(solution.selected.size() == this->selected_nb);
|
||||
// this->fitness( Fitness(solution.fitness()) ); // For the cache.
|
||||
solution.invalidate();
|
||||
}
|
||||
|
||||
/** Set the considered atoms.
|
||||
*
|
||||
* @param in The selected atom.
|
||||
* @param out The rejected atom.
|
||||
*/
|
||||
void set(AtomType in, AtomType out) {
|
||||
this->select = in;
|
||||
this->reject = out;
|
||||
#ifndef NDEBUG
|
||||
is_set = true;
|
||||
#endif
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
/** Set the considered atoms.
|
||||
*
|
||||
* @param in_out A pair of {selected,rejected} atoms.
|
||||
*/
|
||||
void set(std::pair<AtomType,AtomType> in_out) {
|
||||
this->set(in_out.first, in_out.second);
|
||||
}
|
||||
|
||||
/** Get the considered atom.
|
||||
*
|
||||
* @returns A pair of atoms, the first being the selected atom, the second being the rejected one.
|
||||
*/
|
||||
std::pair<AtomType,AtomType> get() {
|
||||
assert(is_set);
|
||||
return std::make_pair(select, reject);
|
||||
}
|
||||
|
||||
/** Returns true if this neighbor has the same selected & rejected atoms than the given neighbor. */
|
||||
virtual bool equals(moBinaryPartitionSwapNeighbor<EOT,Fitness>& neighbor) {
|
||||
auto [in, out] = neighbor.get();
|
||||
return this->select == in and this->reject == out;
|
||||
}
|
||||
private:
|
||||
// Disable access to `equals(moNeighbor<…>&)` (removes the related overloaded-virtual warning).
|
||||
using moBackableNeighbor<EOT,Fitness>::equals;
|
||||
|
||||
public:
|
||||
|
||||
//! Class name for state management.
|
||||
virtual std::string className() const override {
|
||||
return "moBinaryPartitionSwapNeighbor";
|
||||
}
|
||||
|
||||
/** Fancy print. */
|
||||
virtual void printOn(std::ostream& out) const override {
|
||||
assert(is_set);
|
||||
EO<Fitness>::printOn(out); // Fitness.
|
||||
out << " "
|
||||
<< selected_nb
|
||||
<< " -" << reject
|
||||
<< " +" << select;
|
||||
}
|
||||
|
||||
//! Accessor to set the size.
|
||||
void size(size_t _selected_nb) {
|
||||
assert(_selected_nb > 0);
|
||||
this->selected_nb = _selected_nb;
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
//! Accessor to get the size.
|
||||
size_t size() const {
|
||||
return this->selected_nb;
|
||||
}
|
||||
|
||||
// virtual void fitness(const Fitness& fit) override
|
||||
// {
|
||||
// // std::clog << "Fitness assignment -- neighbor: " << *this << " gets fitness: " << fit << std::endl;
|
||||
// EO<Fitness>::fitness(fit);
|
||||
// }
|
||||
|
||||
// virtual const Fitness& fitness() const override
|
||||
// {
|
||||
// return EO<Fitness>::fitness();
|
||||
// }
|
||||
|
||||
#ifndef NDEBUG
|
||||
public:
|
||||
#else
|
||||
protected:
|
||||
#endif
|
||||
/** Fixed dimension of the handled solutions. */
|
||||
size_t selected_nb;
|
||||
|
||||
/** Selected atom. */
|
||||
AtomType select;
|
||||
|
||||
/** Rejected atom. */
|
||||
AtomType reject;
|
||||
|
||||
#ifndef NDEBUG
|
||||
/** Sanity flag.
|
||||
*
|
||||
* Used in debug builds to ensure that the neighbor
|
||||
* have been set before being used.
|
||||
*/
|
||||
bool is_set;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <mo>
|
||||
#include "moBinaryPartition.h"
|
||||
|
||||
/** Stable neighborhood for binary partitions.
|
||||
*
|
||||
* This generates all neighbors of a binary partition
|
||||
* that have the same dimension than the considered solution.
|
||||
* I.e. it enumerates all the swaps of two atoms
|
||||
* between the selected and rejected sets.
|
||||
*
|
||||
* The core data structure is two indices:
|
||||
* - one for the position within the selected set of a binary partition,
|
||||
* - the other for the position within the rejected set.
|
||||
*
|
||||
* The neighborhood is defined as enumerating the neighbors,
|
||||
* first by going over the rejected atoms (outer loop),
|
||||
* then by iterating over the selected atoms (inner loop).
|
||||
*/
|
||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moBinaryPartitionSwapNeighborhood : public moNeighborhood<moBinaryPartitionSwapNeighbor<EOT, Fitness> >
|
||||
{
|
||||
public:
|
||||
/** Shortcut for neighbor's type. */
|
||||
using Neighbor = moBinaryPartitionSwapNeighbor<EOT, Fitness>;
|
||||
|
||||
/** Shortcut for Atom’s type. */
|
||||
using AtomType = typename EOT::AtomType;
|
||||
|
||||
/** Get the currently pointed selected atom. */
|
||||
AtomType selected(EOT& from, const size_t i_select) const {
|
||||
typename EOT::ContainerType::iterator
|
||||
it = std::begin(from.rejected);
|
||||
std::advance(it, i_select);
|
||||
return *it;
|
||||
}
|
||||
|
||||
/** Get the currently pointed rejected atom. */
|
||||
AtomType rejected(EOT& from, const size_t j_reject) const {
|
||||
typename EOT::ContainerType::iterator
|
||||
it = std::begin(from.selected);
|
||||
std::advance(it, j_reject);
|
||||
return *it;
|
||||
}
|
||||
|
||||
/** Initialize the neighborhood.
|
||||
*
|
||||
* This actually make the neighborhood point to the first possible swap:
|
||||
* between the first selected atom and the first rejected atom.
|
||||
*/
|
||||
virtual void init(EOT& from, Neighbor& to) override {
|
||||
i_select = 0;
|
||||
j_reject = 0;
|
||||
|
||||
// std::clog << "Init neighborhood:"
|
||||
// << " outer:" << j_reject+1 << "/" << from.selected.size() << ","
|
||||
// << " inner:" << i_select+1 << "/" << from.rejected.size() << " ="
|
||||
// << " -" << rejected(from, j_reject)
|
||||
// << " +" << selected(from, i_select)
|
||||
// << " from: " << from
|
||||
// << std::endl;
|
||||
|
||||
// First item in both lists.
|
||||
AtomType in = selected(from, i_select);
|
||||
AtomType out = rejected(from, j_reject);
|
||||
to.set(in, out);
|
||||
to.size(from.selected.size());
|
||||
to.invalidate();
|
||||
}
|
||||
|
||||
/** Point to the next neighbor. */
|
||||
virtual void next(EOT& from, Neighbor& to) override {
|
||||
// If last item of the inner loop.
|
||||
if( i_select == from.rejected.size()-1 ) {
|
||||
i_select = 0; // Reset inner loop.
|
||||
j_reject++; // Next outer loop.
|
||||
} else {
|
||||
i_select++; // Next inner loop.
|
||||
}
|
||||
|
||||
// std::clog << "Next in neighborhood:"
|
||||
// << " -" << rejected(from, j_reject)
|
||||
// << " +" << selected(from, i_select)
|
||||
// << " from: " << from
|
||||
// << std::endl;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
assert( from.rejected.contains(selected(from,i_select)) );
|
||||
assert( from.selected.contains(rejected(from,j_reject)) );
|
||||
#else
|
||||
assert( from.rejected.count(selected(from,i_select)) > 0 );
|
||||
assert( from.selected.count(rejected(from,j_reject)) > 0 );
|
||||
#endif
|
||||
assert( selected(from,i_select) != rejected(from,j_reject) );
|
||||
|
||||
// Implant this move in the neighbor.
|
||||
to.set(
|
||||
selected(from, i_select),
|
||||
rejected(from, j_reject)
|
||||
);
|
||||
to.size(from.selected.size());
|
||||
to.invalidate();
|
||||
}
|
||||
|
||||
/** Returns true if there is more neighbors to be enumerated. */
|
||||
virtual bool cont(EOT& from) override {
|
||||
// std::clog << "cont neighborhood?"
|
||||
// << " outer:" << j_reject+1 << "/" << from.selected.size() << ","
|
||||
// << " inner:" << i_select+1 << "/" << from.rejected.size()// << " ="
|
||||
// // << " -" << rejected(from, j_reject)
|
||||
// // << " +" << selected(from, i_select)
|
||||
// << " from: " << from
|
||||
// << std::endl;
|
||||
|
||||
// If reached the last item of the outer loop.
|
||||
if( i_select == from.rejected.size()-1
|
||||
and j_reject == from.selected.size()-1) {
|
||||
// We should also have reached the end of the inner loop,
|
||||
// and have set the inner loop to zero.
|
||||
// std::clog << "\tnope" << std::endl;
|
||||
return false;
|
||||
|
||||
} else { // There is still some items in the outer loop.
|
||||
// and thus also in the inner loop.
|
||||
// std::clog << "\tyes" << std::endl;
|
||||
assert( j_reject < from.selected.size() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns true if there is actual neighbors in the neighborhood.
|
||||
*
|
||||
* Essentially just tells if the rejected set is not empty.
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& solution) override {
|
||||
return solution.rejected.size() > 0;
|
||||
}
|
||||
|
||||
//! Class name for state management.
|
||||
virtual std::string className() const override {
|
||||
return "moBinaryPartitionSwapNeighborhood";
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
public:
|
||||
#else
|
||||
protected:
|
||||
#endif
|
||||
/** Index of the currently pointed selected atom. */
|
||||
size_t i_select;
|
||||
|
||||
/** Index of the currently pointed rejected atom. */
|
||||
size_t j_reject;
|
||||
};
|
||||
|
|
@ -84,10 +84,10 @@ public:
|
|||
moEval<Neighbor>& _eval,
|
||||
unsigned int _nbAdaptWalk) :
|
||||
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
|
||||
neighborEvalCount(_eval),
|
||||
nEvalStat(neighborEvalCount, true),
|
||||
copyEvalStat(nEvalStat),
|
||||
neighborEvalCount(_eval),
|
||||
nEvalStat(neighborEvalCount, true),
|
||||
copyStat(lengthStat), // copy is used to report the statistic of the first walk
|
||||
copyEvalStat(nEvalStat),
|
||||
checkpoint(trueCont),
|
||||
hc(_neighborhood, _fullEval, neighborEvalCount, checkpoint),
|
||||
initHC(_init, hc)
|
||||
|
|
@ -95,15 +95,15 @@ public:
|
|||
// to count the number of step in the HC
|
||||
checkpoint.add(lengthStat);
|
||||
|
||||
// set the long name of this statistic which is the length of the walk
|
||||
copyStat.setLongName("length");
|
||||
// set the long name of this statistic which is the length of the walk
|
||||
copyStat.setLongName("length");
|
||||
|
||||
// to count the number of evaluations
|
||||
// to count the number of evaluations
|
||||
checkpoint.add(nEvalStat);
|
||||
|
||||
// set the long name of this statistic which is the number of neighbor evaluation
|
||||
copyEvalStat.setLongName("ngheval");
|
||||
|
||||
// set the long name of this statistic which is the number of neighbor evaluation
|
||||
copyEvalStat.setLongName("ngheval");
|
||||
|
||||
// add the solution into statistics
|
||||
this->add(copyEvalStat);
|
||||
this->add(solStat);
|
||||
|
|
@ -118,10 +118,10 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
/* count the number of evaluations */
|
||||
moEvalCounter<Neighbor> neighborEvalCount;
|
||||
moValueStat<EOT, unsigned long> nEvalStat;
|
||||
moStatFromStat<EOT, double> copyEvalStat;
|
||||
/* count the number of evaluations */
|
||||
moEvalCounter<Neighbor> neighborEvalCount;
|
||||
moValueStat<EOT, unsigned long> nEvalStat;
|
||||
moStatFromStat<EOT, double> copyEvalStat;
|
||||
|
||||
moSolutionStat<EOT> solStat;
|
||||
moMinusOneCounterStat<EOT> lengthStat;
|
||||
|
|
|
|||
|
|
@ -192,9 +192,9 @@ protected:
|
|||
moSolutionStat<EOT> solutionStat;
|
||||
moDistanceStat<EOT> distStat;
|
||||
moNeighborhoodStat< Neighbor > neighborhoodStat;
|
||||
moMinNeighborStat< Neighbor > minStat;
|
||||
moAverageFitnessNeighborStat< Neighbor > averageStat;
|
||||
moStdFitnessNeighborStat< Neighbor > stdStat;
|
||||
moMinNeighborStat< Neighbor > minStat;
|
||||
moMaxNeighborStat< Neighbor > maxStat;
|
||||
moNbSupNeighborStat< Neighbor > nbSupStat;
|
||||
moNbInfNeighborStat< Neighbor > nbInfStat;
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ set (TEST_LIST
|
|||
t-moIndexedVectorTabuList
|
||||
# t-moRndIndexedVectorTabuList
|
||||
t-moDynSpanCoolingSchedule
|
||||
t-moBinaryPartition
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
|
|
@ -71,15 +71,15 @@ typedef EO<int> Solution;
|
|||
|
||||
class moDummyNeighborTest: public moNeighbor<Solution> {
|
||||
public:
|
||||
virtual void move(Solution & /*_solution*/) {
|
||||
virtual void move(Solution & _solution) {
|
||||
}
|
||||
};
|
||||
|
||||
class moDummyBackableNeighbor: public moBackableNeighbor<Solution> {
|
||||
public:
|
||||
virtual void move(Solution & /*_solution*/) {
|
||||
virtual void move(Solution & _solution) {
|
||||
}
|
||||
virtual void moveBack(Solution & /*_solution*/) {
|
||||
virtual void moveBack(Solution & _solution) {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ public:
|
|||
i(0), j(0) {
|
||||
}
|
||||
|
||||
virtual bool hasNeighbor(EOT & /*_solution*/) {
|
||||
virtual bool hasNeighbor(EOT & _solution) {
|
||||
bool res;
|
||||
if (i % 3 == 0 || i == 1)
|
||||
res = false;
|
||||
|
|
@ -100,11 +100,11 @@ public:
|
|||
i++;
|
||||
return res;
|
||||
}
|
||||
virtual void init(EOT & /*_solution*/, Neighbor & /*_current*/) {
|
||||
virtual void init(EOT & _solution, Neighbor & _current) {
|
||||
}
|
||||
virtual void next(EOT & /*_solution*/, Neighbor & /*_current*/) {
|
||||
virtual void next(EOT & _solution, Neighbor & _current) {
|
||||
}
|
||||
virtual bool cont(EOT & /*_solution*/) {
|
||||
virtual bool cont(EOT & _solution) {
|
||||
j++;
|
||||
return (j % 10 != 0);
|
||||
}
|
||||
|
|
@ -227,7 +227,7 @@ private:
|
|||
|
||||
class dummyInit: public eoInit<bitVector> {
|
||||
public:
|
||||
void operator()(bitVector& /*sol*/) {
|
||||
void operator()(bitVector& sol) {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
|
||||
#include <mo>
|
||||
|
||||
int main()
|
||||
{
|
||||
using Signature = moBinaryPartition<double>;
|
||||
const size_t genes_nb = 4;
|
||||
|
||||
/**********************************************
|
||||
* Test if neighborhood has all neighbors.
|
||||
**********************************************/
|
||||
Signature geneset(genes_nb);
|
||||
std::clog << "Available genes:";
|
||||
for(size_t g : geneset.rejected) {
|
||||
std::clog << " " << g;
|
||||
}
|
||||
std::clog << std::endl;
|
||||
|
||||
const size_t n = 2;
|
||||
for(size_t i=0; i < n; ++i) {
|
||||
geneset.select(i);
|
||||
}
|
||||
|
||||
std::clog << "Init geneset: " << geneset << std::endl;
|
||||
std::clog << std::endl;
|
||||
|
||||
moBinaryPartitionSwapNeighborhood<Signature> neighborhood;
|
||||
|
||||
// Save generated solutions for testing.
|
||||
std::vector<Signature> solutions;
|
||||
|
||||
// Follows the framework's workflow (see moRandomBestHCexplorer):
|
||||
// 1) if hasNeighbor()
|
||||
// 2) neighborhood.init(…)
|
||||
// 3) [eval]
|
||||
// 4) while neighborhood.cont(…)
|
||||
// 5) neighborhood.next(…)
|
||||
// 6) [eval]
|
||||
// … loop.
|
||||
if(neighborhood.hasNeighbor(geneset)) {
|
||||
|
||||
moBinaryPartitionSwapNeighbor<Signature> neighbor(n);
|
||||
neighborhood.init(geneset, neighbor);
|
||||
std::clog << "Init neighbor: " << neighbor << std::endl;
|
||||
|
||||
// Print what it looks like.
|
||||
std::clog << "Current geneset: " << geneset << std::endl;
|
||||
Signature new_geneset = geneset;
|
||||
neighbor.move(new_geneset);
|
||||
std::clog << "Moved to solution: " << new_geneset << std::endl;
|
||||
solutions.push_back(new_geneset);
|
||||
std::clog << std::endl;
|
||||
|
||||
while(neighborhood.cont(geneset)) {
|
||||
// Generate next neighbor.
|
||||
neighborhood.next(geneset, neighbor);
|
||||
std::clog << "New neighbor: " << neighbor << std::endl;
|
||||
|
||||
// Print what it looks like.
|
||||
std::clog << "Current geneset: " << geneset << std::endl;
|
||||
Signature new_geneset = geneset;
|
||||
neighbor.move(new_geneset);
|
||||
std::clog << "Moved to solution: " << new_geneset << std::endl;
|
||||
solutions.push_back(new_geneset);
|
||||
|
||||
// Double check that one can moveBack and get the same solution.
|
||||
neighbor.moveBack(new_geneset);
|
||||
assert(new_geneset == geneset);
|
||||
std::clog << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::clog << "Generated " << solutions.size() << " neighbors of: " << geneset << std::endl;
|
||||
for(Signature s : solutions) {
|
||||
std::clog << "\t" << s << std::endl;
|
||||
}
|
||||
assert(solutions.size() == 4);
|
||||
|
||||
/**********************************************
|
||||
* Test if a full solution does not have neighbor.
|
||||
**********************************************/
|
||||
Signature full(genes_nb);
|
||||
for(size_t i=0; i < genes_nb; ++i) {
|
||||
full.select(i);
|
||||
}
|
||||
assert(not neighborhood.hasNeighbor(full));
|
||||
|
||||
}
|
||||
|
|
@ -258,9 +258,9 @@ public:
|
|||
|
||||
void filtre(){
|
||||
eoPop<MOEOT> pop;
|
||||
for(unsigned i=0; i<size(); i++)
|
||||
for(int i=0; i<size(); i++)
|
||||
pop.push_back(operator[](i));
|
||||
for(unsigned i=0; i<pop.size(); i++)
|
||||
for(int i=0; i<pop.size(); i++)
|
||||
(*this)(pop[i]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public:
|
|||
* Default ctor.
|
||||
* @param _maxSize the size of archive (must be smaller or equal to the population size)
|
||||
*/
|
||||
moeoSPEA2Archive(unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), defaultComparator(), indiComparator(defaultComparator), defaultDistance(), distance(defaultDistance)
|
||||
moeoSPEA2Archive(unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(defaultDistance)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ public:
|
|||
* @param _dist the distance used
|
||||
* @param _maxSize the size of archive (must be smaller or egal to the population size)
|
||||
*/
|
||||
moeoSPEA2Archive(moeoDistance <MOEOT, double>& _dist, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), defaultComparator(), indiComparator(defaultComparator), distance(_dist)
|
||||
moeoSPEA2Archive(moeoDistance <MOEOT, double>& _dist, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(_dist)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ public:
|
|||
* @param _comparator the functor used to compare objective vectors
|
||||
* @param _maxSize the size of archive (must be smaller or egal to the population size)
|
||||
*/
|
||||
moeoSPEA2Archive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), defaultComparator(), indiComparator(defaultComparator), defaultDistance(), distance(defaultDistance)
|
||||
moeoSPEA2Archive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(defaultDistance)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ public:
|
|||
* @param _indiComparator the functor used to compare MOEOT
|
||||
* @param _maxSize the size of archive (must be smaller or egal to the population size)
|
||||
*/
|
||||
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), defaultComparator(), indiComparator(_indiComparator), defaultDistance(), distance(defaultDistance)
|
||||
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(_indiComparator), distance(defaultDistance)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ public:
|
|||
* @param _comparator the functor used to compare objective vectors
|
||||
* @param _maxSize the size of archive (must be smaller or egal to the population size)
|
||||
*/
|
||||
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, moeoDistance <MOEOT, double>& _dist, moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100) : moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), defaultComparator(), indiComparator(_indiComparator), distance(_dist)
|
||||
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, moeoDistance <MOEOT, double>& _dist, moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100) : moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), indiComparator(_indiComparator), distance(_dist)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -283,12 +283,11 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
|
||||
/** archive max size */
|
||||
unsigned int maxSize;
|
||||
/** archive size */
|
||||
unsigned int borne;
|
||||
/** default moeoComparator*/
|
||||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||
/**
|
||||
* Wrapper which allow to used an moeoComparator in std::sort
|
||||
* @param _comp the comparator to used
|
||||
|
|
@ -315,10 +314,12 @@ private:
|
|||
moeoComparator < MOEOT > & comp;
|
||||
}
|
||||
indiComparator;
|
||||
/** default distance */
|
||||
moeoEuclideanDistance < MOEOT > defaultDistance;
|
||||
/** default moeoComparator*/
|
||||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||
/** distance */
|
||||
moeoDistance <MOEOT, double>& distance;
|
||||
/** default distance */
|
||||
moeoEuclideanDistance < MOEOT > defaultDistance;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -99,11 +99,7 @@ class moeoBitVector : public moeoVector < MOEOObjectiveVector, bool, MOEOFitness
|
|||
if (_is)
|
||||
{
|
||||
resize(bits.size());
|
||||
#if __cplusplus >= 201103L
|
||||
std::transform(bits.begin(), bits.end(), begin(), std::bind(std::equal_to<char>(), std::placeholders::_1, '1'));
|
||||
#else
|
||||
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
|
|||
* Nothing to do
|
||||
* @param _pop the population
|
||||
*/
|
||||
virtual void setup(const eoPop < MOEOT > & /*_pop*/)
|
||||
virtual void setup(const eoPop < MOEOT > & _pop)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
|
|||
* @param _max upper bound
|
||||
* @param _obj the objective index
|
||||
*/
|
||||
virtual void setup(double /*_min*/, double /*_max*/, unsigned int /*_obj*/)
|
||||
virtual void setup(double _min, double _max, unsigned int _obj)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
|
|||
* @param _realInterval the eoRealInterval object
|
||||
* @param _obj the objective index
|
||||
*/
|
||||
virtual void setup(eoRealInterval /*_realInterval*/, unsigned int /*_obj*/)
|
||||
virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
|
||||
{}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
|||
* @param _objVec the objective vector
|
||||
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public:
|
|||
* @param _objVec the objective vector
|
||||
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAs
|
|||
* @param _objVec the objective vector
|
||||
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ public:
|
|||
* @param _objVec the objective vector
|
||||
* @warning NOT IMPLEMENTED, DOES NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoNearestNeighborDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
|||
* @param _objVec the objective vector
|
||||
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ bool testDirRes(std::string _dirName, bool _erase);
|
|||
* @param _archive the archive of non-dominated solutions
|
||||
*/
|
||||
template < class MOEOT >
|
||||
eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & /*_eval*/, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive)
|
||||
eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive)
|
||||
{
|
||||
eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
|
||||
/* the objective vector type */
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
* @param _archive the archive of non-dominated solutions
|
||||
*/
|
||||
template < class MOEOT >
|
||||
moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & /*_archive*/)
|
||||
moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive)
|
||||
{
|
||||
|
||||
/* the objective vector type */
|
||||
|
|
|
|||
|
|
@ -113,12 +113,12 @@ class moeoAggregationFitnessAssignment : public moeoSingleObjectivization < MOEO
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/){}
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec){}
|
||||
|
||||
private:
|
||||
|
||||
class DummyEval: public eoEvalFunc<MOEOT>{
|
||||
void operator()(MOEOT &/*moeo*/){}
|
||||
void operator()(MOEOT &moeo){}
|
||||
}defaultEval;
|
||||
|
||||
//the vector of weight
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class moeoConstraintFitnessAssignment : public moeoSingleObjectivization < MOEOT
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
//std::cout << "WARNING : updateByDeleting not implemented in moeoAssignmentFitnessAssignment" << std::endl;
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ class moeoConstraintFitnessAssignment : public moeoSingleObjectivization < MOEOT
|
|||
|
||||
//dummy evaluation function
|
||||
class DummyEval: public eoEvalFunc<MOEOT>{
|
||||
void operator()(MOEOT &/*moeo*/){
|
||||
void operator()(MOEOT &moeo){
|
||||
}
|
||||
} defaultEval;
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ public:
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoDominanceCountFitnessAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public:
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoDominanceCountRankingFitnessAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public:
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoDominanceRankFitnessAssignment" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
|||
* @param _pop the population
|
||||
* @param _objVec the objective vector
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
// nothing to do... ;-)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,8 +108,8 @@ class moeoDMLSMonOp : public eoMonOp < typename Neighbor::EOT >
|
|||
tmp = rng.random(dmlsArchive.size());
|
||||
_moeo = dmlsArchive[tmp];
|
||||
defaultContinuator.totalGenerations(defaultContinuator.totalGenerations());
|
||||
if(verbose) {
|
||||
std::cout << "moeoDMLSMonOp: dmls stop" << std::endl << std::endl; }
|
||||
if(verbose)
|
||||
std::cout << "moeoDMLSMonOp: dmls stop" << std::endl << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
|
|||
* @param _normalize allow to normalize data (default true)
|
||||
* @param _rho coefficient to determine the reference point.
|
||||
*/
|
||||
moeoHyperVolumeMetric(bool _normalize=true, double _rho=1.1): normalize(_normalize), rho(_rho) {
|
||||
moeoHyperVolumeMetric(bool _normalize=true, double _rho=1.1): normalize(_normalize), rho(_rho), ref_point(NULL){
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
|
|
@ -69,7 +69,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
|
|||
* @param _normalize allow to normalize data (default true)
|
||||
* @param _ref_point the reference point
|
||||
*/
|
||||
moeoHyperVolumeMetric(bool _normalize, ObjectiveVector& _ref_point): normalize(_normalize), rho(0.0), ref_point(_ref_point){
|
||||
moeoHyperVolumeMetric(bool _normalize=true, ObjectiveVector& _ref_point=NULL): normalize(_normalize), rho(0.0), ref_point(_ref_point){
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
|
|
@ -318,8 +318,8 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
|
|||
|
||||
//if there are less than 3 objectifs take the fisrt objectif of the first point of front to begin computation of hypervolume
|
||||
if(_no_objectives < 3){
|
||||
if(_no_objectives < 1) {
|
||||
throw("Error in moeoHyperVolumeUnaryMetric::calc_hypervolume -> argument3: _no_objectives must be greater than 0"); }
|
||||
if(_no_objectives < 1)
|
||||
throw("Error in moeoHyperVolumeUnaryMetric::calc_hypervolume -> argument3: _no_objectives must be greater than 0");
|
||||
temp_vol=_front[0][0];
|
||||
}
|
||||
//else if there at least 3 objectives, a recursive computation of hypervolume starts with _no_objectives -1 on the filter_nondominated_set calculating previously.
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue