| route_tsp | R Documentation |
Solves fixed-start routing problems over an sf layer. By default the route
is closed (start and end at the same location), but open routes and fixed
start/end paths are also supported. Optional time windows can be supplied in
the same units as the travel-time matrix.
route_tsp(
locations,
depot = 1L,
start = NULL,
end = NULL,
cost_matrix = NULL,
distance_metric = "euclidean",
method = "2-opt",
earliest = NULL,
latest = NULL,
service_time = NULL
)
locations |
An sf object representing locations to visit. |
depot |
Integer. Backward-compatible alias for |
start |
Integer. Row index of the route start in |
end |
Integer or NULL. Row index of the route end in |
cost_matrix |
Optional. Pre-computed square distance/cost matrix (n x n).
If NULL, computed from |
distance_metric |
Distance metric when computing from geometry: "euclidean" (default) or "manhattan". |
method |
Algorithm: "2-opt" (default, nearest-neighbor + local search) or "nn" (nearest-neighbor only). |
earliest |
Optional earliest arrival/service times. Supply either a
numeric vector of length |
latest |
Optional latest arrival/service times. Must be supplied
together with |
service_time |
Optional service duration at each stop. Supply either a
numeric vector of length |
Supported route variants:
Closed tour: start = 1, end = 1 (default)
Open route: start = 1, end = NULL
Fixed path: start = 1, end = 5
Time windows use the same units as cost_matrix. When windows are supplied,
the solver constructs a feasible route and only accepts local-search moves
that preserve feasibility.
An sf object (the input locations) with added columns:
.visit_order: Visit sequence (1 = route start)
.tour_position: Position in the returned tour/path
.arrival_time: Arrival/service start time at each visited stop
.departure_time: Departure time after service
Metadata is stored in the "spopt" attribute, including total_cost,
nn_cost, improvement_pct, tour, start, end, route_type,
and solve_time.
route_vrp() for multi-vehicle routing, distance_matrix() for
computing cost matrices
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.