| Title: | Heuristic Capacitated Vehicle Routing Problem Solver | 
| Version: | 0.3.0 | 
| Description: | Implements the Clarke-Wright algorithm to find a quasi-optimal solution to the Capacitated Vehicle Routing Problem. See Clarke, G. and Wright, J.R. (1964) <doi:10.1287/opre.12.4.568> for details. The implementation is accompanied by helper functions to inspect its solution. | 
| License: | GPL (≥ 3) | 
| Encoding: | UTF-8 | 
| RoxygenNote: | 7.3.2 | 
| LinkingTo: | cpp11 | 
| SystemRequirements: | C++17 | 
| URL: | https://github.com/lschneiderbauer/heumilkr, https://lschneiderbauer.github.io/heumilkr/ | 
| BugReports: | https://github.com/lschneiderbauer/heumilkr/issues | 
| Imports: | rlang (≥ 1.1.0), cli (≥ 3.6.0), xml2 (≥ 1.3.0), ggplot2 (≥ 3.4.0) | 
| Suggests: | testthat (≥ 3.0.0), hedgehog (≥ 0.1), curl (≥ 5.2.0), ggExtra (≥ 0.10.0), scales (≥ 1.3.0), knitr, rmarkdown | 
| Config/testthat/edition: | 3 | 
| Depends: | R (≥ 3.5.0) | 
| LazyData: | true | 
| VignetteBuilder: | knitr | 
| NeedsCompilation: | yes | 
| Packaged: | 2025-04-24 08:09:50 UTC; lukas | 
| Author: | Lukas Schneiderbauer [aut, cre, cph] | 
| Maintainer: | Lukas Schneiderbauer <lukas.schneiderbauer@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2025-04-24 08:30:02 UTC | 
Create ggplot for a CVRP solution
Description
Represents the sites and runs on a 2D plane so that the distances between
sites on the drawn 2D plane correspond to distances provided to the
solver clarke_wright().
The individual runs are distinguished by color. The demanding site locations are marked with round circles while the (single) supplying site is depicted as a square. The line types (solid/dashed/...) are associated to different vehicle types.
Usage
## S3 method for class 'heumilkr_solution'
autoplot(object, ...)
Arguments
object | 
 A "  | 
... | 
 Not used.  | 
Details
Distance information between sites only determine site positions on a 2D plane up to rotations and translations: those are fixed arbitrarily.
Value
A ggplot object.
Clarke-Wright algorithm, a Capacitated Vehicle Routing Problem solver
Description
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.
Usage
clarke_wright(
  demand,
  distances,
  vehicles,
  restrictions = data.frame(vehicle = integer(), site = integer())
)
Arguments
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   | 
Details
See the original paper, Clarke, G. and Wright, J.R. (1964) doi:10.1287/opre.12.4.568, for a detailed explanation of the Clarke-Wright algorithm.
Value
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 thedemandvector) 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 invehicles) associated to the run. -  
load- The actual load in units ofdemandon 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.
Examples
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)
)
Apply clarke_wright() to CVRPLIB data
Description
Apply clarke_wright() to CVRPLIB data
Usage
clarke_wright_cvrplib(instance)
Arguments
instance | 
 A "  | 
