-
Notifications
You must be signed in to change notification settings - Fork 24
/
5e2-LP-machassign.R
52 lines (47 loc) · 1.2 KB
/
5e2-LP-machassign.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#----------------------------------------------#
#Another Method
#https://cran.r-project.org/web/packages/lpSolveAPI/lpSolveAPI.pdf
#https://ecreee.wikischolars.columbia.edu/file/view/lpSolveAPI+Tutorial.Rmd
library(lpSolveAPI)
#First we create an empty model x.
?make.lp
#max: x + y - 50
lprec <- make.lp(0, 2)
lprec
set.objfn(lprec, c(1, 1))
lprec
#maximise it
lp.control(lprec, sense="max")
lprec
#set.type(lprec, c(1,2), type = c("integer"))
lprec
#50x + 24y <= 2400
add.constraint(lprec, c(50,24), "<=", 2400)
lprec
#30x + 33y <= 2100
add.constraint(lprec, c(30,33), "<=", 2100)
lprec
#x >= 45
#add.constraint(lprec, c(1,0), ">=", 45)
#lprec
#y >= 5
#add.constraint(lprec, c(0,1), ">=", 5)
#lprec
#50 >= x + y
add.constraint(lprec, c(1,1), ">=", 50)
lprec
set.bounds(lprec, lower = c(45, 5), columns = c(1, 2))
lprec
#set.bounds(lprec, upper = 48.98, columns = 4)
#RowNames <- c("MachineA", "MachineB","InitalA", "InitalB","TotalInitial")
RowNames <- c("MachineA", "MachineB","TotalInitial")
ColNames <- c("ProductX", "ProductY")
dimnames(lprec) <- list(RowNames, ColNames)
lprec
solve(lprec) #[1] 0 ok
#get.dual.solution(lprec)
get.objective(lprec)
get.variables(lprec)
get.constraints(lprec)
plot(lprec)
print(lprec)