-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLa2_Rscript.R
More file actions
206 lines (159 loc) · 6.56 KB
/
Copy pathLa2_Rscript.R
File metadata and controls
206 lines (159 loc) · 6.56 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
library(lpSolve)
# Coefficients from min F(x)
Fun <- c(10, 4, 8, 6, 2, 3, 8, 2, 6, 6)
# Boarders (coefficients near limitations)
A <- rbind(c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0), # 1'st claster
c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0), # 2'nd claster
c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1), # 3'th claster
c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), # total sum = 1000
c(10, 4, 8, 6, -2, -3, 0, 0, 0, 0), # сriterion of simultaneous completion of work
c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), # sum data proceeding >= 700
c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), # x1 <= 700
c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0), # x2 >= 700
c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0), # x3 >= 700
c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0), # x4 >= 700
c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0), # x5 <= 700
c(0, 0, 0, 0, 0, 1, 0, 0, 0, 0), # x6 <= 700
c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0), # x7 <= 700
c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0), # x8 <= 700
c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0), # x9 <= 700
c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)) # x10 <= 700
# The right sides
B <- c(400, 800, 600, 1000, 0, 700,
700, 700, 700, 700, 700, 700, 700, 700, 700, 700)
# Signs
CD <- c("<=", "<=", "<=", "=", "=", ">=",
"<=", "<=", "<=", "<=", "<=", "<=", "<=", "<=", "<=", "<=")
optimum <- lp(
direction = "min",
objective.in = Fun,
const.mat = A,
const.dir = CD,
const.rhs = B,
compute.sens = TRUE)
optimum
optimum$solution
library(lpSolveAPI)
# Create function with 10 features & 0 limitations
lprob <- make.lp(0, 10)
# Try to minimaze resualt
stub <- lp.control(lprob, sense = "min")
rm(stub)
add.constraint(lprob, c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0), "<=", 400)
add.constraint(lprob, c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0), "<=", 800)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1), "<=", 600)
add.constraint(lprob, c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), "=", 1000)
add.constraint(lprob, c(10, 4, 8, 6, -2, -3, 0, 0, 0, 0), "=", 0)
add.constraint(lprob, c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ">=", 700)
add.constraint(lprob, c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 1, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1), "<=", 700)
set.objfn(lprob, c(10, 4, 8, 6, 2, 3, 8, 2, 6, 6))
lprob
# Solve
status_code <- solve(lprob)
time_request_target <- get.objective(lprob)
time_request_target
time_request_variables <- get.variables(lprob)
time_request_variables
# Sensitive
original_options <- options(digits = 3, scipen = 30)
time_request_sensetive <- sensitivity_results <- get.sensitivity.obj(lprob)
for (i in 1:length(sensitivity_results$objfrom)) {
cat(paste("x", i, "\t| [", sensitivity_results$objfrom[i], ", ", sensitivity_results$objtill[i], "]\n", sep = ""))
}
get.sensitivity.rhs(lprob)
optimum$sens.coef.from
optimum$sens.coef.to
# Dismiss сriterion of simultaneous completion of work
library(lpSolveAPI)
# Create function with 10 features & 0 limitations
lprob <- make.lp(0, 10)
# Try to minimaze resualt
stub <- lp.control(lprob, sense = "min")
rm(stub)
add.constraint(lprob, c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0), "<=", 400)
add.constraint(lprob, c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0), "<=", 800)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1), "<=", 600)
add.constraint(lprob, c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), "=", 1000)
# add.constraint(lprob, c(10, 4, 8, 6, -2, -3, 0, 0, 0, 0), "=", 0)
add.constraint(lprob, c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ">=", 700)
add.constraint(lprob, c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 1, 0, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0), "<=", 700)
add.constraint(lprob, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1), "<=", 700)
set.objfn(lprob, c(10, 4, 8, 6, 2, 3, 8, 2, 6, 6))
lprob
# Solve
status_code <- solve(lprob)
non_time_request_target <- get.objective(lprob)
non_time_request_target
non_time_request_varibles <- get.variables(lprob)
non_time_request_varibles
# Sensitive
original_options <- options(digits = 3, scipen = 30)
non_time_request_sensetive <- sensitivity_results <- get.sensitivity.obj(lprob)
for (i in 1:length(sensitivity_results$objfrom)) {
cat(paste("x", i, "\t| [", sensitivity_results$objfrom[i], ", ", sensitivity_results$objtill[i], "]\n", sep = ""))
}
optimum$sens.coef.from
optimum$sens.coef.to
# n computer out of work
n <- 5
q_coefs <- c(10, 4, 8, 6, 2, 3, 8, 2, 6, 6)
cluster_1 <- c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0)
cluster_2 <- c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0)
cluster_3 <- c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1)
whole_sum <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
cluster_1[n] <- 0
cluster_2[n] <- 0
cluster_3[n] <- 0
whole_sum[n] <- 0
# Create function with 10 features & 0 limitations
lprob <- make.lp(0, 10)
# Try to minimaze resualt
stub <- lp.control(lprob, sense = "min")
rm(stub)
add.constraint(lprob, cluster_1, "<=", 400)
add.constraint(lprob, cluster_2, "<=", 800)
add.constraint(lprob, cluster_3, "<=", 600)
add.constraint(lprob, whole_sum, "=", 1000)
add.constraint(lprob, whole_sum, ">=", 700)
for (i in 1:10) {
this_computer <- rep(0, 10)
this_computer[i] <- 1
if (i != n){
add.constraint(lprob, this_computer, "<=", 700)
} else {
add.constraint(lprob, this_computer, "=", 0)
}
}
set.objfn(lprob, q_coefs)
lprob
# Solve
status_code <- solve(lprob)
n_out_of_work_target <- get.objective(lprob)
n_out_of_work_target
n_out_of_work_varibles <- get.variables(lprob)
n_out_of_work_varibles
# Sensitive
original_options <- options(digits = 3, scipen = 30)
n_out_of_work_sensetive <- sensitivity_results <- get.sensitivity.obj(lprob)
for (i in 1:length(sensitivity_results$objfrom)) {
cat(paste("x", i, "\t| [", sensitivity_results$objfrom[i], ", ", sensitivity_results$objtill[i], "]\n", sep = ""))
}
optimum$sens.coef.from
optimum$sens.coef.to