knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  dpi = 300
)

Zoning for Autonomous Vehicles

The goal of zav (Zoning for Autonomous Vehicles) is to show the implementation of the problem instance generation and simulation experiment conducted for the project.

Installation

You can install the development version of zav from GitHub with:

# install.packages("devtools")
# note that there is a GitHub only dependency
# devtools::install_github("cuhklinlab/SWKM")
devtools::install_github("Rosenkrands/zav")

Instance generation

To generate a problem instance we can utilize the generate_2d_instance function.

library(zav)
library(ggplot2)
library(dplyr)

instance <- generate_2d_instance(no_of_points = 100)

plot_point(instance)

Zoning solutions

Weighted K-Means

The below code chunk shows how we can utilize the solve_wkmeans function to generate a solution for our problem instance.

solution_wkm <- solve_wkmeans(instance, no_of_centers = 5, type = "swkm")
plot_bases(solution = solution_wkm)

Genetic Algorithm

The below chunk shows how we can utilize the solve_ga function to generate a solution for our problem instance.

First we need to precalculate centroids to use as input for the GA.

centroids <- grid_centroids(instance, dimension = 5)

Having now the centroids and distances between demand points and centroids, we are able to give this as input for the GA. As a default the GA will have a maximum of 10 iterations for demonstration purposes, in reality we would have a much higher number of iterations.

solution <- solve_ga(instance, centroids, no_of_centers = 5, obj = "SAFE")
plot_bases(solution)

Simulation

Here it is shown how you can make a simulation based on the solution just found.

simulation_result <- simulation(
  solution = solution_wkm,
  seed = 1,
  n_replications = 1,
  flight = "zoned",
  queue = T,
  max_dist = 1000000,
  LOS = 600,
  warmup = 0,
  speed_agent = .25,
  verbose = F
)
simulation_result$metrics[[1]]$distances %>%
  ggplot(aes(x = time, 
             y = distance,
             color = paste0(id1,'-',id2))) +
  geom_line() +
  labs(color = "Pair") +
  theme_bw() +
  theme(legend.position = "none")


Rosenkrands/zav documentation built on March 31, 2022, 2:16 p.m.