Skip to content

Commit

Permalink
Merge pull request #296 from bluescarni/pr/topo
Browse files Browse the repository at this point in the history
(WIP) Migration
  • Loading branch information
bluescarni authored Aug 7, 2019
2 parents 916752a + 5a30f9d commit 122ab1f
Show file tree
Hide file tree
Showing 113 changed files with 15,402 additions and 349 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ if(PAGMO_BUILD_PAGMO)
"${CMAKE_CURRENT_SOURCE_DIR}/src/io.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/rng.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/threading.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/topology.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/r_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/s_policy.cpp"
# UDP.
"${CMAKE_CURRENT_SOURCE_DIR}/src/problems/null_problem.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/problems/cec2006.cpp"
Expand Down Expand Up @@ -214,12 +217,22 @@ if(PAGMO_BUILD_PAGMO)
"${CMAKE_CURRENT_SOURCE_DIR}/src/batch_evaluators/default_bfe.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/batch_evaluators/member_bfe.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/batch_evaluators/thread_bfe.cpp"
# UDT.
"${CMAKE_CURRENT_SOURCE_DIR}/src/topologies/base_bgl_topology.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/topologies/unconnected.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/topologies/fully_connected.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/topologies/ring.cpp"
# UDRP.
"${CMAKE_CURRENT_SOURCE_DIR}/src/r_policies/fair_replace.cpp"
# UDSP.
"${CMAKE_CURRENT_SOURCE_DIR}/src/s_policies/select_best.cpp"
# Utils.
"${CMAKE_CURRENT_SOURCE_DIR}/src/utils/constrained.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/utils/discrepancy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/utils/generic.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/utils/multi_objective.cpp"
# Detail.
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/base_sr_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/bfe_impl.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/task_queue.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/prime_numbers.cpp"
Expand Down
40 changes: 39 additions & 1 deletion doc/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Changelog
New
~~~

- NSGA2 can optionally use the batch fitness evaluation framework
(`#308 <https://github.com/esa/pagmo2/pull/308>`__).

- Implement the WFG test suite
(`#298 <https://github.com/esa/pagmo2/pull/298>`__).

- Migration framework
(`#296 <https://github.com/esa/pagmo2/pull/296>`__).

- Various additions to the C++ API of user-defined classes
(`#294 <https://github.com/esa/pagmo2/pull/294>`__).

Expand All @@ -23,6 +32,8 @@ New

- Implement the Lennard-Jones and Golomb ruler problems (`#247 <https://github.com/esa/pagmo2/pull/247>`__).

- Batch fitness evaluation framework (`#226 <https://github.com/esa/pagmo2/pull/226>`__).

Changes
~~~~~~~

Expand All @@ -34,6 +45,21 @@ Changes
OSX and MinGW, as they cause build
issues (`#266 <https://github.com/esa/pagmo2/pull/266>`__, `#292 <https://github.com/esa/pagmo2/pull/292>`__).

- **BREAKING**: the serialization backend was switched from the
Cereal library to the Boost.serialization library. This change has
no consequences
for Python users, nor for C++ users who use pagmo's CMake machinery.
For those C++ users who don't use CMake,
this means that in order to use pagmo it is now necessary to link
to the Boost.serialization library (`#278 <https://github.com/esa/pagmo2/pull/278>`__).

- **BREAKING**: pagmo is not any more a header-only library, it has now
a compiled component. This change has no consequences
for Python users, nor for C++ users who use pagmo's CMake machinery.
For those C++ users who don't use CMake,
this means that in order to use pagmo it is now necessary to link
to a compiled library (`#278 <https://github.com/esa/pagmo2/pull/278>`__).

- Various performance improvements in the :cpp:class:`~pagmo::population` API (`#250 <https://github.com/esa/pagmo2/pull/250>`__).

- **BREAKING**: :class:`pygmo.problem` and :class:`pygmo.algorithm`
Expand All @@ -43,6 +69,17 @@ Changes
Fix
~~~

- Fix a bug in pygmo's plotting utils (`#330 <https://github.com/esa/pagmo2/pull/330>`__).

- Fix a bug in PSO's error handling (`#323 <https://github.com/esa/pagmo2/pull/323>`__).

- Fix a bug in MOEA/D when ``m_neighbours<2`` (`#320 <https://github.com/esa/pagmo2/pull/320>`__).

