aboutsummaryrefslogtreecommitdiffstats
path: root/examples/placement-models-minizinc/vdns-plus-vfw-use-case/placement-minizinc.ipynb
blob: 68ab73b0107fd4aa4809d6f683717fb9b5b6829d (plain)
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int: N_CLOUD_REGIONS;  % number of cloud regions\n",
      "% set of 1..N_CLOUD_REGIONS: C_REGIONS;\n",
      "\n",
      "int: N_ATTRIBUTES; %  number of capability related attributes\n",
      "% set of 1..N_ATTRIBUTES: ATTRIBS;\n",
      "array[1..N_ATTRIBUTES] of float: w_attributes; % weights of each attribute\n",
      "\n",
      "int: N_UTILIZATION_METRICS; % number of dynamic capacity metrics of interest\n",
      "% set of 1..N_UTILIZATION_METRICS: U_METRICS;\n",
      "array[1..N_UTILIZATION_METRICS] of float: w_metrics; % weights of each capacity metric\n",
      "\n",
      "int: cust_type;  % customer type, 0 = regular, 1 = silver, 2 = gold\n",
      "int: N_VMS; % number of VMs in VNF\n",
      "int: N_CAPACITY_METRICS; % number of metrics for cloud region capacity check\n",
      "\n",
      "float: C_ALLOC_THRESHOLD; % allocation threshold for cloud\n",
      "float: CUST_ALLOC_THRESHOLD; % allocation threshold for customer in cloud\n",
      "float: AVG_CPU_UTILIZATION_THRESHOLD;\n",
      "float: PEAK_CPU_UTILIZATION_THRESHOLD;\n",
      "\n",
      "enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n",
      "enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n",
      "enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n",
      "enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n",
      "enum VNFS_TYPES = { VDNS, VFW };\n",
      "int: N_VNFS;\n",
      "\n",
      "% set of 1..N_CAPACITY_METRICS: CAP_METRICS;\n",
      "\n",
      "% whether a cloud region has the corresponding capability -- data will be customer specific\n",
      "% array[1..N_CLOUD_REGIONS, 1..N_CLOUD_REGIONS] of float: c_dist;\n",
      "array[1..N_CLOUD_REGIONS, 1..N_ATTRIBUTES] of int: capabilities;\n",
      "array[1..N_CLOUD_REGIONS, 1..N_UTILIZATION_METRICS] of float: cpu_utilization;  % how much capacity is already dynamically utilized     (fraction)\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: c_alloc_capacity; % how much percent is already allocated in the cloud\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: c_total_capacity;  % total cloud capacity\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: c_alloc_capacity_norm;\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: cust_alloc_capacity; % how much percent is already allocated in the cloud for the customer\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: cust_total_capacity; % total cloud capacity for customer\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: cust_alloc_capacity_norm;\n",
      "\n",
      "% VM requirements for each type of capacity (vm cpu, memory, etc.)\n",
      "% TODO: establish a standard for units (MB RAM, GB disk, N virtual cores, etc.)\n",
      "array[1..N_VMS, 1..N_CAPACITY_METRICS] of int: vm_reqs;\n",
      "array[1..N_CAPACITY_METRICS] of int: vm_reqs_sums = [ sum(k in 1..N_VMS) (vm_reqs[k,j]) | j in 1..N_CAPACITY_METRICS ];\n",
      "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: vm_reqs_sums_norm;\n",
      "%forall(i in 1..N_CLOUD_REGIONS, j in 1..N_CAPACITY_METRICS) (\n",
      "%  vm_reqs_sums_norm[i, j] = vm_reqs_sums[j]/c_total_capacity[i, j]\n",
      "%)\n",
      "%array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: vm_reqs_sums_norm = [ ((vm_reqs_sums[j]/c_total_capacity[i,j]) | j in 1..N_CAPACITY_METRICS) | i in 1..N_CLOUD_REGIONS ];\n",
      "\n",
      "array[1..N_VNFS] of var int: s_regions;  % target cloud regions (solution to the problem)\n",
      "\n",
      "% custom constraints\n",
      "constraint forall (s in s_regions) (\n",
      "    cpu_utilization[s, AVG_CPU_UTILIZATION] <= AVG_CPU_UTILIZATION_THRESHOLD /\\    % hard constraint: need some capacity available\n",
      "    cpu_utilization[s, PEAK_CPU_UTILIZATION] <= PEAK_CPU_UTILIZATION_THRESHOLD /\\  % hard constraint: need some capacity available\n",
      "    cust_alloc_capacity[s, CPU_CLOUD] <= (CUST_ALLOC_THRESHOLD*(cust_total_capacity[s, CPU_CLOUD])) - (vm_reqs_sums[CPU_CLOUD]) /\\\n",
      "    cust_alloc_capacity[s, MEMORY_CLOUD] <= (CUST_ALLOC_THRESHOLD*(cust_total_capacity[s, MEMORY_CLOUD])) - (vm_reqs_sums[MEMORY_CLOUD]) /\\\n",
      "    c_alloc_capacity[s, CPU_CLOUD] <= (C_ALLOC_THRESHOLD*(c_total_capacity[s, CPU_CLOUD])) - (vm_reqs_sums[CPU_CLOUD]) /\\\n",
      "    c_alloc_capacity[s, MEMORY_CLOUD] <= (C_ALLOC_THRESHOLD*(c_total_capacity[s, MEMORY_CLOUD])) - (vm_reqs_sums[MEMORY_CLOUD])\n",
      ");\n",
      "\n",
      "% specific constraints based on the VNF\n",
      "constraint capabilities[s_regions[VDNS], CORE_DC] = 1;  % hard constraint for vDNS: has to be placed in CORE DC\n",
      "\n",
      "% custom soft constraint for gold customers -- give a large weight to direct connection\n",
      "var float: additional_obj = sum(s in s_regions) (bool2int(cust_type = GOLD) * capabilities[s, MIN_GUARANTEE] * 1000);\n",
      "\n",
      "% TODO: global constraints (such as data validation)\n",
      "\n",
      "% Objective for utilization\n",
      "var float: obj_c_capacity = sum(k in 1..N_CAPACITY_METRICS, s in s_regions) (\n",
      "\t\t  (1 - c_alloc_capacity_norm[s, k] - vm_reqs_sums_norm[s, k]) +\n",
      "                  (1 - cust_alloc_capacity_norm[s, k] - vm_reqs_sums_norm[s, k]));\n",
      "\n",
      "% Objective for utilization\n",
      "var float: obj_utilization = sum(k in 1..N_UTILIZATION_METRICS, s in s_regions) ( w_metrics[k] * (1 - cpu_utilization[s, k]) );\n",
      "\n",
      "% Objective for capabilities\n",
      "var float: obj_capabilities = sum(k in 1..N_ATTRIBUTES, s in s_regions) ( w_attributes[k] * capabilities[s, k] );\n",
      "\n",
      "% Overall objective function\n",
      "var float: obj = obj_c_capacity + obj_utilization + obj_capabilities + additional_obj;\n",
      "\n",
      "solve maximize obj;\n",
      "\n",
      "output [ \"Solution: \\nCloud Region for vDNS = \", show(s_regions[VDNS]) ] \n",
      "++ [ if N_VNFS = 2 then \"\\nCloud Region for vFW = \" ++ show(s_regions[VFW]) ++ \"\\n\" else \"\\n\" endif ]\n",
      "++ [ \"Objective function value: \", show(obj), \"\\n\", \"Customer type: \", show(cust_type), \"\\n\"];\n"
     ]
    }
   ],
   "source": [
    "!cat placement.mzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "% enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n",
      "% enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n",
      "% enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n",
      "% enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n",
      "\n",
      "N_CLOUD_REGIONS = 3;  % e-dc-1, core-dc-1, core-dc-2\n",
      "N_ATTRIBUTES = 4;\n",
      "N_UTILIZATION_METRICS = 2;\n",
      "N_CAPACITY_METRICS = 2;\n",
      "N_VMS = 3;\n",
      "C_ALLOC_THRESHOLD = 0.65;\n",
      "CUST_ALLOC_THRESHOLD = 0.95;\n",
      "AVG_CPU_UTILIZATION_THRESHOLD = 0.7;\n",
      "PEAK_CPU_UTILIZATION_THRESHOLD = 0.95;\n",
      "\n",
      "cust_type = GOLD;\n",
      "N_VNFS = 1;\n",
      "\n",
      "w_metrics = [0.9, 0.1];\n",
      "w_attributes = [0.1, 0.9, 0.05, 0.05]; \n",
      "\n",
      "capabilities = [| 0, 1, 1, 1\n",
      "                | 1, 0, 1, 1\n",
      "                | 1, 1, 0, 1 |];\n",
      "\n",
      "cpu_utilization = [| 0.05, 0.9\n",
      "                   | 0.1, 0.5\n",
      "                   | 0.6, 0.8 |];\n",
      "\n",
      "c_alloc_capacity = [| 600, 1200\n",
      "                    | 1200, 2400\n",
      "                    | 2400, 4800 |];\n",
      "\n",
      "c_total_capacity = [| 1000, 2000\n",
      "                    | 2000, 4000\n",
      "                    | 4000, 8000 |];\n",
      "\n",
      "c_alloc_capacity_norm = [| 0.6, 0.6\n",
      "                         | 0.6, 0.6\n",
      "                         | 0.6, 0.6 |];\n",
      "\n",
      "cust_alloc_capacity = [| 60, 120\n",
      "                       | 120, 240\n",
      "                       | 240, 480 |];\n",
      "\n",
      "cust_total_capacity = [| 100, 200\n",
      "                       | 200, 400\n",
      "                       | 400, 800 |];\n",
      "\n",
      "cust_alloc_capacity_norm = [| 0.6, 0.6\n",
      "                            | 0.6, 0.6\n",
      "                            | 0.6, 0.6 |];\n",
      "\n",
      "vm_reqs = [| 1, 4\n",
      "           | 2, 8\n",
      "           | 4, 16 |];\n",
      "\n",
      "%vm_reqs_sums = [ 14, 56 ];\n",
      "\n",
      "vm_reqs_sums_norm = [| 0.007, 0.014\n",
      "                     | 0.0035, 0.007\n",
      "                     | 0.00175, 0.0035 |];\n"
     ]
    }
   ],
   "source": [
    "!cat gold.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23c23\n",
      "<                 | 1, 0, 1, 1\n",
      "---\n",
      ">                 | 1, 0, 0, 1\n"
     ]
    }
   ],
   "source": [
    "!diff gold.dzn gold-no-min-guarantee.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23c23\n",
      "<                 | 1, 0, 1, 1\n",
      "---\n",
      ">                 | 1, 0, 0, 1\n"
     ]
    }
   ],
   "source": [
    "!diff gold.dzn gold-no-min-guarantee.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "% enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n",
      "% enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n",
      "% enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n",
      "% enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n",
      "\n",
      "N_CLOUD_REGIONS = 3;  % e-dc-1, core-dc-1, core-dc-2\n",
      "N_ATTRIBUTES = 4;\n",
      "N_UTILIZATION_METRICS = 2;\n",
      "N_CAPACITY_METRICS = 2;\n",
      "N_VMS = 3;\n",
      "C_ALLOC_THRESHOLD = 0.65;\n",
      "CUST_ALLOC_THRESHOLD = 0.95;\n",
      "AVG_CPU_UTILIZATION_THRESHOLD = 0.7;\n",
      "PEAK_CPU_UTILIZATION_THRESHOLD = 0.95;\n",
      "\n",
      "cust_type = SILVER;\n",
      "N_VNFS = 2;\n",
      "\n",
      "w_metrics = [0.9, 0.1];\n",
      "w_attributes = [0.1, 0.9, 0.05, 0.05]; \n",
      "\n",
      "capabilities = [| 0, 1, 1, 1\n",
      "                | 1, 0, 1, 1\n",
      "                | 1, 1, 0, 1 |];\n",
      "\n",
      "cpu_utilization = [| 0.05, 0.9\n",
      "                   | 0.1, 0.5\n",
      "                   | 0.6, 0.8 |];\n",
      "\n",
      "c_alloc_capacity = [| 600, 1200\n",
      "                    | 1200, 2400\n",
      "                    | 2400, 4800 |];\n",
      "\n",
      "c_total_capacity = [| 1000, 2000\n",
      "                    | 2000, 4000\n",
      "                    | 4000, 8000 |];\n",
      "\n",
      "c_alloc_capacity_norm = [| 0.6, 0.6\n",
      "                         | 0.6, 0.6\n",
      "                         | 0.6, 0.6 |];\n",
      "\n",
      "cust_alloc_capacity = [| 60, 120\n",
      "                       | 120, 240\n",
      "                       | 240, 480 |];\n",
      "\n",
      "cust_total_capacity = [| 100, 200\n",
      "                       | 200, 400\n",
      "                       | 400, 800 |];\n",
      "\n",
      "cust_alloc_capacity_norm = [| 0.6, 0.6\n",
      "                            | 0.6, 0.6\n",
      "                            | 0.6, 0.6 |];\n",
      "\n",
      "vm_reqs = [| 1, 4\n",
      "           | 2, 8\n",
      "           | 4, 16 |];\n",
      "\n",
      "%vm_reqs_sums = [ 14, 56 ];\n",
      "\n",
      "vm_reqs_sums_norm = [| 0.007, 0.014\n",
      "                     | 0.0035, 0.007\n",
      "                     | 0.00175, 0.0035 |];\n"
     ]
    }
   ],
   "source": [
    "!cat silver.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26c26\n",
      "< cpu_utilization = [| 0.05, 0.9\n",
      "---\n",
      "> cpu_utilization = [| 0.05, 0.96\n"
     ]
    }
   ],
   "source": [
    "!diff silver.dzn silver-high-edge-load.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solution: \n",
      "Cloud Region for vDNS = 2\n",
      "Objective function value: 1002.639\n",
      "Customer type: 3\n",
      "----------\n",
      "==========\n"
     ]
    }
   ],
   "source": [
    "!mzn-gecode -a placement.mzn gold.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solution: \n",
      "Cloud Region for vDNS = 2\n",
      "Objective function value: 2.589\n",
      "Customer type: 3\n",
      "----------\n",
      "Solution: \n",
      "Cloud Region for vDNS = 3\n",
      "Objective function value: 3.0195\n",
      "Customer type: 3\n",
      "----------\n",
      "==========\n"
     ]
    }
   ],
   "source": [
    "!mzn-gecode -a placement.mzn gold-no-min-guarantee.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solution: \n",
      "Cloud Region for vDNS = 2\n",
      "Cloud Region for vFW = 1\n",
      "Objective function value: 6.062\n",
      "Customer type: 2\n",
      "----------\n",
      "Solution: \n",
      "Cloud Region for vDNS = 3\n",
      "Cloud Region for vFW = 1\n",
      "Objective function value: 6.4425\n",
      "Customer type: 2\n",
      "----------\n",
      "==========\n"
     ]
    }
   ],
   "source": [
    "!mzn-gecode -a placement.mzn silver.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solution: \n",
      "Cloud Region for vDNS = 2\n",
      "Cloud Region for vFW = 2\n",
      "Objective function value: 5.278\n",
      "Customer type: 2\n",
      "----------\n",
      "Solution: \n",
      "Cloud Region for vDNS = 3\n",
      "Cloud Region for vFW = 2\n",
      "Objective function value: 5.6585\n",
      "Customer type: 2\n",
      "----------\n",
      "Solution: \n",
      "Cloud Region for vDNS = 3\n",
      "Cloud Region for vFW = 3\n",
      "Objective function value: 6.039\n",
      "Customer type: 2\n",
      "----------\n",
      "==========\n"
     ]
    }
   ],
   "source": [
    "!mzn-gecode -a placement.mzn silver-high-edge-load.dzn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}