|
|
@@ -17,7 +17,7 @@ def print_results(graph):
|
|
|
for edge in graph.edge_iter():
|
|
|
label = graph.edge_get_label(edge)
|
|
|
s, t = graph.get_edge(edge)
|
|
|
- print(" ", s, "-[ %s ]->" % label, t)
|
|
|
+ print(" ", s, "-[ %s ]->" % str(label), t)
|
|
|
|
|
|
# TODO: Read from DrawIO
|
|
|
# TODO: Select graph based on Formalism name and instance name
|
|
|
@@ -53,27 +53,46 @@ r1n2 = r1NAC.add_node("State", False)
|
|
|
r1NAC.node_set_attribute(r1n2, Himesis.Constants.MT_LABEL, '1')
|
|
|
r1n3 = r1NAC.add_node("Place", False)
|
|
|
r1NAC.node_set_attribute(r1n3, Himesis.Constants.MT_LABEL, '2')
|
|
|
-r1n4 = r1NAC.add_node("Link", True)
|
|
|
-r1NAC.node_set_attribute(r1n4, Himesis.Constants.MT_LABEL, '3')
|
|
|
-r1NAC.link_nodes(r1n2, r1n4)
|
|
|
-r1NAC.link_nodes(r1n4, r1n3)
|
|
|
+r1NAC.link_nodes(r1n2, r1n3)
|
|
|
r1LHS.addNAC(r1NAC)
|
|
|
|
|
|
r1RHS = HimesisPostConditionPattern("r1RHS", getMvSBackend(MvSKernel.IGRAPH))
|
|
|
-r1n5 = r1RHS.add_node("State", False)
|
|
|
-r1RHS.node_set_attribute(r1n5, Himesis.Constants.MT_LABEL, '1')
|
|
|
-r1n6 = r1RHS.add_node("Place", False)
|
|
|
-r1RHS.node_set_attribute(r1n6, Himesis.Constants.MT_LABEL, '2')
|
|
|
-r1n7 = r1RHS.add_node("Link", True)
|
|
|
-r1RHS.node_set_attribute(r1n7, Himesis.Constants.MT_LABEL, '3')
|
|
|
-r1RHS.link_nodes(r1n5, r1n7)
|
|
|
-r1RHS.link_nodes(r1n7, r1n6)
|
|
|
-
|
|
|
-print("Applying FRule 1")
|
|
|
-frule = FRule(r1LHS, r1RHS)
|
|
|
-FSA2PN = frule.packet_in(Packet(FSA))
|
|
|
-
|
|
|
-print_results(FSA2PN.graph)
|
|
|
+r1n4 = r1RHS.add_node("State", False)
|
|
|
+r1RHS.node_set_attribute(r1n4, Himesis.Constants.MT_LABEL, '1')
|
|
|
+r1n5 = r1RHS.add_node("Place", False)
|
|
|
+r1RHS.node_set_attribute(r1n5, Himesis.Constants.MT_LABEL, '2')
|
|
|
+r1RHS.link_nodes(r1n4, r1n5)
|
|
|
+
|
|
|
+def action(mapper, H: Himesis):
|
|
|
+ attr = H.node_get_attribute(mapper['1'], "name")
|
|
|
+ H.node_set_attribute(mapper['2'], "name", "P(%s)" % attr)
|
|
|
+ return {} # TODO?
|
|
|
+
|
|
|
+r1RHS[Himesis.Constants.MT_ACTION] = action
|
|
|
+
|
|
|
+# print("NAC:")
|
|
|
+# print_results(r1NAC)
|
|
|
+# print("\nLHS:")
|
|
|
+# print_results(r1LHS)
|
|
|
+# print("\nRHS:")
|
|
|
+# print_results(r1RHS)
|
|
|
+
|
|
|
+print("Applying ARule")
|
|
|
+r1NAC[Himesis.Constants.MT_CONSTRAINT] = lambda a, b: True
|
|
|
+r1LHS[Himesis.Constants.MT_CONSTRAINT] = lambda a, b: True
|
|
|
+r1RHS.pre = r1LHS
|
|
|
+r1RHS.pre_labels = []
|
|
|
+for v in r1LHS.node_guid_iter():
|
|
|
+ r1RHS.pre_labels.append(r1LHS.node_get_attribute(v, Himesis.Constants.MT_LABEL))
|
|
|
+arule = FRule(r1LHS, r1RHS, sendAndApplyDeltaFunc=lambda x: None)
|
|
|
+FSA2PN = arule.packet_in(Packet(FSA))
|
|
|
+
|
|
|
+if arule.exception:
|
|
|
+ print(arule.exception)
|
|
|
+else:
|
|
|
+ # import igraph as ig
|
|
|
+ # ig.plot(FSA2PN.graph.state.graph, "result.png")
|
|
|
+ print_results(FSA2PN.graph)
|
|
|
|
|
|
|
|
|
|