HDF5 data set, unable to read contents
Hello everyone, I recently came across a package called matrix2latex which simplifies the creation of very large tables. So, I saved my data in .mat format using the '-v7.3' extension so that they can be read by python. Now, when I try to read these files, I'm having some problems in reproducing the whole matrix. Whenever I try and print out an element of the array, I only get 'HDF5 object reference' as the output. This is basically the short code I wrote and what I basically want to do is have the values of the elements in the arrays and not the 'HDF5 object reference' thing. ex [ [ 1 2 3 4 ], [2 3 4 5 ]...] Could you please help me with this? The link to the .mat file is as below https://drive.google.com/file/d/0B2-j91i19ey2Nm1CbVpCQVdZc3M/view?usp=sharing import numpy as np, h5py from matrix2latex import matrix2latex f = h5py.File('nominal_case_unfix.mat', 'r') data = f.get('nominal_case_unfix') np_data = np.array(data) print np_data Thank You -- https://mail.python.org/mailman/listinfo/python-list
Running a .py file iteratively at the terminal
Hello Everyone, I am running a python script as of now and I have to change three global values repeatedly. I'm tired of doing this manually. SO, I was wondering if there is a way to run a python command repeatedly. In my case, the command would be srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml Everytime I run this, I get a log file with the results. The main file is the NFV_v3py. These are the values I intend to change iteratively and then run the command in the terminal. dataplane_latencybound = 200 # The delay bounds are in milli seconds controlplane_latencybound1 = 200 # The delay bounds are in milli seconds So, in every iteration, I would like to increase it from 0 in steps of 10 till 200. And after doing so, I'd like to run the command. But, I'm unaware of doing this using a single script. I hope some of you experts over there could help me in this issue. It can be a huge timesaver. Thanks a lot guys Varun RS -- https://mail.python.org/mailman/listinfo/python-list
Re: Running a .py file iteratively at the terminal
Thanks a lot Mark but that would be a bit trivial. How can I run the same file multiple times? Or if I need to run two commands: srva@hades:~$ python NFV_nw_eu_v3_14_1_15.py --output eu_v3_14_1_15 --demand demands_v3_21_1_15.xml --xml nobel-eu.xml srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml repeatedly, how can I do that? Can I write a script to perform this function?If so, can you please help me with it? The first command generates an output file eu_v3 and the second file feeds it to the solver. This is what I intend to do multiple times. I hope I have explained it this time in a much better way. I'm sorry English is my second language and I have some problems in expressing myself at times. Thank You -- https://mail.python.org/mailman/listinfo/python-list
Help in using grako for parsing
Hello, I am trying to parse a file which ahs the below content. I tried using the split function but that wasn't a good programming practice. I had to use it repeatedly to split the line and then read my data. I thought of doing it in a better way which is when I came across grako. But I have no idea whatsoever about the usage of grako in a script. It would be nice if any of you could help me understand the usage of grako. I need to extract the values beside the variables z, f and x. The numbers represent the request ID, virtualNode ID and physical nodeID for x and it varies a bit for f, Thanks a lot z_0 1.00 x_0_0_1 1.00 x_0_1_5 1.00 x_0_2_20 1.00 x_0_3_21 1.00 x_0_4_8 1.00 f_0_0(0,1)_(1,5) 1.00 f_0_1(1,2)_(5,9) 1.00 f_0_1(1,2)_(9,20)1.00 f_0_2(2,3)_(2,21)1.00 f_0_2(3,2)_(2,22)1.00 f_0_2(2,3)_(20,22) 1.00 f_0_3(4,3)_(8,10)1.00 f_0_3(3,4)_(0,10)1.00 f_0_3(4,3)_(0,14)1.00 f_0_3(4,3)_(14,21) 1.00 z_1 1.00 x_1_0_16 1.00 x_1_1_6 1.00 x_1_2_13 1.00 x_1_3_0 1.00 x_1_4_25 1.00 x_1_5_15 1.00 x_1_6_19 1.00 f_1_0(1,0)_(6,16)1.00 f_1_1(0,2)_(6,11)1.00 f_1_1(0,2)_(11,13) 1.00 f_1_1(2,0)_(6,16)1.00 f_1_2(3,1)_(0,6) 1.00 f_1_3(2,4)_(13,25) 1.00 f_1_4(5,4)_(15,25) 1.00 f_1_5(3,6)_(0,1) 1.00 f_1_5(3,6)_(1,18)1.00 f_1_5(3,6)_(18,19) 1.00 -- https://mail.python.org/mailman/listinfo/python-list
Re: Help in using grako for parsing
I'm really sorry for not being clear. I shall explain things in detail from now onwards. Really sorry. The output I would like is RF schema=RF.xsd version= VNE requests request ID='0' virtualnodes virtualnode PhysicalNode_ID='1' Request_ID='0' VirtualNode_ID='0'/virtualnode PhysicalNode_ID='5' Request_ID='0' VirtualNode_ID='1'/virtualnode PhysicalNode_ID='20' Request_ID='0' VirtualNode_ID='2'/virtualnode PhysicalNode_ID='21' Request_ID='0' VirtualNode_ID='3'/virtualnode PhysicalNode_ID='8' Request_ID='0' VirtualNode_ID='4'//virtualnodes virtualedges virtualedge PhysicalEdgeHead_ID='5' PhysicalEdgeTail_ID='1' Request_ID='0' VirtualEdgeHead_ID='1' VirtualEdgeTail_ID='0'/virtualedge PhysicalEdgeHead_ID='9' PhysicalEdgeTail_ID='5' Request_ID='0' VirtualEdgeHead_ID='2' VirtualEdgeTail_ID='1'/virtualedge PhysicalEdgeHead_ID='20' PhysicalEdgeTail_ID='9' Request_ID='0' VirtualEdgeHead_ID='2' VirtualEdgeTail_ID='1'/virtualedge PhysicalEdgeHead_ID='21' PhysicalEdgeTail_ID='2' Request_ID='0' VirtualEdgeHead_ID='3' VirtualEdgeTail_ID='2'/virtualedge PhysicalEdgeHead_ID='22' PhysicalEdgeTail_ID='2' Request_ID='0' VirtualEdgeHead_ID='2' VirtualEdgeTail_ID='3'/virtualedge PhysicalEdgeHead_ID='22' PhysicalEdgeTail_ID='20' Request_ID='0' VirtualEdgeHead_ID='3' VirtualEdgeTail_ID='2'/virtualedge PhysicalEdgeHead_ID='10' PhysicalEdgeTail_ID='8' Request_ID='0' VirtualEdgeHead_ID='3' VirtualEdgeTail_ID='4'/virtualedge PhysicalEdgeHead_ID='10' PhysicalEdgeTail_ID= '0' Request_ID='0' VirtualEdgeHead_ID='4' VirtualEdgeTail_ID='3'/virtualedge PhysicalEdgeHead_ID='14' PhysicalEdgeTail_ID='0' Request_ID='0' VirtualEdgeHead_ID='3' VirtualEdgeTail_ID='4'/virtualedge PhysicalEdgeHead_ID='21' PhysicalEdgeTail_ID='14' Request_ID='0' VirtualEdgeHead_ID='3' VirtualEdgeTail_ID='4'//virtualedges In a similar way I have something like this for every request. This is what I intend to get from the input that I had pasted earlier. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help in using grako for parsing
Oh damn, it turned out really crappy. I could not format it properly -- https://mail.python.org/mailman/listinfo/python-list
reading output from a .sol file
Hello everyone, I have a .sol file at my hand and I wish to make it an xml file so that its a bit more convenient to read and skim off data from an xml file. But to do that, I need to write a function to read the values in the .sol file. What I intend is when I read the line z_ something, i need to have a request tree and based on the number that follows the underscore, i will update the id of the request...but for the f_0_0(0,1)_(1,5) category, its a bit tricky. excluding the first few, when I read the contents in the brackets, the first set (0,1) means the virtual link and i update the xml with this and the second set (1,5) indicates the physical link on which the virtual link is placed. This is where I need your help. I tried writing one but I found it too hard. Hopefully you guys help me out or point me to the relevant sources for more information. Sorry for the trouble and thanks a lot z_0 1.00 x_0_0_1 1.00 x_0_1_5 1.00 x_0_2_20 1.00 x_0_3_21 1.00 x_0_4_8 1.00 f_0_0(0,1)_(1,5) 33.80 f_0_1(1,2)_(5,9) 51.10 f_0_1(1,2)_(9,20)51.10 f_0_2(2,3)_(2,21)33.30 f_0_2(3,2)_(2,22)33.30 f_0_2(3,2)_(18,19) 2.90 f_0_2(2,3)_(18,25) 2.90 f_0_2(3,2)_(19,20) 2.90 f_0_2(2,3)_(20,22) 33.30 f_0_2(3,2)_(21,25) 2.90 f_0_3(3,4)_(5,8) 48.00 f_0_3(4,3)_(5,25)48.00 f_0_3(3,4)_(21,25) 48.00 -- https://mail.python.org/mailman/listinfo/python-list
Representing mathematical equations
Hello, I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out? The equation looks like this b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]] / Σ(l∈L) l I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x) i,x,l are sets with different numbers Thank You I'm sorry if the equation is not expressed in a standard form. I don't have LateX -- https://mail.python.org/mailman/listinfo/python-list
Re: Representing mathematical equations
On Monday, 6 October 2014 13:14:04 UTC+2, varu...@gmail.com wrote: Hello, I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out? The equation looks like this b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]] / Σ(l∈L) l I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x) i,x,l are sets with different numbers Thank You I'm sorry if the equation is not expressed in a standard form. I don't have LateX Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links... b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i Thank You -- https://mail.python.org/mailman/listinfo/python-list
Re: Representing mathematical equations
On Monday, 6 October 2014 15:03:44 UTC+2, varu...@gmail.com wrote: On Monday, 6 October 2014 13:14:04 UTC+2, varu...@gmail.com wrote: Hello, I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out? The equation looks like this b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]] / Σ(l∈L) l I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x) i,x,l are sets with different numbers Thank You I'm sorry if the equation is not expressed in a standard form. I don't have LateX Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links... b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i Thank You Unbelievable. I again forgot to express them L = [(1,3), (5,7), .] bd = [23, 34,43.44.] dist = [3,7,5,7, ] hc = [2,3,4,1,2,2,...] for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7 -- https://mail.python.org/mailman/listinfo/python-list
Re: Davis putnam algorithm for satisfiability...
Thank you Cameron. Your post was very helpful. If you don't mind I'd like to ask you the purpose of the final list in the very beginning of the code. It is being updated and then checked for the presence of a literal. If a literal is found it returns not equivalent. Could you brief me the use of a final list? -- https://mail.python.org/mailman/listinfo/python-list
Davis putnam algorithm for satisfiability...
Hello friends, I have some trouble understanding the davis putnam algorithm for satisfiability. I understood most of the code but I don't know where exactly backtracking is happening here. Your assistance would be very helpful to me. import sys import math import copy final_list = [] def sat(cnf): while( len(cnf) 1 ): in_item = single_clause(cnf) #in_item: the first single_clause in cnf if in_item != None: del_sat(cnf, in_item) else: break for i in cnf: if len(i) == 0: cnf.remove(i) return if len(cnf) == 1: final_list.extend( [cnf[0][0]] ) # like a watchlist for i in range(0, len(final_list)): if final_list[i] 0: print Not equivalent! sys.exit(0) return final_list deep_copy = copy.deepcopy(cnf) list2 = cnf[0][0] del_sat(deep_copy,list2) # recursion to delete and then find another way and the proceed or delete more like a tree sat(deep_copy) del_sat(cnf,-list2) sat(cnf) return def parseXml(file_1, file_2): global cnf readfile_1 = open(file_1, r) readfile_2 = open(file_2, r) sum_a = int(readfile_1.readline()) sum_b = int(readfile_2.readline()) inputs_1 = readfile_1.readline().split() inputs_1.sort() inputs_2 = readfile_2.readline().split() inputs_2.sort() outputs_1 = readfile_1.readline().split() outputs_1.sort() outputs_2 = readfile_2.readline().split() outputs_2.sort() inputmap_1 = {} inputmap_2 = {} outputmap_1 = [] outputmap_2 = [] while True: line = readfile_1.readline().strip() if not line: break net,item = line.split() inputmap_1[item] = int(net) while True: line = readfile_2.readline().strip() if not line: break net,item = line.split() inputmap_2[item] = int(net) #print inputmap_2 for line in readfile_1.readlines(): inp1 = line.split() gate = inp1.pop(0) mapping = map(int, inp1) outputmap_1.extend([(gate, mapping)]) print 'outputmap_1' print outputmap_1 for line in readfile_2.readlines(): inp2 = line.split() gate = inp2.pop(0) mapping = map(int, inp2) outputmap_2.extend([(gate, mapping)]) return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 def single_clause(cnf): for i in cnf: if len(i) == 1: return i[0] return None def del_sat(cnf,in_item): cnf2 = cnf[:] for k in cnf2: if k.count(in_item): cnf.remove(k) for i in cnf: if i.count( -in_item): i.remove(-in_item) def cnf_out(miter): miter_len = len(miter) cnf = [] while (miter_len 0): x = miter.pop(0) if ( x[0] == and ): cnf.extend( [[x[1][0], -x[1][2]]] ) cnf.extend( [[x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] ) elif ( x[0] == or ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][2]]] ) cnf.extend( [[-x[1][1], x[1][2]]] ) elif ( x[0] == xor ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] ) cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] ) else: cnf.extend( [[x[1][0], x[1][1]]] ) cnf.extend( [[-x[1][0], -x[1][1]]] ) miter_len = miter_len - 1 return cnf inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 = parseXml(sys.argv[1], sys.argv[2]) incoming1=[] incoming2=[] outgoing1=[] outgoing2=[] for i in inputs_1: incoming1.extend([inputmap_1[i]]) for j in inputs_2: incoming2.extend([inputmap_2[j]]) for k in outputs_1: outgoing1.extend([inputmap_1[k]]) for l in outputs_2: outgoing2.extend([inputmap_2[l]]) gate_num = 0 for output in outputmap_1: for j in output[1]: if gate_num j: gate_num = j # gate_num: first line of netlist file. Total number of nets always need max no.. map2 = outputmap_2 num = len( map2 ) #No. of gates in netlist 2 for i in range(1, num + 1): j = len( map2[i-1][1] ) # Total No. of inputs and outputs of a gate for k in range(0, j): if map2[i-1][1][k] not in incoming2: total = 0 for l in incoming2: if map2[i-1][1][k] l: total = total + 1 # Total no. of nets minus total no. of input
Checking netlists for equivalence
Hello Everyone, I have tried to understand a code but I'm finding it extremely difficult in getting it through my head. I'd be glad if any of you could help me. I understood the parsexml function and I'm trying to understand the rest but finding it very hard. If any of you could spare your valuable time in explaining this code to me,I'd be very grateful and I also can learn a lot from your explanations. Thank You import sys import math import copy final_list = [] def sat(cnf): while( len(cnf) 1 ): in_item = single_clause(cnf) if in_item != None: del_sat(cnf, in_item) else: break for i in cnf: if len(i) == 0: cnf.remove(i) return if len(cnf) == 1: final_list.extend( [cnf[0][0]] ) for i in range(0, len(final_list)): #print final_list if final_list[i] 0: print final_list[i] print Not equivalent! sys.exit(0) return final_list deep_copy = copy.deepcopy(cnf) list2 = cnf[0][0] del_sat(deep_copy,list2) sat(deep_copy) del_sat(cnf,-list2) sat(cnf) return def parseXml(file_1, file_2): global cnf readfile_1 = open(file_1, r) readfile_2 = open(file_2, r) sum_a = int(readfile_1.readline()) sum_b = int(readfile_2.readline()) inputs_1 = readfile_1.readline().split() inputs_1.sort() inputs_2 = readfile_2.readline().split() inputs_2.sort() outputs_1 = readfile_1.readline().split() outputs_1.sort() outputs_2 = readfile_2.readline().split() outputs_2.sort() inputmap_1 = {} inputmap_2 = {} outputmap_1 = [] outputmap_2 = [] while True: line = readfile_1.readline().strip() if not line: break net,item = line.split() inputmap_1[item] = int(net) while True: line = readfile_2.readline().strip() if not line: break net,item = line.split() inputmap_2[item] = int(net) for line in readfile_1.readlines(): inp1 = line.split() gate = inp1.pop(0) mapping = map(int, inp1) outputmap_1.extend([(gate, mapping)]) for line in readfile_2.readlines(): inp2 = line.split() gate = inp2.pop(0) mapping = map(int, inp2) outputmap_2.extend([(gate, mapping)]) return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 def single_clause(cnf): for i in cnf: if len(i) == 1: return i[0] return None def del_sat(cnf,in_item): cnf2 = cnf[:] for k in cnf2: if k.count(in_item): cnf.remove(k) for i in cnf: if i.count( -in_item): i.remove(-in_item) def cnf_out(miter): miter_len = len(miter) cnf = [] while (miter_len 0): x = miter.pop(0) if ( x[0] == and ): cnf.extend( [[x[1][0], -x[1][2]]] ) cnf.extend( [[x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] ) elif ( x[0] == or ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][2]]] ) cnf.extend( [[-x[1][1], x[1][2]]] ) elif ( x[0] == xor ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] ) cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] ) else: cnf.extend( [[x[1][0], x[1][1]]] ) cnf.extend( [[-x[1][0], -x[1][1]]] ) miter_len = miter_len - 1 return cnf inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 = parseXml(sys.argv[1], sys.argv[2]) incoming1=[] incoming2=[] outgoing1=[] outgoing2=[] for i in inputs_1: incoming1.extend([inputmap_1[i]]) for j in inputs_2: incoming2.extend([inputmap_2[j]]) for k in outputs_1: outgoing1.extend([inputmap_1[k]]) for l in outputs_2: outgoing2.extend([inputmap_2[l]]) gate_num = 0 for output in outputmap_1: for j in output[1]: if gate_num j: gate_num = j map2 = outputmap_2 num = len( map2 ) for i in range(1, num + 1): j = len( map2[i-1][1] ) for k in range(0, j): if map2[i-1][1][k] not in incoming2: total = 0 for l in incoming2: if map2[i-1][1][k] l: total = total + 1 map2[i-1][1][k] = map2[i-1][1][k] + gate_num - total else: x = incoming2.index( map2[i-1][1][k] ) map2[i-1][1][k] = incoming1[x] miter = outputmap_1
Is this sort of a constraint implementable in Python?
Hello Everyone, I'm working on a python code to input matrices into CPLEX solver. I have most of my code running fine but as of now, I don't know how to express this constraint. My objective is to minimize the number of nodes. I have got one of the weirdest looking constraints which I don't know how to express in Python because python basically takes matrices and inputs them into cplex. My constraint is as below. This was what I wrote in AMPL minimize phy_nodes: sum {w in PHY_NODES} x_ns[w] ; s.t. Phy_nodes_Eq{w in PHY_NODES, dns in DEMAND}: x_ns[w] = 1 == x_SGW[dns, w] + x_PGW[dns, w] + x_MME[dns, w] + x_IMS[dns, w] + x_PoP[dns, w] = 1 else x_SGW[dns, w] + x_PGW[dns, w] + x_MME[dns, w] + x_IMS[dns, w] + x_PoP[dns, w] = 0; Could you help me fix this problem? Thank You -- https://mail.python.org/mailman/listinfo/python-list
Re: Having trouble in expressing constraints in Python
Thanks a lot Ian. Your post helped me understand the problem in a much better way and I've solved the first objective thanks to you but incase of my second objective which is minimize the number of nodes, I have got one of the weirdest looking constraints which I don't know how to express in Python because python basically takes matrices and inputs them into cplex. My constraint is as below. Thsi was what I wrote in AMPL minimize phy_nodes: sum {w in PHY_NODES} x_ns[w] ; s.t. Phy_nodes_Eq{w in PHY_NODES, dns in DEMAND}: x_ns[w] = 1 == x_SGW[dns, w] + x_PGW[dns, w] + x_MME[dns, w] + x_IMS[dns, w] + x_PoP[dns, w] = 1 else x_SGW[dns, w] + x_PGW[dns, w] + x_MME[dns, w] + x_IMS[dns, w] + x_PoP[dns, w] = 0; Could you help me fix this problem? -- https://mail.python.org/mailman/listinfo/python-list
Having trouble in expressing constraints in Python
I have a problem in writing a constraint in Python. Firstly, I wrote the code in AMPL and it was working and I'm using Python for the reason that it is more suitable to handle large data. I managed to write the code quite fine except for one constraint(Link Mapping Constraint). I've attached pieces of code from both AMPL and Python. First part of it is the Link Capacity Constraint in AMPl followed by Python. Second part of the code is the Link Mapping Constraint and I wish to write it in a similar fashion. But, I'm not able to proceed with it. I really appreciate your help. subject to Link_Capacity_Constraints { (ns1, ns2) in PHY_LINKS}: sum {dns in DEMAND} ((f_eN_SGW[dns, ns1, ns2] * (MME_bdw[dns] + IMS_bdw[dns] + PoP_bdw[dns])) + (f_SGW_PGW[dns, ns1, ns2] * PoP_bdw[dns]) + (f_SGW_IMS[dns, ns1, ns2] * IMS_bdw[dns]) + (f_SGW_MME[dns, ns1, ns2] * MME_bdw[dns]) + (f_PGW_PoP[dns, ns1, ns2] * PoP_bdw[dns])) = capacity_bdw[ns1, ns2]; for edge in phy_network.edges: varNames = [] varCoeffs = [] for demand in demands: varNames.append(f_eN_SGW_{}_{}_{}.format(demand.demandID, edge.SourceID, edge.DestinationID)) varCoeffs.append(demand.MME_bdw + demand.IMS_bdw + demand.PoP_bdw ) varNames.append(f_SGW_PGW_{}_{}_{}.format(demand.demandID, edge.SourceID, edge.DestinationID)) varCoeffs.append(demand.PoP_bdw) varNames.append(f_SGW_IMS_{}_{}_{}.format(demand.demandID, edge.SourceID, edge.DestinationID)) varCoeffs.append(demand.IMS_bdw) varNames.append(f_SGW_MME_{}_{}_{}.format(demand.demandID, edge.SourceID, edge.DestinationID)) varCoeffs.append(demand.MME_bdw) varNames.append(f_PGW_PoP_{}_{}_{}.format(demand.demandID, edge.SourceID, edge.DestinationID)) varCoeffs.append(demand.PoP_bdw) solver.add_constraint(varNames, varCoeffs, L, edge.capacity_bdw, Link_Capacity_Constraints{}_{}_{}.format(edge.SourceID, edge.DestinationID, demand.demandID)) #Link Mapping Constraint subject to Link_Mapping_Constraints_1{dns in DEMAND, ns1 in PHY_NODES}: sum {(ns1,w) in PHY_LINKS} (f_eN_SGW[dns, w, ns1] - f_eN_SGW[dns, ns1, w]) = x_eN[dns, ns1] - x_SGW[dns, ns1]; -- https://mail.python.org/mailman/listinfo/python-list
Re: Having trouble in expressing constraints in Python
Are you trying to implement your own code rather than use an existing library from pypi? I borrowed the idea from a previous file which I was working on. I input variables and coefficients as lists and then inturn as matrices to the CPLEX. So, I have a problem with expressing the constraint in Python. -- https://mail.python.org/mailman/listinfo/python-list
Segmentation fault (core dumped) while using Cplex Python API
Hello Everyone, I am trying to solve a mixed-integer problem using Cplex Python API and I get this error Segmentation fault (core dumped). i am not able to figure out the reason for this. Traceback srva@hades:~$ python RW10.py --output test --logPath log --xml topology.xml Start Time: 2014-6-1-20-56-39 CPLEX Parameter File Version 12.5.0.0 CPX_PARAM_TILIM 3600 CPX_PARAM_TRELIM 2.00 CPX_PARAM_EPGAP 0.03 CPX_PARAM_EACHCUTLIM 21 CPX_PARAM_FLOWCOVERS 0 CPX_PARAM_FLOWPATHS 0 CPX_PARAM_CLIQUES 0 CPX_PARAM_DISJCUTS 0 CPX_PARAM_COVERS 0 CPX_PARAM_ZEROHALFCUTS 0 CPX_PARAM_MIRCUTS 0 CPX_PARAM_MCFCUTS 0 CPX_PARAM_IMPLBD 0 CPX_PARAM_GUBCOVERS 0 CPX_PARAM_AGGCUTLIM 3 Completion Time: 972.63 Num Columns: 1350888 Num Rows: 25488 Solving Segmentation fault (core dumped) A few lines from the log file: Completion Time: 972.63 Num Columns: 1350888 Num Rows: 25488 Tried aggregator 1 time. MIP Presolve eliminated 12648 rows and 1321088 columns. MIP Presolve modified 180 coefficients. Reduced MIP has 12840 rows, 29800 columns, and 136000 nonzeros. Reduced MIP has 29800 binaries, 0 generals, 0 SOSs, and 0 indicators. Presolve time = 0.49 sec. (368.57 ticks) I would be grateful if someone can help me fix this. Thank You -- https://mail.python.org/mailman/listinfo/python-list
Unable to figure out ' invalid matrix input type -- ', u'1'
Hello Everyone, I am currently working on Cplex using Python API. I have a problem when I run the code. I keep getting this error about the invalid matrix input but I'm not able to figure out what it is. I would be grateful if any of you could help. My function is as below def add_constraint(self, variables, coefficients, sense, rhs, name): self.prob.linear_constraints.add( lin_expr = [[ variables, coefficients ]], senses =[sense], rhs = [rhs], names = [name] ) Traceback (most recent call last): File RW10.py, line 569, in module main(sys.argv[1:]) File RW10.py, line 562, in main solveVNEProblem( phy_network, demands, args.output) File RW10.py, line 116, in solveVNEProblem solver.add_constraint( varNames, varCoeffs, E, 1.0, Location_Constraints1{}.format( demand.demandID ) ) File RW10.py, line 26, in add_constraint names = [name] ) File /opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_subinterfaces.py, line 1187, in add rmat = _C_HBMatrix(lin_expr, self._cplex._env_lp_ptr, 0, self._env.parameters.read.apiencoding.get()) File /opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_matrices.py, line 74, in __init__ raise TypeError( invalid matrix input type -- , self._mat[0]) TypeError: (' invalid matrix input type -- ', u'1') Thank You -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in writing demands to the xml file
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 xml is written but the demands doesn't have any attributes whatsoever. I could give 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) -- https://mail.python.org/mailman/listinfo/python-list
Problem in writing demands to the xml file
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 -- https://mail.python.org/mailman/listinfo/python-list
Re: Can't figure out 'instance has no attribute' error
On Sunday, 18 May 2014 01:56:42 UTC+2, varu...@gmail.com wrote: Hello Friends, I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? File RW1: class PHY_NETWORK: def __init__(self, nodes, edges): self.nodes = nodes self.edges = edges def addNode(self, node): self.nodes.append( node ) def addEdge(self, edge): self.edges.append( edge ) File RW3: def createnetwork(graph): doc = parse( args.paramFile ) noderef = [] num = 0 nodelist = doc.getElementsByTagName(node) for node in nodelist: noderef.append(node.getAttribute(id)) proc = random.randint(3500, 5000) stor = random.randint(7200, 8200) switch = random.randint(7000, 1) num = num + 1 totaldemands = random.randint(1, 5) graph.addNode(PHY_NODES( node.getAttribute(id), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) linkid = 0 linklist = doc.getElementsByTagName(link) for link in linklist : linkid = linkid + 1 Source = link.getElementsByTagName(source) [0] Destination = link.getElementsByTagName(target) [0] Capacity = link.getElementsByTagName(capacity) [0] SourceID = noderef.index(Source.firstChild.data) + 1 DestinationID = noderef.index(Destination.firstChild.data) + 1 graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) )) global args args = parser.parse_args() samplenetwork = PHY_NETWORK([], []) for i in range(1, 100): createnetwork(samplenetwork) exportXmlFile(samplenetwork, args.output, 'a' ) if __name__ == __main__: main(sys.argv[1:]) srva@hades:~$ python RW3.py --output topology.xml --xml germany50.xml Traceback (most recent call last): File RW3.py, line 157, in module main(sys.argv[1:]) File RW3.py, line 152, in main createnetwork(samplenetwork) File RW3.py, line 31, in createnetwork graph.addNode(PHY_NODES( node.getAttribute(id), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) AttributeError: PHY_NETWORK instance has no attribute 'addNode' The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You Thank you very much Ned, Rodri and Gary. I changed the settings of gedit text editor as mentioned in the Zed Shaw tutorial. I think this is causing me the problem. I'll follow your advice. -- https://mail.python.org/mailman/listinfo/python-list
Can't figure out 'instance has no attribute' error
Hello Friends, I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? File RW1: class PHY_NETWORK: def __init__(self, nodes, edges): self.nodes = nodes self.edges = edges def addNode(self, node): self.nodes.append( node ) def addEdge(self, edge): self.edges.append( edge ) File RW3: def createnetwork(graph): doc = parse( args.paramFile ) noderef = [] num = 0 nodelist = doc.getElementsByTagName(node) for node in nodelist: noderef.append(node.getAttribute(id)) proc = random.randint(3500, 5000) stor = random.randint(7200, 8200) switch = random.randint(7000, 1) num = num + 1 totaldemands = random.randint(1, 5) graph.addNode(PHY_NODES( node.getAttribute(id), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) linkid = 0 linklist = doc.getElementsByTagName(link) for link in linklist : linkid = linkid + 1 Source = link.getElementsByTagName(source) [0] Destination = link.getElementsByTagName(target) [0] Capacity = link.getElementsByTagName(capacity) [0] SourceID = noderef.index(Source.firstChild.data) + 1 DestinationID = noderef.index(Destination.firstChild.data) + 1 graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) )) global args args = parser.parse_args() samplenetwork = PHY_NETWORK([], []) for i in range(1, 100): createnetwork(samplenetwork) exportXmlFile(samplenetwork, args.output, 'a' ) if __name__ == __main__: main(sys.argv[1:]) srva@hades:~$ python RW3.py --output topology.xml --xml germany50.xml Traceback (most recent call last): File RW3.py, line 157, in module main(sys.argv[1:]) File RW3.py, line 152, in main createnetwork(samplenetwork) File RW3.py, line 31, in createnetwork graph.addNode(PHY_NODES( node.getAttribute(id), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) AttributeError: PHY_NETWORK instance has no attribute 'addNode' The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help to write data onto an XML file after reading data from another xml file
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 -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help to write data onto an XML file after reading data from another xml file
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 do with that file is basically define classes. I have defined all the classes that 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 a lot for your help -- https://mail.python.org/mailman/listinfo/python-list
Need help to write data onto an XML file after reading data from another xml file
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=germany50format=xmlobjectType=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 -- https://mail.python.org/mailman/listinfo/python-list
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. http://sndlib.zib.de/coredata.download.action?objectName=germany50format=xmlobjectType=network 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' to node IDs Berlin and Leipzig, I need to use the same node numbers at the links as well. For example, L22 has sourceLeipzig/source targetBerlin/target 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): self.id = 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: % (self.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.inEdges.append(edge) self.capacity_bidirect = capacity_bidirect + edge.capacity def addOutEdge (self, edge): self.outEdges.append(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) class PHY_NETWORK: 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 else: 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[ node.name ] = node.id 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 : nodes.append(node.getAttribute(id)) #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, 1) num = num + 1 nodes.append(PHY_NODES( node.getAttribute(id), int(num), float(xCoodinates.firstChild.data), float(yCoordinates.firstChild.data), 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 =
Re: Designing a network in Python
On Wednesday, 30 April 2014 20:38:07 UTC+2, Joseph L. Casale wrote: I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the xml file like the node-name, source, destination and the capacity. Since, I am done with that part, I now want to have a link between source and destination and assign capacity to it. I dont mind writing you an SQLite schema and accessor class, can you define your data in a tabular format and mail it to me offline, we add relationships etc as we go. Hopefully it inspires you to adopt this approach in the future as it often proves powerful. jlc Thanks a lot for your help. But, how do I mail you? I can't find your mail id here -- https://mail.python.org/mailman/listinfo/python-list
Designing a network in Python
Hello Friends I would like to design a network given the topology and the source I use is http://sndlib.zib.de/home.action I have managed to read most of the important data in the xml onto lists. Now, I have two lists, Source and Destination and I'd like to create bi-directional links between them. My code is as below. And moreover, I'd like to assign some kind of a bandwidth capacity to the links and similarly, storage and processing capacity to the nodes. So, I generated some random integers for them. I don't know how to proceed further to design the topology. I'd prefer to do the topology design in another .py file probably. I'd be glad if you guys could lend me a helping hand. import sys import xml.dom.minidom as dom import string #from xml.dom.minidom import getDOMimplementation from xml.dom import minidom from xml.dom.minidom import parse import os import random class PHY_NODES: def __init__(self, nodeID, x, y, capacity_proc, capacity_stor, capacity_switch): self.nodeID = nodeID self.x = x self.y = y self.linklist = [] self.capacity_proc = capacity_proc self.capacity_stor = capacity_stor self.capacity_switch = capacity_switch class PHY_LINKS: def __init__(self, linkID, source, destination, capacity_bdw): self.linkID = linkID self.source = source self.destination = destination self.capacity_bdw = capacity_bdw # Reading Nodes Read_Data = minidom.parse(germany50.xml) nodelist = Read_Data.getElementsByTagName(node) corenodes = [] for node in nodelist : corenodes.append(node.getAttribute(id)) nodeid = node.getAttribute(id) xCoordinates = node.getElementsByTagName(x) [0] yCoordinates = node.getElementsByTagName(y) [0] proc = random.randint(20, 40) stor = random.randint(40, 80) switch = random.randint(60, 90) nodeobj = PHY_NODES(nodeid, xCoordinates, yCoordinates, proc, stor, switch) # Reading Links linklist = Read_Data.getElementsByTagName(link) links = [] sources = [] destinations = [] capacity_link = [] for link in linklist : linkid = link.getAttribute(id) Source = link.getElementsByTagName(source) [0] Destination = link.getElementsByTagName(target) [0] Capacity = link.getElementsByTagName(capacity) [0] linkobj = PHY_LINKS(linkid, Source, Destination, Capacity) sources.append(Source.firstChild.data) destinations.append(Destination.firstChild.data) capacity_link.append(Capacity.firstChild.data) -- https://mail.python.org/mailman/listinfo/python-list
Re: Designing a network in Python
I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the xml file like the node-name, source, destination and the capacity. Since, I am done with that part, I now want to have a link between source and destination and assign capacity to it. eg., [a,b,c,d,e] [l,m,n,o,p] [5,2,3,4,5] I need something like a - l: 5, b - m: 2,I don't know how to describe this exactly but I hope this would give you a rough idea. After this, I put the stuff back into an xml but this time only there are more parameters and looks more detailed Like nodeID = Aachen...stor_capacity = 100, proc_capacity = 200, switch_capacity = 190...etc -- https://mail.python.org/mailman/listinfo/python-list