title: ‘Resource Allocation LP Problem: Blue Ridge Hot Tubs’
pdf_document: default
html_document: default
Copyright By PowCoder代写 加微信 powcoder
“`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Two popular R packages for solving linear programming models are: lpSolve and lpSolveAPI. Make sure you have them installed.
#install.packages(‘lpSolve’)
#install.packages(‘lpSolveAPI’)
library(lpSolveAPI)
**Resource Allocation LP Problem: Blue Ridge Hot Tubs**
Blue Ridge Hot Tubs produces two types of hot tubs: Aqua-Spas & Hydro-Luxes. , owner-operator of the company, needs to decide how many of each type of hot tub to produce during the next production cycle.
Howie buys prefabricated fiberglass hot tub shells from a local supplier and adds the pump and tubing to the shells to create his hot tubs. Howie installs the same type of pump into both hot tub models. He will have only 200 pumps available for the next production rub. In manufacturing the hot tubs, the main difference between the Aqua-Spa and Hydro-Lux models is the amount of tubing and labor required. Each Aqua-Spa requires 9 hours of labor and 12 feet of tubing. Each Hydro-Lux requires 6 hours of labor and 16 feet of tubing. Howie expects to have 1,566 production labor hours and 2,880 feet of tubing available.
Howie earns a profit of \$350 on each Aqua-Spa he sells and \$300 on each Hydro-Lux he sells. How many of each model hot tub should Blue Ridge produce in order to maximize profits during the next production cycle?
Let X1 = # of Aquq-Spa models and X2 = # of Hydro-Lux models.
Maximize 350(X1) + 300(X2)
subject to:
1(X1) + 1(X2) <= 200
9(X1) + 6(X2) <= 1566
12(X1) + 16(X2) <= 2800
```{r include=FALSE}
## We have 2 decision variables and 3 constraints
model <- make.lp(3,2)
lp.control(model, sense = "max")
A common convention for defining the model constraints in lpSolve is by column.
## columns of constraints
set.column(model, 1, c(1, 9, 12))
set.column(model, 2, c(1, 6, 16))
## vector for comparison operators in constraints
set.constr.type(model, c(rep("<=",3)))
## vector for right hand side of constraints
set.rhs(model, c(200,1566,2880))
## Now set objective function
set.objfn(model, c(350, 300))
##Set type of decision variables, if desired.
## Choices are "integer" and "binary". Default is "Real" (continuous)
set.type(model, c(1:2), 'integer')
## You can set the names of the constraints (rows) and decision variables (columns), if desired.
dimnames(model) <- list(c('pumps', 'labor', 'tubing'), c('Aqua-Spa', 'Hydro-Lux'))
## Solve the model
solve(model)
Common status codes:
0 - optimal solution found
1 - model sub-optimal
2 - model infeasible
3 - model unbounded
7 - timeout
## retrieve optimal solution
get.variables(model)
## retrieve objective function value at optimal solution
get.objective(model)
## retrieve constraint values at optimal solution
get.constraints(model)
## retrieve sensitivity values
get.sensitivity.rhs(model)
get.sensitivity.obj(model)
```{r include=FALSE}
## Add Typhoon-Lagoon at $320 unit profit
model2 <- make.lp(3,3)
lp.control(model2, sense = "max")
set.column(model2, 1, c(1, 9, 12))
set.column(model2, 2, c(1, 6, 16))
set.column(model2, 3, c(1, 8, 13))
set.constr.type(model2, c(rep("<=",3)))
set.rhs(model2, c(200,1566,2880))
set.objfn(model2, c(350, 300, 320))
set.type(model2, c(1:3), 'integer')
dimnames(model2) <- list(c('pumps', 'labor', 'tubing'), c('Aqua-Spa', 'Hydro-Lux', 'Typhoon-Lagoon'))
solve(model2)
get.variables(model2)
get.objective(model2)
get.sensitivity.rhs(model2)
get.sensitivity.obj(model2)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com