-
Notifications
You must be signed in to change notification settings - Fork 0
/
Group_4_Tesla_Optimization.R
274 lines (230 loc) · 12.5 KB
/
Group_4_Tesla_Optimization.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#Math Project: Mabisa Chhetry, Harshada Pujari, Khushboo Surana
#Date: 12/09/2023
library(alabama)
# ANSWER 1: Objective function to minimize
objective_function <- function(x) (60* (2* x["full_time_english_7_9"] + 2* x["full_time_spanish_7_9"] +
2*x["full_time_english_9_11"] + 2* x["full_time_spanish_9_11"] +
2* x["full_time_english_11_1"] + 2* x["full_time_spanish_11_1"]+
x["full_time_english_1_3"] + x["full_time_spanish_1_3"] +
x["full_time_english_3_5"] + x["full_time_spanish_3_5"] + x["part_time_english_3_5"]) +
90 * (2 *x["part_time_english_5_7"]+x["part_time_english_3_5"]+
x["full_time_english_1_3"]+ x["full_time_spanish_1_3"]+
+x["full_time_english_3_5"]+ x["full_time_spanish_3_5"]))
constraint_equal <- function(x) {
# equality constraints
h=0
h[1]= x["full_time_english_7_9"] + x["full_time_spanish_7_9"] - 8 # 7 A.M. – 9 A.M.
h[2]= x["full_time_english_9_11"] + x["full_time_spanish_9_11"] - 15 # 9 A.M. – 11 A.M.
h[3]= x["full_time_english_11_1"] + x["full_time_spanish_11_1"]+ x["full_time_english_7_9"]+x["full_time_spanish_7_9"] - 13 # 11 A.M. – 1 P.M.
h[4]= x["full_time_english_1_3"] + x["full_time_spanish_1_3"]+ x["full_time_english_9_11"]+ x["full_time_spanish_9_11"] - 17 # 1 P.M. – 3 P.M.
h[5]= x["full_time_english_3_5"] + x["full_time_spanish_3_5"] + x["part_time_english_3_5"]+x["full_time_english_11_1"]+ x["full_time_spanish_11_1"] - 14 # 3 P.M. – 5 P.M.
h[6]= x["part_time_english_5_7"]+ x["part_time_english_3_5"] +x["full_time_english_1_3"]+ x["full_time_spanish_1_3"] - 7 # 5PM - 7PM
h[7]= x["part_time_english_5_7"]+x["full_time_english_3_5"]+ x["full_time_spanish_3_5"] - 3 # 7PM - 9PM
return(h)
}
# Constraints
constraint_inequal <- function(x) {
# Inequality constraints
h=0
h[1]= 6 * x["full_time_english_7_9"] - 32 # 7 A.M. – 9 A.M.
h[2]= 6 * x["full_time_spanish_7_9"] - 8 # 7 A.M. – 9 A.M.
h[3]= 6 * x["full_time_english_9_11"] - 68 # 9 A.M. – 11 A.M.
h[4]= 6 * x["full_time_spanish_9_11"] - 17 # 9 A.M. – 11 A.M.
h[5]= 6 * x["full_time_english_11_1"] + 6 * x["full_time_english_7_9"] - 56 # 11 A.M. – 1 P.M.
h[6]= 6 * x["full_time_spanish_11_1"] + 6 * x["full_time_spanish_7_9"] - 14 # 11 A.M. – 1 P.M.
h[7]= 6 * x["full_time_english_1_3"] + 6 * x["full_time_english_9_11"]- 76 # 1 P.M. – 3 P.M.
h[8]= 6 * x["full_time_spanish_1_3"] + 6 * x["full_time_spanish_9_11"] - 19 # 1 P.M. – 3 P.M.
h[9]= 6 * x["full_time_english_3_5"] + 6 * x["part_time_english_3_5"]+ 6 * x["full_time_english_11_1"]- 64 # 3 P.M. – 5 P.M.
h[10]= 6 * x["full_time_spanish_3_5"] + 6 * x["full_time_spanish_11_1"] - 16 # 3 P.M. – 5 P.M.
h[11]= 6 * x["part_time_english_5_7"] + 6 * x["part_time_english_3_5"] + 6 * x["full_time_english_1_3"]- 28 # 5PM - 7PM
h[12]= 6 * x["full_time_spanish_1_3"] - 7 # 5PM - 7PM
h[13]= 6 * x["part_time_english_5_7"] + 6 * x["full_time_english_3_5"] - 8 # 7PM - 9PM
h[14]= 6 * x["full_time_spanish_3_5"] - 2 # 7PM - 9PM
h[15]= x["full_time_english_7_9"]
h[16]= x["full_time_spanish_7_9"]
h[17]= x["full_time_english_9_11"]
h[18]= x["full_time_spanish_9_11"]
h[19]= x["full_time_english_11_1"]
h[20]= x["full_time_spanish_11_1"]
h[21]= x["full_time_english_1_3"]
h[22]= x["full_time_spanish_1_3"]
h[23]= x["full_time_english_3_5"]
h[24]= x["full_time_spanish_3_5"]
h[25]= x["part_time_english_3_5"]
h[26]= x["part_time_english_5_7"]
return(h)
}
# Initial values for the decision variables
initial_values = c(
full_time_english_7_9 = 6,
full_time_spanish_7_9 = 2,
full_time_english_9_11 = 12,
full_time_spanish_9_11 = 3,
full_time_english_11_1 = 4,
full_time_spanish_11_1 = 2,
full_time_english_1_3 = 1,
full_time_spanish_1_3 = 2,
full_time_english_3_5 = 4,
full_time_spanish_3_5 = 1,
part_time_english_3_5 = 3,
part_time_english_5_7 = 2
)
# Solve the optimization problem with constraints
result = constrOptim.nl(initial_values, objective_function,
heq = constraint_equal, hin = constraint_inequal)
result$par
# Answer A
cat("\n Full-time English-speaking agents, full-time Spanish-speaking agents, \n
and part-time agents Alex should hire for each 2-hour shift to minimize operating costs are: \n")
ceiling(result$par)
#Answer B
result$value
cat("\n Minimum Cost for the Optimization Model: $", round(result$value, 2), "\n")
# ANSWER 2: Objective function to minimize
a_objective_function <- function(x) (60* (2* x["full_time_english_7_9"] + 2* x["full_time_spanish_7_9"] +
2*x["full_time_english_9_11"] + 2* x["full_time_spanish_9_11"] +
2* x["full_time_english_11_1"] + 2* x["full_time_spanish_11_1"]+
x["full_time_english_1_3"] + x["full_time_spanish_1_3"] +
x["full_time_english_3_5"] + x["full_time_spanish_3_5"] + x["part_time_english_3_5"]) +
90 * (x["part_time_english_5_7"] + x["part_time_english_5_7"]+x["part_time_english_3_5"]+
x["full_time_english_1_3"]+ x["full_time_spanish_1_3"]+
+x["full_time_english_3_5"]+ x["full_time_spanish_3_5"]))
a_constraint_equal <- function(x) {
# equality constraints
h=0
h[1]= x["full_time_english_7_9"] + x["full_time_spanish_7_9"] - 8 # 7 A.M. – 9 A.M.
h[2]= x["full_time_english_9_11"] + x["full_time_spanish_9_11"] - 15 # 9 A.M. – 11 A.M.
h[3]= x["full_time_english_11_1"] + x["full_time_spanish_11_1"]+ x["full_time_english_7_9"]+x["full_time_spanish_7_9"] - 13 # 11 A.M. – 1 P.M.
h[4]= x["full_time_english_1_3"] + x["full_time_spanish_1_3"]+ x["full_time_english_9_11"]+ x["full_time_spanish_9_11"] - 17 # 1 P.M. – 3 P.M.
h[5]= x["full_time_english_3_5"] + x["full_time_spanish_3_5"] + x["part_time_english_3_5"]+x["full_time_english_11_1"]+ x["full_time_spanish_11_1"] - 14 # 3 P.M. – 5 P.M.
h[6]= x["part_time_english_5_7"]+ x["part_time_english_3_5"] +x["full_time_english_1_3"]+ x["full_time_spanish_1_3"] - 7 # 5PM - 7PM
h[7]= x["part_time_english_5_7"]+x["full_time_english_3_5"]+ x["full_time_spanish_3_5"] - 3 # 7PM - 9PM
# New constraint: Only one full-time English agent for 1 PM - 3 PM
h[8] = x["full_time_english_1_3"] - 1
return(h)
}
# Constraints
a_constraint_inequal <- function(x) {
# Inequality constraints
h=0
h[1]= 6 * x["full_time_english_7_9"] - 32 # 7 A.M. – 9 A.M.
h[2]= 6 * x["full_time_spanish_7_9"] - 8 # 7 A.M. – 9 A.M.
h[3]= 6 * x["full_time_english_9_11"] - 68 # 9 A.M. – 11 A.M.
h[4]= 6 * x["full_time_spanish_9_11"] - 17 # 9 A.M. – 11 A.M.
h[5]= 6 * x["full_time_english_11_1"] + 6 * x["full_time_english_7_9"] - 56 # 11 A.M. – 1 P.M.
h[6]= 6 * x["full_time_spanish_11_1"] + 6 * x["full_time_spanish_7_9"] - 14 # 11 A.M. – 1 P.M.
h[7]= 6 * x["full_time_english_1_3"] + 6 * x["full_time_english_9_11"]- 76 # 1 P.M. – 3 P.M.
h[8]= 6 * x["full_time_spanish_1_3"] + 6 * x["full_time_spanish_9_11"] - 19 # 1 P.M. – 3 P.M.
h[9]= 6 * x["full_time_english_3_5"] + 6 * x["part_time_english_3_5"]+ 6 * x["full_time_english_11_1"]- 64 # 3 P.M. – 5 P.M.
h[10]= 6 * x["full_time_spanish_3_5"] + 6 * x["full_time_spanish_11_1"] - 16 # 3 P.M. – 5 P.M.
h[11]= 6 * x["part_time_english_5_7"]+ 6 * x["part_time_english_3_5"] + 6 * x["full_time_english_1_3"]- 28 # 5PM - 7PM
h[12]= 6 * x["full_time_spanish_1_3"] - 7 # 5PM - 7PM
h[13]= 6 * x["part_time_english_5_7"]+ 6 * x["full_time_english_3_5"] - 8 # 7PM - 9PM
h[14]= 6 * x["full_time_spanish_3_5"] - 2 # 7PM - 9PM
h[15]= x["full_time_english_7_9"]
h[16]= x["full_time_spanish_7_9"]
h[17]= x["full_time_english_9_11"]
h[18]= x["full_time_spanish_9_11"]
h[19]= x["full_time_english_11_1"]
h[20]= x["full_time_spanish_11_1"]
h[21]= x["full_time_english_1_3"]
h[22]= x["full_time_spanish_1_3"]
h[23]= x["full_time_english_3_5"]
h[24]= x["full_time_spanish_3_5"]
h[25]= x["part_time_english_3_5"]
h[26]= x["part_time_english_5_7"]
return(h)
}
# Initial values for the decision variables
a_initial_values = c(
full_time_english_7_9 = 6,
full_time_spanish_7_9 = 2,
full_time_english_9_11 = 12,
full_time_spanish_9_11 = 3,
full_time_english_11_1 = 4,
full_time_spanish_11_1 = 2,
full_time_english_1_3 = 1,
full_time_spanish_1_3 = 2,
full_time_english_3_5 = 4,
full_time_spanish_3_5 = 1,
part_time_english_3_5 = 3,
part_time_english_5_7 = 2
)
# Solve the optimization problem with constraints
a_result = constrOptim.nl(a_initial_values, a_objective_function,
heq = a_constraint_equal, hin = a_constraint_inequal)
a_result$par
#Answer C
cat("\n Full-time English-speaking agents, full-time Spanish-speaking agents, and part-time agents should Alex hire \n
when only one qualified English-speaking agent willing to start work at 1 P.M. and 3 P.M are:\n")
ceiling(a_result$par)
#Answer D
a_result$value
cat("\nMinimum Cost for the Optimization Model: $", round(a_result$value, 2), "\n")
library(alabama)
# ANSWER 3: Objective function to minimize
bilin_objective_function <- function(x) (60* (2* x["full_time_7_9"] +
2*x["full_time_9_11"] +
2* x["full_time_11_1"] +
x["full_time_1_3"] +
x["full_time_3_5"] + x["part_time_3_5"]) +
90 * (2 *x["part_time_5_7"]+x["part_time_3_5"]+
x["full_time_1_3"]+
+x["full_time_3_5"]))
bilin_constraint_equal <- function(x) {
# equality constraints
h=0
h[1]= x["full_time_7_9"] - 8 # 7 A.M. – 9 A.M.
h[2]= x["full_time_9_11"] - 15 # 9 A.M. – 11 A.M.
h[3]= x["full_time_11_1"] + x["full_time_7_9"] - 13 # 11 A.M. – 1 P.M.
h[4]= x["full_time_1_3"] + x["full_time_9_11"] - 17 # 1 P.M. – 3 P.M.
h[5]= x["full_time_3_5"] + x["part_time_3_5"] + x["full_time_11_1"] - 14 # 3 P.M. – 5 P.M.
h[6]= x["part_time_5_7"] + x["part_time_3_5"] + x["full_time_1_3"] - 7 # 5PM - 7PM
h[7]= x["part_time_5_7"] + x["full_time_3_5"] - 3 # 7PM - 9PM
return(h)
}
# Constraints
bilin_constraint_inequal <- function(x) {
# Inequality constraints
h=0
h[1]= 6 * x["full_time_7_9"] - 40 # 7 A.M. – 9 A.M.
h[2]= 6 *x["full_time_9_11"] - 85 # 9 A.M. – 11 A.M.
h[3]= 6 *x["full_time_11_1"] + 6 *x["full_time_7_9"] - 70 # 11 A.M. – 1 P.M.
h[4]= 6 *x["full_time_1_3"] + 6 *x["full_time_9_11"] - 95 # 1 P.M. – 3 P.M.
h[5]= 6 *x["full_time_3_5"] + 6 *x["part_time_3_5"] + 6 *x["full_time_11_1"] - 80 # 3 P.M. – 5 P.M.
h[6]= 6 *x["part_time_5_7"]+ 6 *x["part_time_3_5"] + 6 *x["full_time_1_3"] - 35 # 5PM - 7PM
h[7]= 6 *x["part_time_5_7"] + 6 *x["full_time_3_5"] - 10 # 7PM - 9PM
h[8]= x["full_time_7_9"]
h[9]= x["full_time_9_11"]
h[10]= x["full_time_11_1"]
h[11]= x["full_time_1_3"]
h[12]= x["full_time_3_5"]
h[13]= x["part_time_3_5"]
h[14]= x["part_time_5_7"]
return(h)
}
# Initial values for the decision variables
bilin_initial_values = c(
full_time_7_9 = 9,
full_time_9_11 = 16,
full_time_11_1 = 5,
full_time_1_3 = 2,
full_time_3_5 = 8,
part_time_3_5 = 2,
part_time_5_7 = 4
)
# Solve the optimization problem with constraints
bilin_result = constrOptim.nl(bilin_initial_values, bilin_objective_function,
heq = bilin_constraint_equal, hin = bilin_constraint_inequal)
bilin_result$par
#Answer E:
cat("\n Number of bilingual agents Alex should hire: \n")
ceiling(bilin_result$par)
bilin_result$value
#Answer F:
cat("\nMinimum Cost for the Optimization Model (Bilingual): $", round(bilin_result$value, 2), "\n")
# Calculate the maximum percentage increase in the hourly wage rate for bilingual agents
hourly_wage_rate_increase_percentage = (a_result$value - bilin_result$value) / sum(bilin_result$par) * 100
#Answer G:
cat("\nMaximum Percentage Increase in Hourly Wage Rate for Bilingual Agents: ",
round(hourly_wage_rate_increase_percentage, 1), "%\n")