Browse Source

Decision making seems to be successful

Yentl Van Tendeloo 7 years ago
parent
commit
def1859dc4
2 changed files with 37 additions and 21 deletions
  1. 36 20
      kernel/rules/to_python.alc
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 36 - 20
kernel/rules/to_python.alc

@@ -2,6 +2,7 @@ include "primitives.alh"
 include "modelling.alh"
 include "modelling.alh"
 include "object_operations.alh"
 include "object_operations.alh"
 include "random.alh"
 include "random.alh"
+include "utils.alh"
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
 	String result
 	String result
@@ -18,6 +19,7 @@ Boolean function main(model : Element):
 	String rule
 	String rule
 	String value
 	String value
 	Element explored
 	Element explored
+	Element remainder_to_explore
 
 
 	explored = set_create()
 	explored = set_create()
 	result = "root, = yield [('RR', [])]\n"
 	result = "root, = yield [('RR', [])]\n"
@@ -29,6 +31,7 @@ Boolean function main(model : Element):
 
 
 		// Keep following outgoing edges to find matching nodes
 		// Keep following outgoing edges to find matching nodes
 		to_explore = set_create()
 		to_explore = set_create()
+		remainder_to_explore = set_create()
 		set_add(to_explore, node)
 		set_add(to_explore, node)
 
 
 		while (set_len(to_explore) > 0):
 		while (set_len(to_explore) > 0):
@@ -44,27 +47,40 @@ Boolean function main(model : Element):
 					// Is a match node, so fetch the value on the edge
 					// Is a match node, so fetch the value on the edge
 					name = read_attribute(model, edge, "value")
 					name = read_attribute(model, edge, "value")
 					destination = string_replace(new_node, "/", "_")
 					destination = string_replace(new_node, "/", "_")
-					if (set_in(explored, destination)):
-						// Already visited this one in another way, so try to merge!
-						String rand
-						rand = random_string(10)
-						result = result + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
-						result = result + "if " + rand + " != " + destination + ":\n"
-						// If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
-						result = result + "\t" + destination + " = None\n"
+
+					if (element_eq(name, read_root())):
+						String node_key
+						node_key = string_replace(set_pop(allAssociationDestinations(model, edge, "")), "/", "_")
+						if (set_in(explored, node_key)):
+							result = result + destination + ", = yield [('RDN', [" + source + ", " + node_key + "])]\n"
+						else:
+							set_add(remainder_to_explore, node)
 					else:
 					else:
-						// First visit to this element, so just assign
-						result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
-						set_add(explored, destination)
-
-						String value
-						value = read_attribute(model, new_node, "value")
-						if (element_neq(value, read_root())):
-							// Match node has a value we should compare as well!
-							// Read out the value from the Modelverse
-							result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
-
-						set_add(to_explore, new_node)
+						if (set_in(explored, destination)):
+							// Already visited this one in another way, so try to merge!
+							String rand
+							rand = random_string(10)
+							result = result + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+							result = result + "if " + rand + " != " + destination + ":\n"
+							// If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
+							result = result + "\t" + destination + " = None\n"
+						else:
+							// First visit to this element, so just assign
+							result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+							set_add(explored, destination)
+
+							String value
+							value = read_attribute(model, new_node, "value")
+							if (element_neq(value, read_root())):
+								// Match node has a value we should compare as well!
+								// Read out the value from the Modelverse
+								result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
+
+							set_add(to_explore, new_node)
+
+			if (bool_and(set_len(to_explore) == 0, set_len(remainder_to_explore) > 0)):
+				to_explore = remainder_to_explore
+				remainder_to_explore = set_create()
 
 
 	rules = allInstances(model, "Rules/Rule")
 	rules = allInstances(model, "Rules/Rule")
 	while (set_len(rules) > 0):
 	while (set_len(rules) > 0):

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Fri Nov 24 12:36:49 2017
+Date:   Fri Nov 24 13:18:47 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server