PaGMO  1.1.5
Protected Attributes | Friends
pagmo::base_island Class Referenceabstract

Base island class. More...

#include <base_island.h>

Inheritance diagram for pagmo::base_island:
Inheritance graph
[legend]

Public Member Functions

Ctors, dtor and assignment operator.
 base_island (const base_island &)
 Copy constructor. More...
 
 base_island (const algorithm::base &, const problem::base &, int, const migration::base_s_policy &, const migration::base_r_policy &)
 Constructor from problem::base, algorithm::base, number of individuals, migration probability and selection/replacement policies. More...
 
 base_island (const algorithm::base &, const population &, const migration::base_s_policy &, const migration::base_r_policy &)
 Constructor from population. More...
 
base_islandoperator= (const base_island &)
 Assignment operator. More...
 
virtual base_island_ptr clone () const =0
 Clone method. More...
 
virtual ~base_island ()
 Destructor. More...
 
Input/output.
std::string human_readable_terse () const
 Return terse human readable representation of the island. More...
 
std::string human_readable () const
 Return human readable representation of the island. More...
 
virtual std::string get_name () const
 Return a string identifying the island's type. More...
 
Getters and setters.
algorithm::base_ptr get_algorithm () const
 Return copy of the internal algorithm. More...
 
void set_algorithm (const algorithm::base &)
 Algorithm setter. More...
 
void set_x (population::size_type, const decision_vector &)
 Sets a decision vector. More...
 
void set_v (population::size_type, const decision_vector &)
 Sets a velocity vector. More...
 
problem::base_ptr get_problem () const
 Return copy of the internal problem. More...
 
population::size_type get_size () const
 Size of the internal population. More...
 
migration::base_s_policy_ptr get_s_policy () const
 Get a copy of the selection policy. More...
 
migration::base_r_policy_ptr get_r_policy () const
 Get a copy of the replacement policy. More...
 
population get_population () const
 Get a copy of the internal population. More...
 
void set_population (const population &)
 Set internal population. More...
 

Protected Attributes

algorithm::base_ptr m_algo
 Algorithm.
 
population m_pop
 Population.
 
archipelagom_archi
 Pointer that, if not null, points to the archipelago containing the island.
 
std::size_t m_evo_time
 Total time spent by the island on evolution (in milliseconds).
 
migration::base_s_policy_ptr m_s_policy
 Migration selection policy.
 
migration::base_r_policy_ptr m_r_policy
 Migration replacement policy.
 
boost::scoped_ptr< boost::thread > m_evo_thread
 Evolution thread.
 

Friends

class archipelago
 The archipelago class needs access to the internals of the island.
 
struct raii_thread_hook
 
class boost::serialization::access
 

Evolution.

Methods related to island evolution.

virtual void join () const
 Join island. More...
 
bool busy () const
 Query the status of the island. More...
 
void evolve (int=1)
 Evolve island n times. More...
 
void evolve_t (int)
 Evolve island for a specified minimum amount of time. More...
 
void interrupt ()
 Interrupt evolution. More...
 
std::size_t get_evolution_time () const
 Return the total evolution time in milliseconds. More...
 
virtual void perform_evolution (const algorithm::base &, population &) const =0
 Method that implements the evolution of the population.
 
virtual void thread_entry ()
 Thread entry hook. More...
 
virtual void thread_exit ()
 Thread exit hook. More...
 

Detailed Description

Base island class.

This class incorporates a pagmo::population and a pagmo::algorithm::base used to evolve the population. Each time the evolve() (or evolve_t()) method is called, a derived island class will execute the algorithm's evolve method on the population. The actual mechanism of launching the evolve method is defined in the derived class - see below for more details. While evolution is undergoing, the island is locked down and no further operations will be allowed. The method join() can be used to wait until evolution on the island has terminated. The busy() methods can be used to query the state of the island.

The island can either exist as a stand-alone object or as a component of an archipelago. If the island belongs to an archipelago, it can exchange individuals with other islands in the archipelago. The topology of the archipelago determines the connections between islands, whereas every island can define migration policies to specify how to select and replace individuals during migration. The relevant policy classes are migration::base_s_policy (selection policy) and migration::base_r_policy (replacement policy). The probability of inserting migrating individuals into the island is regulated by the migration probability parameter. These migration parameters can be specified upon island construction and they are given (hopefully) reasonable default values. See the constructors for detailed information.

The interface of this class mirrors the interface of the population class. It is hence possible to get and set individuals, get the population size, access the population champion, etc. The main difference is that the methods of this class will never return references to internal members, in order to protect the internal state of the island while evolution is undergoing. All getters methods will thus return copies instead of references, and all public methods will wait for an ongoing evolution to terminate before performing any action.

