Need help to write data onto an XML file after reading data fromanother xml file

V

varun7rs

Hello Users,

I am in dire need of your help. I have been working on this code for quite some time and it is making me restless. All I am trying to do is,

1. Read data from an xml file. Source: http://sndlib.zib.de/coredata.download.action?objectName=germany50&format=xml&objectType=network

2. The data I'm concerned about is the node ID, co-ordinates, capacity of the links, source and destination names.

3. I'm creating a topology with this information and the topology is same as the one given in the xml file. But, I'd like to add a few extra parameters and demands which I have mentioned in the .py file.

4. This is where I am faltering. I am just not able to create this topology. The file has also become really messy as I tried a lot of weird stuff and commented it out as it did not work.

5. I'll attach the relevant files and I'd like to write the output onto a new xml file.

I'd be glad if any of you could help me out. I'm indebted to you guys. Oh I was not aware that I could attach files. Anyways, here is the link to the files I'm working on
https://www.dropbox.com/sh/i8h321y7c9c60vt/AADzDj7oOM8YU76Ww6W4LIPYa

Thanks a lot everyone
 
D

Dave Angel

Hello Users,

I am in dire need of your help. I have been working on this code for quite some time and it is making me restless. All I am trying to do is,

1. Read data from an xml file. Source: http://sndlib.zib.de/coredata.download.action?objectName=germany50&format=xml&objectType=network

2. The data I'm concerned about is the node ID, co-ordinates, capacity of the links, source and destination names.

3. I'm creating a topology with this information and the topology is same as the one given in the xml file. But, I'd like to add a few extra parameters and demands which I have mentioned in the .py file.

4. This is where I am faltering. I am just not able to create this topology. The file has also become really messy as I tried a lot of weird stuff and commented it out as it did not work.

5. I'll attach the relevant files and I'd like to write the output onto a new xml file.

I'd be glad if any of you could help me out. I'm indebted to you guys. Oh I was not aware that I could attach files. Anyways, here is the link to the files I'm working on
https://www.dropbox.com/sh/i8h321y7c9c60vt/AADzDj7oOM8YU76Ww6W4LIPYa

Thanks a lot everyone

Try to include the relevant information in your message. Many people
cannot, or will not, follow links. Further, those links are frequently
transient (such as your dropbox one), which means the message thread
becomes historically useless. So a link to point to a particular
library is useful and practical, one to your source code is not.

And many readers cannot see attachments or html formatted messages.
 
V

varun7rs

I try to add an edge with the source id and destination id over a loop but this is the error I am getting. And the range for the for addEdge is something I have no clue about.

python export.py --output topology.xml --xml germany50.xml
Traceback (most recent call last):
File "export.py", line 239, in <module>
main(sys.argv[1:])
File "export.py", line 234, in main
network.addEdge( PHY_LINKS( j , sourcen, destnn, sid, did, cap_bdw) )
File "/home/srva/Approach_Read.py", line 89, in addEdge
self.nodes[ edge.SourceID ].addInEdge( edge )
IndexError: list index out of range

Thank You
 
D

Dave Angel

I try to add an edge with the source id and destination id over a loop but this is the error I am getting. And the range for the for addEdge is something I have no clue about.

python export.py --output topology.xml --xml germany50.xml
Traceback (most recent call last):
File "export.py", line 239, in <module>
main(sys.argv[1:])
File "export.py", line 234, in main
network.addEdge( PHY_LINKS( j , sourcen, destnn, sid, did, cap_bdw) )
File "/home/srva/Approach_Read.py", line 89, in addEdge
self.nodes[ edge.SourceID ].addInEdge( edge )
IndexError: list index out of range

Thanks for posting a complete stack trace, it can be a real help. You
still have not shown us the source code. Did you write it yourself, or
are you just trying to debug something written by someone else?

In particular, the exception occurs in Approach_Read.py. Is that your
file, and can you edit it to ferret out the problem? Do you know what
attributes are supposed to be of what types?

I peaked; I actually took a look at your dropbox files. So I have some
comments, though they may not help debug the problem. After all, there
are hundreds of lines of code,

First, you don't mention the Python version nor the OS you're using.
Indirectly, I can surmise Python 2.7 and Linux, but it's much safer to
declare such things in the problem descrition.

Assuming 2.x, you're using old-style classes. While that might not be a
bug, they've been obsolete for at least a decade. You need to derive
each of your classes from object. So, you should have for example:

class CplexSolver(object):

next, you have way too few comments. I can't even tell why you put
certain classes and functions in one file, versus others in another file.

Next, you don't follow Pep8, or any other reasonable standard, for
naming. Thus, I can't tell readily whether a particular name is a class
name, an attribute, a method, or whatever. If the code were smaller, I
might be willing to work it out, and make myself a crossref, but that's
why you should simplify a problem you're asking for help with. If the
code is 700 lines, few people are going to be willing to study it unless
it's very well commented and easy to follow.

You have a name PHY_NETWORK, which being all caps would indicate it's a
const, but instead it's actually a class. It has a method addEdge(),
which takes an argument edge. But it's not obvious to me what class
that is, so I could look up its definition. If you don't know either,
you could add a print type(edge) to that method, and see what gets
printed just before it gets the exception.

That field might happen to be of type PHY_LINKS, in which case we see
the initializer has the line
self.SourceID = SourceID

Unfortunately, we don't know what class that's supposed to be. You're
using it like it's an integer, and the integer is apparently outside the
range of the list PHY_NETWORK.nodes

So you could add a few more print statements, find out the len() of
nodes, and the value of SourceID.
 
V

varun7rs

That is a very descriptive post. Since its my first time programming I am not aware of many conventions that are being used to name classes. I tried to distinguish them by naming classes in caps. I borrowed some ideas from here and there to come up with the Approach_Read.py file. What I intend to dowith that file is basically define classes. I have defined all the classesthat are necessary for me. Now, the lower part of the file contains a function readXML or something which I am still working on but as of now it is not relevant. Second file would be the approach file which I have to use once I generate the xml file that I need to use. So, this brings me to the last file which is really messy.
All I want to do in the export.py file is that I'd like to pull out some data from the xml file(from the SNDLib website for the sake of topology). Since this xml file contains the source, destination and some other relevant attributes, I read them out of it. Now, I want to use the class PHY_NETWORK to create this topology. The class consists of arguments nodes, edges, etc., Here to add edges between the nodes, I call the method addEdge from the class PHY_NETWORK. But when I do that I get this error 'unicode' object has no attribute 'addInEdge. I'm not sure if I made myself clear. Once the stuff is working, I would like an xml file which looks somewhat like the one below but with attributes we need like the processing, storage and switching power.

VNEInstance schema="VNEInstance.xsd" version="">
<substrate>
<nodes>
<node capacity="975.4" costs="0.0" id="0" nodeName="0" xCoordinate="54" yCoordinate="41"/>
<node capacity="742.5" costs="0.0" id="1" nodeName="1" xCoordinate="67" yCoordinate="33"/> I'm really sorry for the trouble but once I get this thing going then I can move on with the CPLEX solving stuff.Thanks alot for your help
 
C

Chris Angelico

Since its my first time programming I am not aware of many conventions that are being used to name classes. I tried to distinguish them by naming classes in caps.

The most commonly followed naming conventions in Python are those
mandated for Python's own standard library. The definition of that is
in a document called PEP 8:

http://www.python.org/dev/peps/pep-0008/

Makes a good read. If you at least mostly follow PEP 8, people on this
list will instantly know what's a class and what's not, etc, and it'll
make things easier all round.

ChrisA
 

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

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top