Problem in writing demands to the xml file

V

varun7rs

Hello Friends,

I am still working on the script to write data onto the xml file and now I've got a problem.

This is how my xml file looks now but I intend to add attributes to demands. I am not able to do it properly.
substrate>
<nodes>
<node Name="u'Aachen'" ProcessingCapacity="20" StorageCapacity="38" SwitchingCapacity="45" TotalDemands="5" nodenum="1" xCoordinate="u'6.04'" yCoordinate="u'50.76'">
<demands/>
</node>
<node Name="u'Augsburg'" ProcessingCapacity="21" StorageCapacity="39" SwitchingCapacity="46" TotalDemands="2" nodenum="2" xCoordinate="u'10.9'" yCoordinate="u'48.33'">
<demands/>
</node>

My class for nodes. I have a class for DEMAND but I don't want to populate the post with all of it.
class PHY_NODES:
def __init__(self, nodeID, nodenum, x, y, capacity_proc, capacity_stor, capacity_switch, totaldemand, demands):
self.id = nodeID
self.nodenum = nodenum
self.x = x
self.y = y
self.capacity_proc = capacity_proc
self.capacity_stor = capacity_stor
self.capacity_switch = capacity_switch
self.totaldemand = totaldemand
self.demands = demands

def addDemand (self, demand):
self.demands.append( demand )

The problem I have is in writing the demands. I generate the necessary stuff for it but when I try and append it, it doesn't seem to work. I'd be glad to share my files if you need them. Could you please help me fix this?

Thank You
 
V

varun7rs

There is no traceback error. But I want to actually fill the demands with certain attributes which I'm not able to do. When I run the program, the xmlis written but the demands doesn't have any attributes whatsoever. I couldgive you a clear idea of what I expect in the demands. For every node, I have an attribute called totaldemands which takes a value between 1 and 5. Now, I need the same no. of demands being written onto the xml file below every node which is now empty

totaldemands = random.randint(1, 5)
demnum = 0
for demand in range(totaldemands):
demnum = demnum + 1
PoPbdw = random.uniform(2, 2.5)
PoPstor = random.uniform(2, 2.5)
PoPpro = random.uniform(0.5, 1)
MMEbdw = random.uniform(2, 2.5)
MMEstor = random.uniform(2, 3)
MMEpro = random.uniform(0.5, 1)
IMSbdw = random.uniform(2.5, 3)
IMSstor = random.uniform(2.5, 3.5)
IMSpro = random.uniform(0.5, 1)
SGWbdw = random.uniform(3, 3.5)
SGWstor = random.uniform(2.5, 3.5)
SGWpro = random.uniform(0.5, 1)
PGWbdw = random.uniform(2.5, 3.5)
PGWstor = random.uniform(2, 2.5)
PGWpro = random.uniform(0.5, 1)
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top