浏览代码

LoLAConvert: Handle renamed places/transitions.

bentleyjoakes 5 年之前
父节点
当前提交
d4099a4b11
共有 1 个文件被更改,包括 22 次插入14 次删除
  1. 22 14
      LoLAConvert.py

+ 22 - 14
LoLAConvert.py

@@ -16,16 +16,18 @@ class LoLAConvert:
         print("Arcs: " + str(arcs))
 
         places_with_markings = []
-        for place, marking in places.items():
+        for p_id, p_data in places.items():
+            p_name, marking = p_data
             if int(marking) > 0:
-                places_with_markings.append((place, marking))
+                places_with_markings.append((p_id, p_name, marking))
 
         lola_file = filename.replace(".xml", ".lola")
         with open(lola_file, 'w') as f:
             f.write("PLACE\n")
 
-            for i, place in enumerate(places):
-                f.write("\t" + place)
+            for i, p_id in enumerate(places):
+                p_name, marking = places[p_id]
+                f.write("\t" + p_name)
                 if i < len(places) - 1:
                     f.write(",\n")
                 else:
@@ -33,34 +35,34 @@ class LoLAConvert:
 
             f.write("\nMARKING\n")
             for i, pm in enumerate(places_with_markings):
-                f.write("\t" + pm[0] + " : " + pm[1])
+                f.write("\t" + pm[1] + " : " + pm[2])
                 if i < len(places_with_markings) - 1:
                     f.write(",\n")
                 else:
                     f.write(";\n")
 
-            for trans in transitions:
-                f.write("\nTRANSITION " + trans + "\n")
+            for trans_id, trans_name in transitions.items():
+                f.write("\nTRANSITION " + trans_name + "\n")
                 consume = {}
                 produce = {}
 
                 for arc in arcs:
                     s, t, w = arc
-                    if t == trans:
+                    if t == trans_id:
                         consume[s] = w
-                    elif s == trans:
+                    elif s == trans_id:
                         produce[t] = w
 
                 f.write("\tCONSUME\n")
                 for i, s in enumerate(consume):
-                    f.write("\t\t" + s + " : " + consume[s])
+                    f.write("\t\t" + places[s][0] + " : " + consume[s])
                     if i < len(consume) - 1:
                         f.write(",\n")
                     else:
                         f.write(";\n")
                 f.write("\tPRODUCE\n")
                 for i, t in enumerate(produce):
-                    f.write("\t\t" + t + " : " + produce[t])
+                    f.write("\t\t" + places[t][0] + " : " + produce[t])
                     if i < len(produce) - 1:
                         f.write(",\n")
                     else:
@@ -74,26 +76,32 @@ class LoLAConvert:
         net = root[0]
 
         places = {}
-        transitions = []
+        transitions = {}
         arcs = []
 
         for child in net:
 
             if child.tag == "place":
+                p_id = child.get("id")
+
                 name_node = self.get_child_with_name(child, "name")
                 name = self.get_child_with_name(name_node, "value").text
+                name = name.replace(" ", ".")
 
                 marking_node = self.get_child_with_name(child, 'initialMarking')
                 marking_value_node = self.get_child_with_name(marking_node, 'value')
                 marking = marking_value_node.text.split(",")[1]
 
-                places[name] = marking
+                places[p_id] = (name, marking)
 
             elif child.tag == "transition":
+                t_id = child.get("id")
+
                 name_node = self.get_child_with_name(child, "name")
                 name = self.get_child_with_name(name_node, "value").text
+                name = name.replace(" ", ".")
 
-                transitions.append(name)
+                transitions[t_id] = name
 
             elif child.tag == "arc":
                 source = child.get("source")