Răsfoiți Sursa

fix bug. dealing with float weights

jkunlin 8 ani în urmă
părinte
comite
1acbb6507e
1 a modificat fișierele cu 2 adăugiri și 2 ștergeri
  1. 2 2
      graphml2dimacs.py

+ 2 - 2
graphml2dimacs.py

@@ -24,7 +24,7 @@ for elem in root:
     if elem.tag == namespace + 'node':
     if elem.tag == namespace + 'node':
         # print (elem.attrib['id'], " weight: ")
         # print (elem.attrib['id'], " weight: ")
         node_map[elem.attrib['id']] = nodex_index
         node_map[elem.attrib['id']] = nodex_index
-        while len(adjacency_list) < nodex_index:
+        while len(adjacency_list) - 1 < nodex_index:
             adjacency_list.append([])
             adjacency_list.append([])
         nodex_index += 1
         nodex_index += 1
 
 
@@ -33,7 +33,7 @@ for elem in root:
             # print (sub_elem.attrib['key'])
             # print (sub_elem.attrib['key'])
             if sub_elem.attrib['key'] == weight_id:
             if sub_elem.attrib['key'] == weight_id:
                 # print (sub_elem.text)
                 # print (sub_elem.text)
-                node_weight.append(int(sub_elem.text))
+                node_weight.append(int(float(sub_elem.text)))
     # get edge
     # get edge
     elif elem.tag == namespace + 'edge':
     elif elem.tag == namespace + 'edge':
         source_index = node_map[elem.attrib['source']]
         source_index = node_map[elem.attrib['source']]