-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstanceGen.py
More file actions
50 lines (39 loc) · 1.52 KB
/
Copy pathinstanceGen.py
File metadata and controls
50 lines (39 loc) · 1.52 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
from GraphGen.classes.graph import Graph
import GraphGen.classes.node
import GraphGen.utils.json_utils as json_utils
import GraphGen.utils.pycgr_utils as pycgr_utils
import sys
import sim_utils
TAG = 'instanceGen.py:'
def createGraph(graphFilePath):
sim_utils.log(TAG, 'createGraph')
nodes, edges = pycgr_utils.readNodesAndEdges(graphFilePath)
graph = Graph(nodes)
for e in edges:
node_1 = e[0]
node_2 = e[1]
weight = e[2] # distance
graph.addEdge(node_1, node_2, float(weight))
return graph
def main(jsonFilePath, graphFilePath):
sim_utils.log(TAG, 'main')
mainGraph = createGraph(graphFilePath)
# mainGraph.printAdjList()
jsonData = json_utils.readJsonInput(jsonFilePath)
cloudlets = json_utils.buildCloudlets(jsonData['Cloudlets'])
users = json_utils.buildUserVms(jsonData['UserVMs'])
"""
In fact, these subgraphs might be useful but I don't really need to return it...
I can make them when necessary through the main graph
cloudletsNodes = [mainGraph.findNodeById(c.nodeId) for c in cloudlets]
cloudletsSubgraph = mainGraph.getSubgraph(cloudletsNodes)
usersRoutes = []
for u in users:
userRouteNodes = [mainGraph.findNodeById(routeNode) for routeNode in u.route]
curr = mainGraph.getSubgraph(userRouteNodes)
usersRoutes.append(curr) """
return [cloudlets, users, mainGraph]
if __name__ == '__main__':
jsonFilePath = sys.argv[1:][0]
graphFilePath = sys.argv[1:][1]
main(jsonFilePath, graphFilePath)