forked from saeedt/PythonGraphSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhybalg.py
More file actions
80 lines (65 loc) · 2.45 KB
/
Copy pathhybalg.py
File metadata and controls
80 lines (65 loc) · 2.45 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
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 12 11:03:56 2020
@author: ma076216
"""
import math
import random
demand_points_rnd = random.sample(range(1,19835),500)
demand_levels =[]
for i in range (len(demand_points_rnd)):
demand_levels.append(random.randint(1,100))
demand_set = list(zip(demand_points_rnd,demand_levels))
number_clusters = 5
capacity = 100
from clusalg import *
clusters_f = findCluster(demand_points_rnd, demand_levels, number_clusters, .5)
clusters_list = []
for i in range (number_clusters):
clusters_list.append(clusters_f[0][i]['dps'])
total_demand_clusters = []
number_modules = []
utilization = []
for i in range (number_clusters):
demand_sum = 0
j=0
for j in range(len(clusters_list[i])):
demand_sum = demand_sum+clusters_list[i][j][1]
total_demand_clusters.append(demand_sum)
number_modules.append(demand_sum/capacity)
utilization.append (number_modules[i]- math.floor(number_modules[i]))
uti_sort = sorted(utilization,reverse=True)
sim_thrishold = 7000
i = 0
dedicated_mod = []
shared_mod = []
remainder_mod=[]
while len(uti_sort)>0:
if uti_sort[i]== 1:
dedicated_mod.append(utilization.index(uti_sort[i],0, number_clusters-1))
uti_sort.pop(0)
continue
if uti_sort[i]>=0.50:
uti_shared = uti_sort[i]
sh_l = []
sh_l.append(utilization.index(uti_sort[i])) # get index of module with utilization >0.5 store it in shl
j=i+1
while j in range (1,len(uti_sort)-1): # iterate through remainng elements to find shared modules
uti_shared = uti_shared + uti_sort[j]
if uti_shared > 1: # if a combination is greater than 100 utilization do not combine them and move on
uti_shared = uti_shared - uti_sort[j]
j+=1
continue
sh_l.append(utilization.index(uti_sort[j])) # if two modules can be combined, do it and get their indecies
uti_sort.pop(j) # reomve the item combined from sorted utilization list
if len(sh_l)>1: #if 2 or more modules combined add them to the shared modules list, otherwise to dedicated list
shared_mod.append(sh_l)
uti_sort.pop(i)
continue
else:
dedicated_mod.append(sh_l)
uti_sort.pop(i)
continue
if uti_sort[i]<0.50:
remainder_mod.append(utilization.index(uti_sort[i]))
uti_sort.pop(i)