Browse Source

Working global constraints on LHS

Yentl Van Tendeloo 8 years ago
parent
commit
a8ef463dec
3 changed files with 26 additions and 1 deletions
  1. BIN
      bootstrap/bootstrap.m.gz
  2. 15 0
      bootstrap/transform.alc
  3. 11 1
      integration/test_pn_interface.py

BIN
bootstrap/bootstrap.m.gz


+ 15 - 0
bootstrap/transform.alc

@@ -156,6 +156,21 @@ Element function match(host_model : Element, LHS_model : Element):
 
 		mappings = new_mappings
 
+	// Finished, so try the global constraint
+	Element LHS
+	Element constraint
+
+	new_mappings = create_node()
+	LHS = allInstances(LHS_model, "LHS")
+	LHS = set_pop(LHS)
+	constraint = read_attribute(LHS_model, LHS, "constraint")
+	if (element_neq(constraint, read_root())):
+		while (read_nr_out(mappings) > 0):
+			map = set_pop(mappings)
+			if (constraint(host_model, map)):
+				set_add(new_mappings, map)
+		mappings = new_mappings
+
 	return mappings!
 
 Void function rewrite(host_model : Element, RHS_model : Element, mapping : Element):

+ 11 - 1
integration/test_pn_interface.py

@@ -549,11 +549,19 @@ Integer function value(host_model : Element, RHS_model : Element):
             """
 include "primitives.alh"
 Boolean function constraint(host_model : Element, name : String):
-\treturn value_eq(host_model["model"][name], 3)!
+\treturn value_eq(host_model["model"][name], 1)!
+            """
+
+        global_constraint_code = \
+            """
+include "primitives.alh"
+Boolean function constraint(host_model : Element, mapping : Element):
+\treturn value_eq(host_model["model"][mapping["0_tokens"]], 1)!
             """
 
         constructor_action = get_constructor(action_code)
         constructor_constraint = get_constructor(constraint_code)
+        constructor_global_constraint = get_constructor(global_constraint_code)
 
         self.assertTrue(run_file(all_files,
             ["new", "PetriNets", "pn",
@@ -587,6 +595,8 @@ Boolean function constraint(host_model : Element, name : String):
                 "attr_add", "p", "label", "2_p",
                 "attr_add", "t", "label", "3_t",
                 "attr_add", "pt", "label", "4_pt",
+                "attr_add_code", "lhs", "constraint",
+            ] + constructor_global_constraint + [
                 "exit",
              "new", "PetriNets_POST", "pn_RHS",
                 "instantiate", "RHS", "rhs",