计算机代写 title: “Lease Plan LP”

title: “Lease Plan LP”
pdf_document: default
html_document: default

Copyright By PowCoder代写 加微信 powcoder

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

library(lpSolveAPI)
library(dplyr)

A movie production company will be shooting on location in Atlanta, GA for five months. During this time period, the production company will require storage space for its sets, props and costumes, which it can lease from a local warehouse. The warehouse leases storage space by the square foot, at prices shown in Table 1 below, depending on the duration of the lease. The warehouse will allow the production company to have multiple leases for space in any particular month and to lease space starting in any month for any duration. For example, the production company could sign a 3 month lease for 30,000 sq ft in month 1 and then add 1 month lease for an additional 20,000 sq ft in month 3.

**Table 1: Lease Cost**

|Cost per sq. ft.|Lease Duration|
|:——:|:———:|
|\$ 65 |1 month|
|\$ 100 |2 months|
|\$ 135 |3 months|
|\$ 160 |4 months|
|\$ 190 |5 months|

The production company has varying needs for storage space over the course of the five month shoot. The space they estimate they will need in each month is shown in Table 2.

**Table 2: Space Required**

|Month|Sq. Ft.|
|:——:|:———:|
|1 |30,000|
|2 |20,000|
|3 |40,000|
|4 |10,000|
|5 |50,000|

Formulate and solve a LP model to determine the optimal leasing plan for the production company, in order to have all the storage space it needs in each month at the minimum cost.

durations <- c(1:5) months <- c(1:5) start_month <- 1 end_month <- 5 space_required <- data.frame(month = months, space = c(30000, 20000, 40000, 10000, 50000)) cost_per_sqft <- data.frame(duration = durations, cost = c(65, 100, 135, 160, 190)) cost_per_sqft leases <- data.frame(lease = apply(expand.grid(durations, months), 1, paste, collapse="_"), duration = rep(durations, length(months)), month = rep(months, each = length(durations))) leases <- subset(leases, month + duration - 1 <= end_month) leases <- merge(leases, cost_per_sqft) leases <- leases %>%
select(lease, duration, month, cost) %>%
arrange(month, duration)

model <- make.lp(length(months), nrow(leases)) ## a note on creating the columns c(rep(0, m - 1), rep(1, d), rep(0, end_month - (m + d - 1))) for (i in 1:nrow(leases)){ m <- leases[i, 'month'] d <- leases[i, 'duration'] set.column(model, i, c(rep(0, m - 1), rep(1, d), rep(0, end_month - (m + d - 1)))) set.constr.type(model, c(rep(">=”,length(months))))
set.constr.value(model, rhs = space_required$space)

## set objective function
set.objfn(model, leases$cost)
set.type(model, c(1:nrow(leases)), “integer”)

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