Implementation of the evolution methods

When one of the evolution methods (evolve() or evolve_t()) is launched, a local thread is opened and the perform_evolution() method is called from the new thread using as arguments the population and the algorithm stored in the island.

Author
Francesco Biscani (blues.nosp@m.carn.nosp@m.i@gma.nosp@m.il.c.nosp@m.om)
Marek RuciƄski (marek.nosp@m..ruc.nosp@m.inski.nosp@m.@gma.nosp@m.il.co.nosp@m.m)

Definition at line 81 of file base_island.h.

Constructor & Destructor Documentation

pagmo::base_island::base_island ( const base_island isl)

Copy constructor.

Will perform a deep copy of all the elements of island isl, which will be synchronised before any operation takes place.

Parameters
[in]islisland to be copied.

Definition at line 75 of file base_island.cpp.

pagmo::base_island::base_island ( const algorithm::base a,
const problem::base p,
int  n,
const migration::base_s_policy s_policy,
const migration::base_r_policy r_policy 
)
explicit

Constructor from problem::base, algorithm::base, number of individuals, migration probability and selection/replacement policies.

Will store a copy of the problem, of the algorithm and of the policies internally, will initialise internal population to n individuals and evolution time to zero. Will fail if n is negative or if migration probability is not in the [0,1] range.

Parameters
[in]aalgorithm::base which will be associated to the island.
[in]pproblem::base to which the internal population will be associated.
[in]nnumber of individuals in the internal population.
[in]s_policymigration::base_s_policy for the island.
[in]r_policymigration::base_r_policy for the island.
Exceptions
pagmo::value_errorif migration probability is outside the [0,1] range.

Definition at line 65 of file base_island.cpp.

pagmo::base_island::base_island ( const algorithm::base a,
const population pop,
const migration::base_s_policy s_policy,
const migration::base_r_policy r_policy 
)
explicit

Constructor from population.

Will construct an island containing the given population and algorithm.

Parameters
[in]aalgorithm::base which will be associated to the island.
[in]poppopulation that will be contained in the island.
[in]s_policymigration::base_s_policy for the island.
[in]r_policymigration::base_r_policy for the island.
Exceptions
pagmo::value_errorif migration probability is outside the [0,1] range.

Definition at line 97 of file base_island.cpp.

pagmo::base_island::~base_island ( )
virtual

Destructor.

Will call base_island::join() (the default implementation) internally. No other side effects.

Definition at line 131 of file base_island.cpp.

Member Function Documentation

bool pagmo::base_island::busy ( ) const

Query the status of the island.

Returns
true if the island is evolving, false otherwise.

Definition at line 419 of file base_island.cpp.

virtual base_island_ptr pagmo::base_island::clone ( ) const
pure virtual

Clone method.

Provided that the derived island implements properly the copy constructor, virtually all implementations of this method will look like this:

return base_ptr(new derived_island(*this));
Returns
pagmo::base_island_ptr to a copy of this.

Implemented in pagmo::mpi_island, and pagmo::island.

void pagmo::base_island::evolve ( int  n = 1)

Evolve island n times.

Call the internal algorithm's algorithm::base::evolve() method n times on the internal population, using an island-specific mechanism for the actual execution of the code.

During evolution, the island is locked down and no actions on it are possible, but the flow of the rest of the program might continue without waiting for all evolutions to finish. To explicitly block the program until all evolution runs have been performed on the island, call the join() method.

Parameters
[in]nnumber of algorithm::base::evolve() calls that will be performed by the internal algorithm on the population.

Definition at line 308 of file base_island.cpp.

void pagmo::base_island::evolve_t ( int  t)

Evolve island for a specified minimum amount of time.

Call the internal algorithm's algorithm::base::evolve() method on the population at least once, and keep calling it until at least t milliseconds (in "wall clock" time) have elapsed. Will fail if t is negative.

During evolution, the island is locked down and no actions on it are possible, but the flow of the rest of the program might continue without waiting for all evolutions to finish. To explicitly block the program until all evolution runs have been performed on the island, call the join() method.

Parameters
[in]tminimum evolution time in milliseconds.

Definition at line 391 of file base_island.cpp.

algorithm::base_ptr pagmo::base_island::get_algorithm ( ) const

Return copy of the internal algorithm.

Returns
algorithm::base_ptr to the cloned algorithm.

Definition at line 444 of file base_island.cpp.

