Email          : brigita.melantika@student.matanauniversity.ac.id
RPubs         : https://rpubs.com/brigitatiaraem/
Jurusan      : Statistika
Address     : ARA Center, Matana University Tower
             Jl. CBD Barat Kav, RT.1, Curug Sangereng, Kelapa Dua, Tangerang, Banten 15810.
Python : https://colab.research.google.com/drive/1FfTwlZsRXYATw_guC66JTwRd9ai05x6I?usp=sharing
Find the maximum solution
\[max \space Z=4x+3y\]
Suppose that the objective function is subject to the following constraints: \[\begin{align*} x≥0 \\ y≥2 \\ 2y≤25-x \\ 4y≤2x-8 \\ y≤2x-5 \\ \end{align*}\]
library(lpSolve)
max_z <- c(4,3)
LHS <- matrix(c(1,2,
-2,4,
-2,1,
0,1)
,ncol=2, byrow=TRUE)
arah_kendala <- c("<=","<=","<=",">=")
RHS <- c(25,-8,-5,2)
# Penyelesaian
model <- lp ("max",
max_z,
LHS,
arah_kendala,
RHS,
compute.sens = TRUE)
print(model)## Success: the objective function is 90
model$solution## [1] 21 2
provide value. There is one robot, 2 engineers and one detailer in the factory. The detailer has some holiday off, so only has 21 days available.
The 2 cars need different time with each resource:
| Resource time | Car A | Car B |
|---|---|---|
| Robot | 3 days | 4 days |
| Engineer | 5 days | 6 days |
| Detailer | 1.5 days | 3 days |
Car A provides $30,000 profit, whilst Car B offers $45,000 profit. At the moment, they produce 4 of each car per month, for $300,000 profit. Not bad at all, but we think we can do better for them.
library(lpSolve)
max_z <- c(30000,45000)
LHS <- matrix(c(3,4,
5,6,
1.5,3)
,ncol=2, byrow=TRUE)
arah_kendala <- c("<=","<=","<=")
RHS <- c(30,60,21)
# Penyelesaian
model <- lp ("max",
max_z,
LHS,
arah_kendala,
RHS,
compute.sens = TRUE)
print(model)## Success: the objective function is 330000
model$solution## [1] 2 6
library(gMOIP)
p1 <- plotPolytope(
LHS,
RHS,
max_z,
type = rep("c", ncol(LHS)),
crit = "max",
faces = rep("c", ncol(LHS)),
plotFaces = TRUE,
plotFeasible = TRUE,
plotOptimum = FALSE,
labels = NULL
) + ggplot2::ggtitle("Feasible region only")
p1Let say you would like to make some sausages and you have the following ingredients available:
| Ingredient | Cost ($/kg) | Availability (kg) |
|---|---|---|
| Chicken | 4.32 | 30 |
| Wheat | 2.46 | 20 |
| Starch | 1.86 | 17 |
Assume that you will make 2 types of sausage:
According to government regulations of Indonesia:
So, please figure out how to optimize the cost effectively to blend your sausages.
Please visualize a contour plot of the following function:
\[f(x,y)=x^2+y^2+3xy\]
f <- function(x, y) {
x^2 + y^2 + 3* x * y
}
n <- 30
xpts <- seq(-1.5, 1.5, len = n)
ypts <- seq(-1.5, 1.5, len = n)
gr <- expand.grid(x = xpts, y = ypts)
feval <- with(gr, matrix(f(x, y), nrow = n, ncol = n))
par(mar = c(5, 4, 1, 1))
contour(xpts, ypts, feval, nlevels = 20, xlab = "x", ylab = "y")
points(-1, -1, pch = 19, cex = 2)
abline(h = -1)