Struct Route

Source
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

Source

pub fn new(indexes: Vec<usize>) -> Self

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]));
Source

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 Clone for Route

Source§

fn clone(&self) -> Route

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Route

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Route

Make Route formattable.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

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

Source§

impl Hash for Route

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<'a> Individual<'a> for Route

Source§

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

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

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

The Type of cost data this individual is compatible to compute its fitness on.
Source§

impl PartialEq for Route

Source§

fn eq(&self, other: &Route) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Route

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V