Browse Source

Working matching with some additional checks

Yentl Van Tendeloo 8 years ago
parent
commit
7694c10521
3 changed files with 41 additions and 9 deletions
  1. BIN
      bootstrap/bootstrap.m.gz
  2. 39 6
      bootstrap/transform.alc
  3. 2 3
      integration/test_pn_interface.py

BIN
bootstrap/bootstrap.m.gz


+ 39 - 6
bootstrap/transform.alc

@@ -77,16 +77,21 @@ Element function get_possible_bindings(host_model : Element, LHS_model : Element
 
 
 		if (bool_and(set_in(dict_keys(map), src_label), set_in(dict_keys(map), dst_label))):
 		if (bool_and(set_in(dict_keys(map), src_label), set_in(dict_keys(map), dst_label))):
 			// Source and destination are bound
 			// Source and destination are bound
+			log("MERGE")
 			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
 			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
-			options = set_overlap(options, allIncomingAssociationInstances(host_model, map[src_label], original_typename))
+			log("SRC: " + set_to_string(allOutgoingAssociationInstances(host_model, map[src_label], original_typename)))
+			log("DST: " + set_to_string(allIncomingAssociationInstances(host_model, map[dst_label], original_typename)))
+			options = set_overlap(options, allIncomingAssociationInstances(host_model, map[dst_label], original_typename))
 
 
 		elif (set_in(dict_keys(map), src_label)):
 		elif (set_in(dict_keys(map), src_label)):
 			// Source is bound
 			// Source is bound
+			log("SOURCE")
 			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
 			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
 
 
 		elif (set_in(dict_keys(map), dst_label)):
 		elif (set_in(dict_keys(map), dst_label)):
 			// Destination is bound
 			// Destination is bound
-			options = allIncomingAssociationInstances(host_model, map[src_label], original_typename)
+			log("DESTINATION")
+			options = allIncomingAssociationInstances(host_model, map[dst_label], original_typename)
 
 
 		else:
 		else:
 			// Neither is bound, so just get all of them
 			// Neither is bound, so just get all of them
@@ -96,11 +101,37 @@ Element function get_possible_bindings(host_model : Element, LHS_model : Element
 		// Is a node, so check for already bound incoming/outgoing
 		// Is a node, so check for already bound incoming/outgoing
 		options = allInstances(host_model, original_typename)
 		options = allInstances(host_model, original_typename)
 
 
-	// Filter out duplicate matches from the map
+	// Filter options further
+	Element filtered_options
+	String option
 
 
-	// Filter out based on local constraints
+	filtered_options = create_node()
+	log("Checking options")
+	while (read_nr_out(options) > 0):
+		option = set_pop(options)
+		// Check for detecting same element twice
+		log("Option: " + cast_v2s(option))
+		if (bool_not(set_in(map, option))):
+			// Option is already present with another label, so skip this!
+
+			// Check for local constraints of element
+			if (element_eq(read_attribute(LHS_model, current_element, "constraint"), read_root())):
+				// No local constraints, so all is well
+				log("No constraints, so ignore")
+				set_add(filtered_options, option)
+			else:
+				log("Verify constraints first")
+				// Check local constraints and add only if positive
+				Element constraint_function
+				constraint_function = read_attribute(LHS_model, current_element, "constraint")
+				Boolean result
+				result = constraint_function(host_model, option)
+				if (result):
+					set_add(filtered_options, option)
+		else:
+			log("ERROR: already matched")
 
 
-	return options!
+	return filtered_options!
 
 
 Element function match(host_model : Element, LHS_model : Element):
 Element function match(host_model : Element, LHS_model : Element):
 	// Match the LHS_model to the host_model, returning all possible mappings from LHS_model elements to host_model elements
 	// Match the LHS_model to the host_model, returning all possible mappings from LHS_model elements to host_model elements
@@ -122,7 +153,7 @@ Element function match(host_model : Element, LHS_model : Element):
 	set_add(mappings, create_node())
 	set_add(mappings, create_node())
 	while (bool_and(read_nr_out(schedule) > 0, read_nr_out(mappings) > 0)):
 	while (bool_and(read_nr_out(schedule) > 0, read_nr_out(mappings) > 0)):
 		current_element = list_pop(schedule, 0)
 		current_element = list_pop(schedule, 0)
-		log("Finding options for " + current_element)
+		log("Finding options for " + cast_v2s(read_attribute(LHS_model, current_element, "label")))
 		new_mappings = create_node()
 		new_mappings = create_node()
 
 
 		while (read_nr_out(mappings) > 0):
 		while (read_nr_out(mappings) > 0):
@@ -153,11 +184,13 @@ Void function transform(host_model : Element, LHS_model : Element, RHS_model : E
 
 
 	// Get all possible mappings
 	// Get all possible mappings
 	mappings = match(host_model, LHS_model)
 	mappings = match(host_model, LHS_model)
+	log("Found total mappings: " + cast_v2s(read_nr_out(mappings)))
 
 
 	// Select one such mapping and rewrite it
 	// Select one such mapping and rewrite it
 	if (read_nr_out(mappings) > 0):
 	if (read_nr_out(mappings) > 0):
 		// Mapping found, so can rewrite it
 		// Mapping found, so can rewrite it
 		mapping = set_pop(mappings)
 		mapping = set_pop(mappings)
+		log("Found example mapping " + dict_to_string(mapping))
 		rewrite(host_model, RHS_model, mapping)
 		rewrite(host_model, RHS_model, mapping)
 	else:
 	else:
 		output("No mapping found!")
 		output("No mapping found!")

+ 2 - 3
integration/test_pn_interface.py

@@ -550,10 +550,9 @@ Element function constraint(model : Element, name : String):
                 "attr_add", "p2", "tokens", 2,
                 "attr_add", "p2", "tokens", 2,
                 "attr_add", "p2t", "weight", 1,
                 "attr_add", "p2t", "weight", 1,
                 "attr_add", "p2t2", "weight", 2,
                 "attr_add", "p2t2", "weight", 2,
-                "verify", "exit",
+                "exit",
              "ramify", "PetriNets",
              "ramify", "PetriNets",
              "new", "PetriNets_PRE", "pn_LHS",
              "new", "PetriNets_PRE", "pn_LHS",
-                "types",
                 "instantiate", "LHS", "lhs",
                 "instantiate", "LHS", "lhs",
                 "instantiate", "Pre_Place", "p",
                 "instantiate", "Pre_Place", "p",
                 "instantiate", "Pre_Natural", "tokens",
                 "instantiate", "Pre_Natural", "tokens",
@@ -568,7 +567,7 @@ Element function constraint(model : Element, name : String):
                 "attr_add", "p", "label", "2_p",
                 "attr_add", "p", "label", "2_p",
                 "attr_add", "t", "label", "3_t",
                 "attr_add", "t", "label", "3_t",
                 "attr_add", "pt", "label", "4_pt",
                 "attr_add", "pt", "label", "4_pt",
-                "verify", "exit",
+                "exit",
              "transform", "pn", "pn_LHS", "pn_LHS",
              "transform", "pn", "pn_LHS", "pn_LHS",
                 ],
                 ],
             None, "PO"))
             None, "PO"))