pub struct Route {
    pub indexes: Vec<usize>,
}
Expand description

The Route is an invidiual in the traveling salemens problem that is a valid route.

Fields

indexes: Vec<usize>

The order in which the nodes should be visited.

Implementations

Create a new route based on a vector of indexes.

Arguments
  • indexes - The order in which the nodes are visited in the Traveling Salesman Problem.
Examples
use genetic_algorithm_tsp::route::Route;

let my_individual = Route::from(Route::new(vec![0,1,2]));

Get the number of nodes for this route.

Examples
use genetic_algorithm_tsp::route::Route;

let three_node_route = Route::from(Route::new(vec![0,1,2]));
println!("This route has {} nodes", three_node_route.get_n_nodes());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Make Route formattable.

As a string representation of the Route, just display the inidividual nodes that are visited.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Randomly changes the order of two nodes in the route

Arguments
  • prob - The probability with which the indexes will be changed
Examples
use genetic_algorithm_tsp::route::Route;
use  genetic_algorithm_traits::Individual;

let my_individual = Route::from(Route::new(vec![0,1,2]));
let my_mutated_indiviual =  my_individual.mutate(1.0);

Crossover this invidual with another individual to create a new individual. Currently uses the ordered_crossover algorithm.

Arguments
  • other - The other individual you would like to crossover with this individual.
Examples
use genetic_algorithm_tsp::route::Route;
use  genetic_algorithm_traits::Individual;

let my_individual = Route::from(Route::new(vec![0,1,2]));
let my_individual = my_individual.crossover(
    &Route::from(Route::new(vec![1,0,2]))
);

Compute how much distance the individual implies with its order of nodes and the distance matrix.

Arguments
  • distance_matrix - Distance Matrix that determines the length of the proposed route
Examples
use genetic_algorithm_tsp::route::Route;
use genetic_algorithm_tsp::distance_mat::DistanceMat;
use  genetic_algorithm_traits::Individual;

let my_individual = Route::from(Route::new(vec![0,1,2]));
println!("Fitness of your individual: {}", my_individual.fitness(
    &DistanceMat::new(vec![vec![0.0,1.0,2.0], vec![1.0,0.0,3.0], vec![2.0,3.0,0.0]]))
)

The Type of cost data this individual is compatible to compute its fitness on. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.