Value
A "heumilkr_solution" object. See clarke_wright().
See Also
Other cvrplib: 
cvrplib_download(),
cvrplib_ls()
Examples
clarke_wright_cvrplib(cvrplib_A[[1]])
CVRP instance data by Augerat, 1995
Description
A collection of CVRP instances by Augerat, 1995, provided courtesy of CVRPLIB. See CVRPLIB for visualizations of the instances and their solutions as well as a multitude of alternative instance data.
Usage
cvrplib_A
Format
cvrplib_A
A list of CVRP instances as "cvrplib_instance" objects. The instances
can be directly fed into solver algorithm, e.g. via clarke_wright_cvrplib().
Source
http://vrp.atd-lab.inf.puc-rio.br
CVRP instance data by Augerat, 1995
Description
A collection of CVRP instances by Augerat, 1995, provided courtesy of CVRPLIB. See CVRPLIB for visualizations of the instances and their solutions as well as a multitude of alternative instance data.
Usage
cvrplib_B
Format
cvrplib_B
A list of CVRP instances as "cvrplib_instance" objects. The instances
can be directly fed into solver algorithm, e.g. via clarke_wright_cvrplib().
Source
http://vrp.atd-lab.inf.puc-rio.br
CVRP instance data by Christofides and Eilon, 1969
Description
A collection of CVRP instances by Christofides and Eilon, 1969, provided courtesy of CVRPLIB. See CVRPLIB for visualizations of the instances and their solutions as well as a multitude of alternative instance data.
Usage
cvrplib_E
Format
cvrplib_E
A list of CVRP instances as "cvrplib_instance" objects. The instances
can be directly fed into solver algorithm, e.g. via clarke_wright_cvrplib().
Source
http://vrp.atd-lab.inf.puc-rio.br
CVRP instance data by Fisher, 1994
Description
A collection of CVRP instances by Fisher, 1994, provided courtesy of CVRPLIB. See CVRPLIB for visualizations of the instances and their solutions as well as a multitude of alternative instance data.
Usage
cvrplib_F
Format
cvrplib_F
A list of CVRP instances as "cvrplib_instance" objects. The instances
can be directly fed into solver algorithm, e.g. via clarke_wright_cvrplib().
Source
http://vrp.atd-lab.inf.puc-rio.br
CVRP instance data by Rochat and Taillard, 1995
Description
A collection of CVRP instances by Rochat and Taillard, 1995, provided courtesy of CVRPLIB. See CVRPLIB for visualizations of the instances and their solutions as well as a multitude of alternative instance data.
Usage
cvrplib_Tai
Format
cvrplib_Tai
A list of CVRP instances as "cvrplib_instance" objects. The instances
can be directly fed into solver algorithm, e.g. via clarke_wright_cvrplib().
Source
http://vrp.atd-lab.inf.puc-rio.br
CVRPLIB problem instance downloader
Description
CVRLIB offers a selection of
CVRP problem instances. This function downloads the instance data and
conveniently makes it available to be fed into solver functions, e.g. with
clarke_wright_cvrplib(). The primary purpose for those instances is
benchmarking / comparing speed as well as performance of solvers.
Usage
cvrplib_download(qualifier)
Arguments
qualifier | 
 The qualifier of the problem instance. E.g. "tai/tai150d".
This can either be inferred directly from the website or by the output of
  | 
Value
Returns a "cvrplib_instance" object which contains CVRPLIB problem
instance data.
See Also
Other cvrplib: 
clarke_wright_cvrplib(),
cvrplib_ls()
List available CVRPLIB online data
Description
Scrapes the CVRPLIB website to look for available data sets. This function call can take some time.
Usage
cvrplib_ls()
Value
A vector of data set qualifiers which can be used with cvrplib_download().
See Also
Other cvrplib: 
clarke_wright_cvrplib(),
cvrplib_download()
Vehicle runs cost / distance
Description
Calculates the total distance associated to a clarke_wright() result.
This is the measure that the corresponding Capacitated Vehicle Routing
Problem minimizes.
Usage
milkr_cost(solution)
Arguments
solution | 
 A "  | 
Value
The total traveled distance.
Examples
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)
  )
solution <- clarke_wright(
  demand,
  dist(positions),
  data.frame(n = NA_integer_, caps = 6)
)
milkr_cost(solution)
Vehicle run saving
Description
Measures the saving that was achieved by the heuristic optimization
algorithm clarke_wright() compared to the naive vehicle run assignment,
i.e. one run per site.
Usage
milkr_saving(solution, relative = FALSE)
Arguments
solution | 
 A "  | 
relative | 
 Should the saving be given as dimensionful value (in units of distance as
provided to   | 
Value
The savings either as dimensionful value or as percentage relative to the
naive costs, depending on relative.
Examples
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)
  )
solution <- clarke_wright(
  demand,
  dist(positions),
  data.frame(n = NA_integer_, caps = 6)
)
print(milkr_saving(solution))
print(milkr_saving(solution, relative = TRUE))
Plot a CVRP solution
Description
Represents the sites and runs on a 2D plane so that the distances between
sites on the drawn 2D plane correspond to distances provided to the
solver clarke_wright().
The individual runs are distinguished by color. The demanding site locations are marked with round circles while the (single) supplying site is depicted as a square. The line types (solid/dashed/...) are associated to different vehicle types.
Usage
## S3 method for class 'heumilkr_solution'
plot(x, ...)
Arguments
x | 
 A "  | 
... | 
 Not used.  | 
Details
Distance information between sites only determine site positions on a 2D plane up to rotations and translations: those are fixed arbitrarily.