pub struct Tour<T: Metrizable> {
pub path: Vec<T>,
}
Expand description
Represents a solution to the tsp for the items T
Fields§
§path: Vec<T>
Implementations§
Source§impl<T: Metrizable + Clone + Borrow<T>> Tour<T>
impl<T: Metrizable + Clone + Borrow<T>> Tour<T>
Sourcepub fn new() -> Tour<T>
pub fn new() -> Tour<T>
Returns a new, empty Tour
§Example
use tsp_rs::Tour;
use tsp_rs::point::Point;
let tour: Tour<Point> = Tour::new();
Sourcepub fn from(nodes: &Vec<T>) -> Tour<T>where
T: Clone,
pub fn from(nodes: &Vec<T>) -> Tour<T>where
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);
Sourcepub fn tour_len(&self) -> f64
pub fn tour_len(&self) -> f64
Returns the length of a tour.
§Example
let tour = Tour::from(&some_points); let total_cost = tour.tour_len();
Sourcepub fn optimize_kopt(&mut self, timeout: Duration)
pub fn optimize_kopt(&mut self, timeout: Duration)
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));
Sourcepub fn optimize_nn(&mut self)where
T: Metrizable + Clone,
pub fn optimize_nn(&mut self)where
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: Metrizable> StructuralPartialEq for Tour<T>
Auto Trait Implementations§
impl<T> Freeze for Tour<T>
impl<T> RefUnwindSafe for Tour<T>where
T: RefUnwindSafe,
impl<T> Send for Tour<T>where
T: Send,
impl<T> Sync for Tour<T>where
T: Sync,
impl<T> Unpin for Tour<T>where
T: Unpin,
impl<T> UnwindSafe for Tour<T>where
T: UnwindSafe,
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