pub struct TspInstance {
pub name: String,
pub dimension: usize,
pub comment: Option<String>,
pub edge_weight_type: EdgeWeightType,
pub coords: Option<Vec<(f64, f64)>>,
pub distances: Vec<Vec<f64>>,
pub best_known: Option<f64>,
}Expand description
A TSP problem instance
Fields§
§name: StringInstance name
dimension: usizeNumber of cities
comment: Option<String>Optional comment
edge_weight_type: EdgeWeightTypeEdge weight type
coords: Option<Vec<(f64, f64)>>City coordinates (if available)
distances: Vec<Vec<f64>>Distance matrix (computed or explicit)
best_known: Option<f64>Best known solution length (if available)
Implementations§
Source§impl TspInstance
impl TspInstance
Sourcepub fn from_coords(name: &str, coords: Vec<(f64, f64)>) -> TspResult<Self>
pub fn from_coords(name: &str, coords: Vec<(f64, f64)>) -> TspResult<Self>
Create a new TSP instance from coordinates
Sourcepub fn from_matrix(name: &str, distances: Vec<Vec<f64>>) -> TspResult<Self>
pub fn from_matrix(name: &str, distances: Vec<Vec<f64>>) -> TspResult<Self>
Create a new TSP instance from a distance matrix
Sourcepub fn num_cities(&self) -> usize
pub fn num_cities(&self) -> usize
Get number of cities
Sourcepub fn tour_length(&self, tour: &[usize]) -> f64
pub fn tour_length(&self, tour: &[usize]) -> f64
Calculate tour length
Sourcepub fn validate_tour(&self, tour: &[usize]) -> TspResult<()>
pub fn validate_tour(&self, tour: &[usize]) -> TspResult<()>
Validate a tour
Sourcepub fn nearest_neighbor_rank(&self, i: usize, j: usize) -> usize
pub fn nearest_neighbor_rank(&self, i: usize, j: usize) -> usize
Get nearest neighbor rank of city j from city i
Trait Implementations§
Source§impl Clone for TspInstance
impl Clone for TspInstance
Source§fn clone(&self) -> TspInstance
fn clone(&self) -> TspInstance
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TspInstance
impl RefUnwindSafe for TspInstance
impl Send for TspInstance
impl Sync for TspInstance
impl Unpin for TspInstance
impl UnwindSafe for TspInstance
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more