[][src]Struct tsp_rs::Tour

pub struct Tour<T: Metrizable> {
    pub path: Vec<T>,
}

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]

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]

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: PartialEq + Metrizable> PartialEq<Tour<T>> for Tour<T>[src]

impl<T: Clone + Metrizable> Clone for Tour<T>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Debug + Metrizable> Debug for Tour<T>[src]

Auto Trait Implementations

impl<T> Send for Tour<T> where
    T: Send

impl<T> Sync for Tour<T> where
    T: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.