Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tour_length

Calculate the length of a tour


Description

Calculate the length of a tour given a TSP and an order.

Usage

tour_length(x, ...)
## S3 method for class 'TOUR'
tour_length(x, tsp = NULL, ...)

Arguments

x

an object of class TOUR.

tsp

a TSP object of class TSP, ATSP or ETSP.

...

further arguments are currently unused.

Details

If no tsp is given, then the tour length stored in x as attribute "tour_length" is returned. If tsp is given then the tour length is recalculated.

If a distance in the tour is infinite, the result is also infinite. If the tour contains positive and negative infinite distances then the method returns NA.

Author(s)

Michael Hahsler

See Also

TOUR, TSP, ATSP and ETSP.

Examples

data("USCA50")

## original order
tour_length(solve_TSP(USCA50, method="identity"))

## length of a manually created (random) tour
tour <- TOUR(sample(seq(n_of_cities(USCA50))))
tour
tour_length(tour)
tour_length(tour, USCA50)

TSP

Traveling Salesperson Problem (TSP)

v1.1-10
GPL-3
Authors
Michael Hahsler [aut, cre, cph], Kurt Hornik [aut, cph]
Initial release
2020-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.