Mapping of node numbers



Hello Everyone,

I need to map the node ID to a number. I am using this xml file as of now.
Also, I need to use the same node number whenever there is a node occurrence in the source and destination. If I have assigned numbers '4' and '32' tonode IDs Berlin and Leipzig, I need to use the same node numbers at the links as well. For example, L22 has <source>Leipzig</source>
I need two attributes next to them saying that sourceID = '32'targetID = '4'

class PHY_NODES:
def __init__(self, nodeID, nodenum, x, y, capacity_proc, capacity_stor,capacity_switch): = nodeID
self.nodenum = nodenum
self.x = x
self.y = y
self.inEdges = []
self.outEdges = []
self.capacity_proc = capacity_proc
self.capacity_stor = capacity_stor
self.capacity_switch = capacity_switch
self.capacity_bidirect = 0.0

def __str__(self):
return "Physical Node ID: " % ( "nodenum: %4d x: %.3f y: %.3f capProc: %.3f capStor: %.3f capSwitch: %.3f" %(self.nodenum, self.x, self.y, self.capacity_proc, self.capacity_stor, self.capacity_switch)

def addInEdge (self, edge):
self.capacity_bidirect = capacity_bidirect + edge.capacity

def addOutEdge (self, edge):
self.capacity_bidirect = capacity_bidirect + edge.capacity

class PHY_LINKS:
def __init__(self, linkID, source, destination, tailNodeId, headNodeId,capacity_bdw):
self.linkID = linkID
self.source = source
self.destination = destination
self.tailNodeId = tailNodeId
self.headNodeId = headNodeId
self.capacity_bdw = capacity_bdw

def __str__(self):
return "Physical Link ID: " % (self.linkID) "source: %s destination: %s tailNodeId: %4d headNodeId: %4d capacity_bdw: %.3f" %(self.source, self.destination, self.tailNodeId, self.headNodeId, self.capacity_bdw)

def __init__(self, nodes, edges, nameToIdMap)
self.nodes = nodes
self.edges = edges
self.nameToIdMap = nameToIdMap

def getEdge(self, tailId, headId):
if tailId < 0 or tailId >= len( self.nodes ) or headId < 0 or headId >= len( self.nodes ):
return None
for edge in self.nodes[ tailId ].outEdges:
if edge.headNodeId == headId:
return self.edges[ edge.linkID ]

for edge in self.nodes[ headId ].outEdges:
if edge.headNodeId == tailId:
return self.edges[ edge.linkID ]
return None

def hasEdge( self, tailId, headId ):
if len( self.nodes ) <= tailId or len( self.nodes ) <= headId :
return False
for edge in self.nodes[tailId].outEdges:
if edge.headNodeId == headId:
return True
for edge in self.nodes[tailId].inEdges:
if edge.tailNodeId == tailId:
return True

return False

def addNode(self, node):
self.nodes.append( node )
self.nameToIdMap[ ] =

def addEdge(self, edge):
self.edges.append( edge )
self.nodes[ edge.headNodeId ].addInEdge( edge )
self.nodes[ edge.tailNodeId ].addOutEdge( edge )

nodes = []
edges = []
nodeNameToIdMap = {}
Read_Data = parse(filename) # "germany50.xml"

# Reading Nodes

nodelist = Read_Data.getElementsByTagName("node")

num = 0

for node in nodelist :
#nodeid = node.getAttribute("id")
xCoordinates = node.getElementsByTagName("x") [0]
yCoordinates = node.getElementsByTagName("y") [0]
proc = random.randint(3500, 5000)
stor = random.randint(7200, 8200)
switch = random.randint(7000, 10000)
num = num + 1

nodes.append(PHY_NODES( node.getAttribute("id"), int(num), float(, float(, float(proc), float(stor), float(switch)))

nodeNameToIdMap[ nodes[-1].num ] = nodes[-1].id

# Reading Links

linklist = Read_Data.getElementsByTagName("link")

for link in linklist :
linkid = link.getAttribute("id")
Source = link.getElementsByTagName("source") [0]
Destination = link.getElementsByTagName("target") [0]
Capacity = link.getElementsByTagName("capacity") [0]
SourceID =

edges.append(PHY_LINKS( link.getAttribute("id"),,, int( ))

nodes[ edges[-1].source ].addInEdge( edges[-1] )
nodes[ edges[-1].destination ].addOutEdge( edges[-1] )

Could you please help me with this problem?

Thanks a lot


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question