[−][src]Struct tsp_rs::Tour
Represents a solution to the tsp for the items T
Fields
path: Vec<T>
Methods
impl<T: Metrizable + Clone + Borrow<T>> Tour<T>
[src]
pub fn new() -> Tour<T>
[src]
Returns a new, empty Tour
Example
use tsp_rs::Tour; use tsp_rs::point::Point; let tour: Tour<Point> = Tour::new();
pub fn from(nodes: &Vec<T>) -> Tour<T> where
T: Clone,
[src]
T: Clone,
Returns a tour from nodes: Vec<T>
passed in where the tour
is nodes[0] -> nodes[1] -> ... nodes[nodes.len() - 1] -> nodes[0]
Example
use tsp_rs::Tour; use tsp_rs::point::Point; let nodes = vec![ Point::new(0., 0.), Point::new(1., 0.), Point::new(1., 1.), Point::new(0., 1.), ]; let tour = Tour::from(&nodes);
pub fn tour_len(&self) -> f64
[src]
Returns the length of a tour.
Example
let tour = Tour::from(&some_points); let total_cost = tour.tour_len();
pub fn optimize_kopt(&mut self, timeout: Duration)
[src]
Improves the tour in place using the 2opt heuristic (with 3opt kicks if it gets stuck)
Examples
use std::time; use tsp_rs::Tour; use tsp_rs::point::Point; let nodes = vec![ Point::new(0., 0.), Point::new(1., 0.), Point::new(1., 1.), Point::new(0., 1.), ]; let mut tour = Tour::from(&nodes); tour.optimize_kopt(time::Duration::from_secs(1));
pub fn optimize_nn(&mut self) where
T: Metrizable + Clone,
[src]
T: Metrizable + Clone,
Constructs a tour inplace using the nearest neighbor heuristic
Examples
use tsp_rs::Tour; use tsp_rs::point::Point; let nodes = vec![ Point::new(0., 0.), Point::new(1., 0.), Point::new(1., 1.), Point::new(0., 1.), ]; let mut tour = Tour::from(&nodes); tour.optimize_nn();
Trait Implementations
impl<T: Clone + Metrizable> Clone for Tour<T>
[src]
fn clone(&self) -> Tour<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: PartialEq + Metrizable> PartialEq<Tour<T>> for Tour<T>
[src]
impl<T: Debug + Metrizable> Debug for Tour<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,