Class GeneticAlgorithm

Inheritance Relationships

Base Type

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 through
  • popsize: number of individuals within a signle generation
  • c: cmargin of error from best path
  • shorten_chromosome: shorten the chromosome if the goal is found before the path length reaches its maximum value
  • path_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 node
  • goal: 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

std::vector<Node> GenerateRandomPath() const

Creates a random chromosome.

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

bool CheckPath(const std::vector<Node> &path) const

Checks whether path is valid or not.

Return
bool value of validity of path
Parameters
  • path: Each chromosome represents a path by a sequence of moves.

void CheckIfNodesInPathAreAcceptable(const std::vector<Node> &path) const

Checks whether every node in the path is an acceptable motion primitive.

Return
void
Parameters
  • path: Each chromosome represents a path by a sequence of moves.