std::size_t pagmo::base_island::get_evolution_time ( ) const

Return the total evolution time in milliseconds.

Note that on many 32-bit machines this counter will wrap after roughly 49 days. On most 64-bit machines, the wrapping time will be around 584 million years.

Returns
number of milliseconds spent evolving the population.

Definition at line 434 of file base_island.cpp.

std::string pagmo::base_island::get_name ( ) const
virtual

Return a string identifying the island's type.

Default implementation will return the island's C++ mangled name.

Returns
a string identifying the island's type.

Reimplemented in pagmo::mpi_island, and pagmo::island.

Definition at line 142 of file base_island.cpp.

population pagmo::base_island::get_population ( ) const

Get a copy of the internal population.

Returns
copy of the population contained in the island.

Definition at line 532 of file base_island.cpp.

problem::base_ptr pagmo::base_island::get_problem ( ) const

Return copy of the internal problem.

Returns
problem::base_ptr to the cloned problem.

Definition at line 492 of file base_island.cpp.

migration::base_r_policy_ptr pagmo::base_island::get_r_policy ( ) const

Get a copy of the replacement policy.

Returns
migration::base_r_policy_ptr to the cloned policy.

Definition at line 522 of file base_island.cpp.

migration::base_s_policy_ptr pagmo::base_island::get_s_policy ( ) const

Get a copy of the selection policy.

Returns
migration::base_s_policy_ptr to the cloned policy.

Definition at line 512 of file base_island.cpp.

population::size_type pagmo::base_island::get_size ( ) const

Size of the internal population.

Returns
size of the internal population.

Definition at line 502 of file base_island.cpp.

std::string pagmo::base_island::human_readable ( ) const

Return human readable representation of the island.

Will return a formatted string containing:

  • island type from base_island::get_name(),
  • description of the algorithm,
  • the output of population::human_readable().
Returns
string containing complete human readable representation of the island.

Definition at line 179 of file base_island.cpp.

std::string pagmo::base_island::human_readable_terse ( ) const

Return terse human readable representation of the island.

Will return a formatted string containing:

  • island type from base_island::get_name(),
  • description of the algorithm,
  • the output of population::human_readable_terse().
Returns
string containing terse human readable representation of the island.

Definition at line 157 of file base_island.cpp.

void pagmo::base_island::interrupt ( )

Interrupt evolution.

If an evolution is undergoing, the evolution will be stopped the first time the flow reaches one of the internal interruption points. The method will block until the interruption point has been reached.

Definition at line 407 of file base_island.cpp.

void pagmo::base_island::join ( ) const
virtual

Join island.

This method is intended to block the flow of the program until any ongoing evolution has terminated. The default implementation will join on the internal thread object if an evolution is ongoing, otherwise it will be a no-op. Re-implementation of this method should always call the default implementation.

Definition at line 199 of file base_island.cpp.

base_island & pagmo::base_island::operator= ( const base_island isl)

Assignment operator.

Performs a deep copy of all the elements of isl into this island. Both island will be synchronised before assignment.

Parameters
[in]islisland used for assignment.
Returns
reference to this.

Definition at line 109 of file base_island.cpp.

void pagmo::base_island::set_algorithm ( const algorithm::base algo)

Algorithm setter.

The input algorithm will be cloned.

Parameters
[in]algonew algorithm::base for the island.

Definition at line 482 of file base_island.cpp.

void pagmo::base_island::set_population ( const population pop)

Set internal population.

Parameters
[in]popto be copied into the island.

Definition at line 542 of file base_island.cpp.

void pagmo::base_island::set_v ( population::size_type  i,
const decision_vector v 
)

Sets a velocity vector.

Assigns a velocity vector to the i-th individual of the island population

Parameters
[in]iindividual
[in]vvelocity_vector

Definition at line 470 of file base_island.cpp.

void pagmo::base_island::set_x ( population::size_type  i,
const decision_vector x 
)

Sets a decision vector.

Assigns a decision vector to the i-th individual of the island population

Parameters
[in]iindividual
[in]xdecision_vector

Definition at line 457 of file base_island.cpp.

void pagmo::base_island::thread_entry ( )
protectedvirtual

Thread entry hook.

This method will be called before any other operation takes place in the threads spawned during evolution. Default implementation is a no-op.

Definition at line 211 of file base_island.cpp.

void pagmo::base_island::thread_exit ( )
protectedvirtual

Thread exit hook.

This method will be called after any other operation has taken place in the threads spawned during evolution. Default implementation is a no-op.

Definition at line 219 of file base_island.cpp.


The documentation for this class was generated from the following files: