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§
Source§impl 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§
Source§impl<'a> Individual<'a> for Route
impl<'a> Individual<'a> for Route
Source§fn 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);
Source§fn 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]))
);
Source§fn 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]]))
)
Source§type IndividualCost = DistanceMat
type IndividualCost = DistanceMat
The Type of cost data this individual is compatible to compute its
fitness on.
impl Eq for Route
impl StructuralPartialEq for Route
Auto Trait Implementations§
impl Freeze for Route
impl RefUnwindSafe for Route
impl Send for Route
impl Sync for Route
impl Unpin for Route
impl UnwindSafe for Route
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more