Class GeneticAlgorithm¶
- Defined in File genetic_algorithm.hpp
Inheritance Relationships¶
Base Type¶
public Planner
(Class Planner)
Class Documentation¶
-
class
GeneticAlgorithm
: public Planner¶ Class for objects that plan using the Genetic algorithm.
Public Functions
-
GeneticAlgorithm
(const std::vector<std::vector<int>> &grid)¶ Constructor.
- Return
- no return value
- Parameters
grid
: the grid on which the planner is to plan
-
void
SetParams
(const int generations = 10000, const int popsize = 30, const double c = 1.05, const bool shorten_chromosome = false, const int path_length = 30)¶ Set params for the planner.
- Return
- no return value
- Parameters
generations
: number of generations that the algorithm goes throughpopsize
: number of individuals within a signle generationc
: cmargin of error from best pathshorten_chromosome
: shorten the chromosome if the goal is found before the path length reaches its maximum valuepath_length
: maximum path length
-
std::tuple<bool, std::vector<Node>>
Plan
(const Node &start, const Node &goal)¶ Genetic Algorithm implementation.
- Return
- tuple contatining a bool as to whether a path was found, and the path
- Parameters
start
: start nodegoal
: goal node
-
std::vector<Node>
ReturnLastPath
() const¶ Returns the last valid path within an iteration.
- Return
- last valid path
-
void
PrintChromosome
(const std::vector<Node> &path) const¶ Prints a chromosome, ie the sequence of moves made.
- Return
- void
- Parameters
path
: Each chromosome represents a path by a sequence of moves.
-
void
PrintPathOfChromosome
(const std::vector<Node> &path) const¶ Prints the path represented by the chomosome.
- Return
- void
- Parameters
path
: Each chromosome represents a path by a sequence of moves.
-
std::vector<Node>
GenerateSimplePath
() const¶ Creates a chromosome using the x and y distances between the start and the goal.
- Return
- chromosome
-
int
CalculateFitness
(const std::vector<Node> &path) const¶ Calculates fitness value of a path.
- Return
- value of fitness
- Parameters
path
: Each chromosome represents a path by a sequence of moves.
-
std::vector<Node>
Crossover
() const¶ Mutation function to create random combinations of parents as well as some random changes. Applied to every chromosome in paths.
- Return
- new potential path
-
std::vector<Node>
Mutate
() const¶ Mutation function to create that alters one of the paths found to create a new path.
- Return
- new potential path
-