- Fix type mismatches in the constrained/MO utils (`#315 <https://github.com/esa/pagmo2/pull/315>`__).

- Fix a potential deadlock when setting/getting an island's
population/algorithm (`#309 <https://github.com/esa/pagmo2/pull/309>`__).

- Fix a build failure when pagmo is configured without Eigen3 (`#281 <https://github.com/esa/pagmo2/pull/281>`__).

- Fix a build failure in the Ipopt algorithm wrapper when using the Debian/Ubuntu Ipopt packages (`#266 <https://github.com/esa/pagmo2/pull/266>`__).
Expand All @@ -56,7 +93,8 @@ Fix
`#257 <https://github.com/esa/pagmo2/pull/257>`__, `#262 <https://github.com/esa/pagmo2/pull/262>`__,
`#265 <https://github.com/esa/pagmo2/pull/265>`__, `#266 <https://github.com/esa/pagmo2/pull/266>`__,
`#279 <https://github.com/esa/pagmo2/pull/279>`__, `#287 <https://github.com/esa/pagmo2/pull/287>`__,
`#288 <https://github.com/esa/pagmo2/pull/288>`__).
`#288 <https://github.com/esa/pagmo2/pull/288>`__, `#327 <https://github.com/esa/pagmo2/pull/327>`__,
`#328 <https://github.com/esa/pagmo2/pull/328>`__).

- The :cpp:class:`~pagmo::fork_island` UDI now properly cleans up zombie processes (`#242 <https://github.com/esa/pagmo2/pull/242>`__).

Expand Down
9 changes: 9 additions & 0 deletions doc/sphinx/docs/cpp/archipelago.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Archipelago
===========

*#include <pagmo/archipelago.hpp>*

.. doxygenclass:: pagmo::archipelago
:members:

Types
-----

.. doxygenenum:: pagmo::migration_type

.. doxygenenum:: pagmo::migrant_handling
27 changes: 27 additions & 0 deletions doc/sphinx/docs/cpp/cpp_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ we suggest to follow the tutorials / examples.
island
archipelago
bfe
topology
r_policy
s_policy

Implemented algorithms
^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -96,6 +99,30 @@ Implemented batch evaluators
batch_evaluators/thread_bfe
batch_evaluators/member_bfe

Implemented topologies
^^^^^^^^^^^^^^^^^^^^^^
.. toctree::
:maxdepth: 1

topologies/unconnected
topologies/fully_connected
topologies/base_bgl_topology
topologies/ring

Implemented replacement policies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. toctree::
:maxdepth: 1

r_policies/fair_replace

Implemented selection policies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. toctree::
:maxdepth: 1

s_policies/select_best

Utilities
^^^^^^^^^
Various optimization utilities.
Expand Down
28 changes: 28 additions & 0 deletions doc/sphinx/docs/cpp/island.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
Island
======

*#include <pagmo/island.hpp>*

.. doxygenclass:: pagmo::island
:members:

Functions
---------

.. cpp:namespace-push:: pagmo

.. cpp:function:: std::ostream &operator<<(std::ostream &os, const island &isl)

Stream operator for :cpp:class:`pagmo::island`.

This operator will stream to *os* a human-readable representation of *isl*.

It is safe to call this method while the island is evolving.

:param os: the target stream.
:param isl: the input island.

:return: a reference to *os*.

:exception unspecified: any exception trown by the stream operators of fundamental types or by
the public interface of :cpp:class:`pagmo::island` and of all its members.

.. cpp:namespace-pop::

Types
-----

.. doxygenenum:: pagmo::evolve_status
128 changes: 128 additions & 0 deletions doc/sphinx/docs/cpp/r_policies/fair_replace.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
Fair replacement policy
=======================

.. versionadded:: 2.11

*#include <pagmo/r_policies/fair_replace.hpp>*

.. cpp:namespace-push:: pagmo

.. cpp:class:: fair_replace

This user-defined replacement policy (UDRP) will replace individuals in
a group only if the candidate replacement individuals are *better* than
the original individuals.

In this context, *better* means the following:

* in single-objective unconstrained problems, an individual is better
than another one if its fitness is lower,
* in single-objective constrained problems, individuals are ranked
via :cpp:func:`~pagmo::sort_population_con()`,
* in multi-objective unconstrained problems, individuals are ranked
via :cpp:func:`~pagmo::sort_population_mo()`.

See the documentation of :cpp:func:`~pagmo::fair_replace::replace()` for
more details on the replacement algorithm implemented by this UDRP.

Note that this user-defined replacement policy currently does *not* support
multi-objective constrained problems.

.. cpp:function:: fair_replace()

Default constructor.

The default constructor initialises a policy with an absolute migration rate of 1
(that is, 1 individual in the original population is considered for replacement).

.. cpp:function:: template <typename T> explicit fair_replace(T x)

Constructor from a migration rate.

This constructor participates in overload resolution only if ``T`` is a C++
integral or a floating-point type. The input migration rate, *x*, is used to indicate
how many individuals will be replaced in an input population by the
:cpp:func:`~pagmo::fair_replace::replace()` member function.

If *x* is a floating point value in the :math:`\left[0,1\right]` range,
then it represents a *fractional* migration rate. That is, it indicates,
the fraction of individuals that may be replaced in the input population:
a value of 0 means that no individuals will be replaced, a value of 1 means that
all individuals may be replaced.

If *x* is an integral value, then it represents an *absolute* migration rate, that is,
the exact number of individuals that may be replaced in the input population.

:param x: the fractional or absolute migration rate.

:exception std\:\:invalid_argument: if the supplied fractional migration rate is not finite
or not in the :math:`\left[0,1\right]` range.
:exception unspecified: any exception raised by ``boost::numeric_cast()`` while trying
to convert the input absolute migration rate to :cpp:type:`~pagmo::pop_size_t`.

.. cpp:function:: individuals_group_t replace(const individuals_group_t &inds, const vector_double::size_type &, \
const vector_double::size_type &, const vector_double::size_type &nobj, \
const vector_double::size_type &nec, const vector_double::size_type &nic, \
const vector_double &tol, const individuals_group_t &mig) const

This member function will replace individuals in *inds* with individuals from *mig*.

The replacement algorithm determines first how many individuals in *inds* can be replaced. This depends both on
the migration rate specified upon construction, and on the size :math:`S` of *inds*.

After having established the number :math:`N` of individuals that can be replaced in *inds*,
the algorithm then selects the top :math:`N` individuals from *mig*, merges them
with *inds* into a new population, and returns the top :math:`S` individuals
from the new population. The ranking of individuals in *mig* and in the new population
depends on the problem's properties:

* in single-objective unconstrained problems, the individuals are ranked according to their
(scalar) fitnesses,
* in single-objective constrained problems, the ranking of individuals
is done via :cpp:func:`~pagmo::sort_population_con()`,
* in multi-objective unconstrained problems, the ranking of individuals
is done via :cpp:func:`~pagmo::sort_population_mo()`.

Note that this user-defined replacement policy currently does *not* support
multi-objective constrained problems.

:param inds: the input individuals.
:param nobj: the number of objectives of the problem the individuals in *inds* and *mig* refer to.
:param nec: the number of equality constraints of the problem the individuals in *inds* and *mig* refer to.
:param nic: the number of inequality constraints of the problem the individuals in *inds* and *mig* refer to.
:param tol: the vector of constraint tolerances of the problem the individuals in *inds* and *mig* refer to.
:param mig: the individuals that may replace individuals in *inds*.

:return: the new population resulting from replacing individuals in *inds* with individuals from *mig*.

:exception std\:\:invalid_argument: in the following cases:

* the problem the individuals in *inds* and *mig* refer to is
multi-objective and constrained,
* an absolute migration rate larger than the number of input individuals
was specified.

:exception unspecified: any exception raised by one of the invoked ranking functions or by memory
allocation errors in standard containers.

.. cpp:function:: std::string get_name() const

Get the name of the policy.

:return: ``"Fair replace"``.

.. cpp:function:: std::string get_extra_info() const

:return: Human-readable extra info about this replacement policy.

.. cpp:function:: template <typename Archive> void serialize(Archive &ar, unsigned)

Serialisation support.

This member function is used to implement the (de)serialisation of this replacement policy to/from an archive.

:param ar: the input/output archive.

:exception unspecified: any exception raised by the (de)serialisation of primitive types.

.. cpp:namespace-pop::
Loading

0 comments on commit 122ab1f

Please sign in to comment.