Vita
Public Types | Public Member Functions | Friends | Related Functions | List of all members
vita::i_ga Class Reference

An GA-individual optimized for combinatorial optimization. More...

#include <i_ga.h>

Inherits vita::individual< i_ga >.

Public Types

using const_iterator = genome_t::const_iterator
 
using genome_t = std::vector< int >
 
using iterator = genome_t::iterator
 
using value_type = genome_t::value_type
 

Public Member Functions

iterator begin ()
 
const_iterator begin () const
 
unsigned distance (const i_ga &) const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
void graphviz (std::ostream &) const
 Produces a dot-language representation of this individual. More...
 
 i_ga (const problem &)
 Constructs a new, random GA individual. More...
 
bool is_valid () const
 
unsigned mutation (double, const problem &)
 
 operator std::vector< value_type > () const
 
i_gaoperator= (const std::vector< value_type > &)
 
bool operator== (const i_ga &) const
 
value_type & operator[] (std::size_t i)
 
value_type operator[] (std::size_t i) const
 
std::size_t parameters () const
 
hash_t signature () const
 The signature (hash value) of this individual. More...
 
std::size_t size () const
 
- Public Member Functions inherited from vita::individual< i_ga >
unsigned age () const
 
void inc_age ()
 
bool load (std::istream &, const symbol_set &=symbol_set())
 
bool save (std::ostream &) const
 

Friends

i_ga crossover (const i_ga &, const i_ga &)
 
class individual< i_ga >
 

Related Functions

(Note that these are not member functions.)

i_ga crossover (const i_ga &lhs, const i_ga &rhs)
 Two points crossover. More...
 
std::ostream & in_line (const i_ga &ga, std::ostream &s)
 Prints the genes of the individual. More...
 
unsigned mutation (double pgm, const problem &prb)
 Mutates the current individual. More...
 
std::ostream & operator<< (std::ostream &s, const i_ga &ind)
 

Additional Inherited Members

- Protected Member Functions inherited from vita::individual< i_ga >
void set_older_age (unsigned)
 
- Protected Attributes inherited from vita::individual< i_ga >
hash_t signature_
 

Detailed Description

An GA-individual optimized for combinatorial optimization.

Examples
pathfinding01.cc, and pathfinding02.cc.

Definition at line 24 of file i_ga.h.

Member Typedef Documentation

◆ const_iterator

using vita::i_ga::const_iterator = genome_t::const_iterator

Definition at line 32 of file i_ga.h.

◆ genome_t

using vita::i_ga::genome_t = std::vector<int>

Definition at line 31 of file i_ga.h.

◆ iterator

using vita::i_ga::iterator = genome_t::iterator

Definition at line 33 of file i_ga.h.

◆ value_type

using vita::i_ga::value_type = genome_t::value_type

Definition at line 34 of file i_ga.h.

Constructor & Destructor Documentation

◆ i_ga()

vita::i_ga::i_ga ( const problem p)
explicit

Constructs a new, random GA individual.

Parameters
[in]pcurrent problem

The process that generates the initial, random expressions has to be implemented so as to ensure that they do not violate the type system's constraints.

Definition at line 29 of file i_ga.cc.

Member Function Documentation

◆ begin() [1/2]

i_ga::iterator vita::i_ga::begin ( )
inline
Returns
an iterator pointing to the first individual of the team

Definition at line 134 of file i_ga.h.

◆ begin() [2/2]

i_ga::const_iterator vita::i_ga::begin ( ) const
inline
Returns
a const iterator pointing to the first individual of the team

Definition at line 118 of file i_ga.h.

◆ distance()

unsigned vita::i_ga::distance ( const i_ga ind) const
Parameters
[in]indan individual to compare with this
Returns
a numeric measurement of the difference between ind and this (the number of different genes between individuals)

Definition at line 199 of file i_ga.cc.

◆ empty()

bool vita::i_ga::empty ( ) const
inline
Returns
true if the individual is empty, false otherwise

Definition at line 64 of file i_ga.h.

◆ end() [1/2]

i_ga::iterator vita::i_ga::end ( )
inline
Returns
an iterator pointing to a end-of-team sentry

Definition at line 142 of file i_ga.h.

◆ end() [2/2]

i_ga::const_iterator vita::i_ga::end ( ) const
inline
Returns
a const iterator pointing to a end-of-team sentry

Definition at line 126 of file i_ga.h.

◆ graphviz()

void vita::i_ga::graphviz ( std::ostream &  s) const

Produces a dot-language representation of this individual.

Parameters
[out]soutput stream

The output stream contains a graph, described in dot language (http://www.graphviz.org/), of this individual.

Definition at line 51 of file i_ga.cc.

◆ is_valid()

bool vita::i_ga::is_valid ( ) const
Returns
true if the individual passes the internal consistency check

Definition at line 214 of file i_ga.cc.

◆ operator==()

bool vita::i_ga::operator== ( const i_ga x) const
Parameters
[in]xsecond term of comparison
Returns
true if the two individuals are equal
Note
Age is not checked.

Definition at line 184 of file i_ga.cc.

◆ operator[]() [1/2]

value_type & vita::i_ga::operator[] ( std::size_t  i)
inline

Definition at line 48 of file i_ga.h.

◆ operator[]() [2/2]

value_type vita::i_ga::operator[] ( std::size_t  i) const
inline

Definition at line 42 of file i_ga.h.

◆ parameters()

std::size_t vita::i_ga::parameters ( ) const
inline
Returns
the number of parameters stored in the individual
Note
size() and parameters() are aliases.
Examples
pathfinding01.cc.

Definition at line 78 of file i_ga.h.

◆ signature()

hash_t vita::i_ga::signature ( ) const

The signature (hash value) of this individual.

Returns
the signature of this individual

Identical individuals at genotypic level have the same signature. The signature is calculated just at the first call and then stored inside the individual.

Definition at line 154 of file i_ga.cc.

◆ size()

std::size_t vita::i_ga::size ( ) const
inline
Returns
the number of parameters stored in the individual
Note
parameters() and size() are aliases.
Examples
pathfinding02.cc.

Definition at line 71 of file i_ga.h.

Friends And Related Function Documentation

◆ crossover()

i_ga crossover ( const i_ga lhs,
const i_ga rhs 
)
related

Two points crossover.

Parameters
[in]lhsfirst parent
[in]rhssecond parent
Returns
crossover children (we only generate a single offspring)

We randomly select two loci (common crossover points). The offspring is created with genes from the rhs parent before the first crossover point and after the second crossover point; genes between crossover points are taken from the lhs parent.

Note
Parents must have the same size.

Definition at line 126 of file i_ga.cc.

◆ in_line()

std::ostream & in_line ( const i_ga ga,
std::ostream &  s 
)
related

Prints the genes of the individual.

Parameters
[in]gadata to be printed
[out]soutput stream
Returns
a reference to the output stream

Definition at line 70 of file i_ga.cc.

◆ individual< i_ga >

friend class individual< i_ga >
friend

Definition at line 88 of file i_ga.h.

◆ mutation()

unsigned mutation ( double  pgm,
const problem prb 
)
related

Mutates the current individual.

Parameters
[in]pgmprobability of gene mutation
[in]prbthe current problem
Returns
number of mutations performed

Definition at line 85 of file i_ga.cc.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  s,
const i_ga ind 
)
related
Parameters
[out]soutput stream
[in]indindividual to print
Returns
output stream including ind

Definition at line 286 of file i_ga.cc.


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