View source: R/clarke_wright.R
clarke_wright | R Documentation |
Finds a quasi-optimal solution to the Capacitated Vehicle Routing Problem (CVRP). It is assumed that all demands will be satisfied by a single source.
clarke_wright(
demand,
distances,
vehicles,
restrictions = data.frame(vehicle = integer(), site = integer())
)
demand |
A numeric vector consisting of "demands" indexed by sites.
The |
distances |
An object of class |
vehicles |
A
The order of the |
restrictions |
An optional
Each row defines a restriction: vehicle type |
See the original paper, Clarke, G. and Wright, J.R. (1964) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1287/opre.12.4.568")}, for a detailed explanation of the Clarke-Wright algorithm.
Returns a "heumilkr_solution
" object, a data.frame()
with one row per
site-run combination bestowed with additional attributes. Its columns
consist of:
site
- The site index (i.e. the index of the demand
vector) associated
to the run.
run
- Identifies the run the site is assigned to.
order
- Integer values providing the visiting order within each run.
vehicle
- The vehicle type index (as provided in vehicles
) associated
to the run.
load
- The actual load in units of demand
on the particular run.
distance
- The travel distance of the particular run.
Unless a site demand exceeds the vehicle capacities it is always assigned to only a single run.
demand <- c(3, 2, 4, 2)
positions <-
data.frame(
pos_x = c(0, 1, -1, 2, 3),
pos_y = c(0, 1, 1, 2, 3)
)
clarke_wright(
demand,
dist(positions),
data.frame(n = NA_integer_, caps = 6)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.