-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkshop7.R
More file actions
109 lines (65 loc) · 2.65 KB
/
Workshop7.R
File metadata and controls
109 lines (65 loc) · 2.65 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
### Linear programming
## Maximize z = 3s + 2t aka objective function
# constraint 2s + t <= 100
# constraint s + t <= 80
# constraint s <= 80
# constraint s,t >=0
# plot graph for constraints on an online plotting tool
# point 40,20 satisfies the all teh constraints
# hence max z = 3(40) + 2(20) = 160
## Minimize z = 1470-12x-19y aka objective function
# constraint 3x+6y <= 540
# constraint 5x+5y <=450
# constraint 4x+8y <=480
# constraint x,y >=0
# plot them and we see that 60, 30 point satisfies all the conditions.
# hence min z = 1470-12(60)-19(30) = 180
## minmize z = 10f1 + 3f2
# constraints 3f1 + 2f2 >= 60
# constraints 7f1 + 2f2 >= 84
# constraints 3f1 + 6f2 >= 72
# after plotting we check for interesection of all lines,
# one of those point satisfies all the constraints
# if multiple points satisfy the constrainsts,
# for each, substitue in our object function and compare values
# the one that gives minimum value is our point.
# plot has points 18,3 and 6,21 that satisfy constraints, out of which 6,21 give min value.
# SIT718 - Two Variable LP programming
# The following script provide solutions for two examples used in week 7
# 7.5 - Toy Company Problem
library(lpSolveAPI)
toyCompanyModel <- make.lp(0, 2)
lp.control(toyCompanyModel, sense= "maximize")
set.objfn(toyCompanyModel, c(3,2))
add.constraint(toyCompanyModel, c(2,1), "<=", 100)
add.constraint(toyCompanyModel, c(1,1), "<=", 80)
set.bounds(toyCompanyModel, lower = c(0,0), columns = c(1, 2))
set.bounds(toyCompanyModel, upper = 40, columns = 1)
RowNames <- c("Constraint 1", "Constraint 2")
ColNames <- c("Soldiers", "Trains")
dimnames(toyCompanyModel) <- list(RowNames, ColNames)
solve(toyCompanyModel) # http://lpsolve.sourceforge.net/5.5/solve.htm
get.objective(toyCompanyModel)
get.variables(toyCompanyModel)
get.constraints(toyCompanyModel)
toyCompanyModel
##############################
# 7.6 - Assembly Line Problem
library(lpSolveAPI)
assemblyModel <- make.lp(0, 2) # two variables
lp.control(assemblyModel, sense= "maximize")
set.objfn(assemblyModel, c(12,19))
add.constraint(assemblyModel, c(3,6), "<=", 540)
add.constraint(assemblyModel, c(5,5), "<=", 450)
add.constraint(assemblyModel, c(4,8), "<=", 480)
set.bounds(assemblyModel, lower = c(0,0), columns = c(1, 2))
# set.bounds(assemblyModel, upper = 40, columns = 1)
RowNames <- c("Constraint 1", "Constraint 2")
ColNames <- c("Smart-1", "Smart-2")
dimnames(assemblyModel) <- list(RowNames, ColNames)
solve(assemblyModel) # http://lpsolve.sourceforge.net/5.5/solve.htm
get.objective(assemblyModel)
get.variables(assemblyModel)
get.constraints(assemblyModel)
assemblyModel
##############################