CS代考 title: “Set-Covering ILP”

title: “Set-Covering ILP”
pdf_document: default
html_document: default

Copyright By PowCoder代写 加微信 powcoder

“`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(lpSolveAPI)
library(dplyr)

The greater metropolitan area of Easton, IL includes 17 suburbs that are serviced by the and Rescue Department. Because of the proximities of some of the suburbs, one suburb’s fire station may serve neighboring communities. The requirement is that the station must be closer than a 15 minute drive from any suburb that it serves. The data file FireStations_DriveTimes.csv contains the drive times in minutes between the 17 suburbs.

Formulate an ILP to identify the smallest number of stations that will cover the area. Where are they located?

data <- read.csv(file.choose()) min_time <- 15 matrix <- data[ ,-1] matrix[matrix < 15] <- 1 matrix[matrix >= 15] <- 0 matrix$Suburb <- data$Suburb matrix <- matrix %>% select(‘Suburb’, everything())

suburbs <- data$Suburb model <- make.lp(length(suburbs), length(suburbs)) for (i in 1:length(suburbs)){ set.column(model, i, matrix[, i+1]) set.constr.type(model, c(rep(">=”,length(suburbs))))
set.constr.value(model, rhs = rep(1, length(suburbs)))

## set objective function
set.objfn(model, rep(1, length(suburbs)))
set.type(model, c(1:length(suburbs)), “binary”)

## name variables
dimnames(model)[[2]] <- suburbs write.lp(model, filename = 'model.lp') solve(model) num_stations <- get.objective(model) num_stations stations_located <- get.variables(model) names(stations_located) <- suburbs stations_located get.constraints(model) 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com