An GA-individual optimized for combinatorial optimization.
More...
#include <i_ga.h>
Inherits vita::individual< i_ga >.
|
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_ga & | operator= (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 |
|
unsigned | age () const |
|
void | inc_age () |
|
bool | load (std::istream &, const symbol_set &=symbol_set()) |
|
bool | save (std::ostream &) const |
|
An GA-individual optimized for combinatorial optimization.
- Examples
- pathfinding01.cc, and pathfinding02.cc.
Definition at line 24 of file i_ga.h.
◆ const_iterator
using vita::i_ga::const_iterator = genome_t::const_iterator |
◆ genome_t
using vita::i_ga::genome_t = std::vector<int> |
◆ iterator
using vita::i_ga::iterator = genome_t::iterator |
◆ value_type
using vita::i_ga::value_type = genome_t::value_type |
◆ i_ga()
vita::i_ga::i_ga |
( |
const problem & |
p | ) |
|
|
explicit |
Constructs a new, random GA individual.
- Parameters
-
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.
◆ 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] | ind | an 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
-
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] | x | second 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 |
◆ operator[]() [2/2]
value_type vita::i_ga::operator[] |
( |
std::size_t |
i | ) |
const |
|
inline |
◆ parameters()
std::size_t vita::i_ga::parameters |
( |
| ) |
const |
|
inline |
◆ 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 |
◆ crossover()
Two points crossover.
- Parameters
-
[in] | lhs | first parent |
[in] | rhs | second 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] | ga | data to be printed |
[out] | s | output stream |
- Returns
- a reference to the output stream
Definition at line 70 of file i_ga.cc.
◆ individual< i_ga >
◆ mutation()
unsigned mutation |
( |
double |
pgm, |
|
|
const problem & |
prb |
|
) |
| |
|
related |
Mutates the current individual.
- Parameters
-
[in] | pgm | probability of gene mutation |
[in] | prb | the 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] | s | output stream |
[in] | ind | individual 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: