Learn R Programming

TSP (version 1.0-4)

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, order)

Arguments

x
an object of class TSP or ATSP.
order
optional order of the visited cities as a integer vector or an object of class TOUR. If no order is given, the cities are visited in the original order in x.

Details

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

See Also

TSP, ATSP, TOUR.

Examples

Run this code
data("USCA50")

## original order
tour_length(USCA50)

## random tour
tour_length(USCA50, sample(1:n_of_cities(USCA50)))

Run the code above in your browser using DataLab