Struct genetic_algorithm_tsp::route::Route
source · [−]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
sourceimpl Route
impl Route
sourcepub fn get_n_nodes(&self) -> usize
pub fn get_n_nodes(&self) -> usize
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
sourceimpl<'a> Individual<'a> for Route
impl<'a> Individual<'a> for Route
sourcefn mutate(self, prob: f32) -> Self
fn mutate(self, prob: f32) -> Self
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);
sourcefn crossover(&self, other: &Route) -> Self
fn crossover(&self, other: &Route) -> Self
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]))
);
sourcefn fitness(&self, distance_mat: &DistanceMat) -> f64
fn fitness(&self, distance_mat: &DistanceMat) -> f64
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]]))
)
type IndividualCost = DistanceMat
type IndividualCost = DistanceMat
The Type of cost data this individual is compatible to compute its fitness on. Read more
impl Eq for Route
impl StructuralEq for Route
impl StructuralPartialEq for Route
Auto Trait Implementations
impl RefUnwindSafe for Route
impl Send for Route
impl Sync for Route
impl Unpin for Route
impl UnwindSafe for Route
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more