Optimization
Home Work - Week 1
Email : je070601@gmail.com
RPubs : https://rpubs.com/invokerarts/
Github : https://github.com/invokerarts
Majors : Business Statistics
Address : ARA Center, Matana University Tower Jl. CBD Barat Kav, RT.1, Curug Sangereng,
Kelapa Dua, Tangerang, Banten 15810.
# install.packages("lpSolve")
# Load lpSolve
library(lpSolve)
## koefisien variabel / fungsi objectif
Cost <- c(30, 40, 80)
# Buat matrix sebelah kiri
Bahan <- matrix(c(1, 1, -10,
4, 3, -20,
1, 0, -2,
1, 1, 0), nrow=4, byrow=TRUE)
# Buat matrix sebelah kanan
Batas <- c(500, 200, 100, 1000)
# set operator perbandingannya
constranints_direction <- c("<=", "<=", "<=", ">=")
# panggil fungsi linear programming
optimum <- lp(direction="min", #minimalkan biaya
objective.in = Cost,
const.mat = Bahan,
const.dir = constranints_direction,
const.rhs = Batas,
all.int = T)
# jika menghasilkan 0 maka feasible!
print(optimum$status)## [1] 0
# nilai optimal dari A, B and t
best_sol <- optimum$solution
names(best_sol) <- c("A", "B", "t")
print(best_sol)## A B t
## 420 580 161
#fungsi biaya
print(paste("Total cost: ", optimum$objval, sep=""))## [1] "Total cost: 48680"