Procházet zdrojové kódy

Fixes to transformations and core

Yentl Van Tendeloo před 8 roky
rodič
revize
75a49fb0c1

+ 19 - 1
bootstrap/transform.alc

@@ -21,6 +21,7 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 	schedule = create_node()
 	workset = create_node()
 	all_elements = allAssociationDestinations(schedule_model, LHS, "LHS_contains")
+	log("All elements: " + set_to_string(all_elements))
 	full_all_elements = set_copy(all_elements)
 	required_size = read_nr_out(all_elements)
 
@@ -45,6 +46,7 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 				if (set_in(full_all_elements, next)):
 					if (bool_not(set_in(ignore, read_attribute(schedule_model, next, "label")))):
 						list_append(schedule, next)
+					else:
 						required_size = required_size - 1
 
 					// If it is an edge, we should also add the target and source
@@ -60,6 +62,13 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 						if (set_in_node(schedule_model["model"], read_out(schedule_model["model"][next], counter))):
 							set_add(workset, reverseKeyLookup(schedule_model["model"], read_out(schedule_model["model"][next], counter)))
 
+					// And incoming links
+					counter = read_nr_in(schedule_model["model"][next])
+					while (counter > 0):
+						counter = counter - 1
+						if (set_in_node(schedule_model["model"], read_in(schedule_model["model"][next], counter))):
+							set_add(workset, reverseKeyLookup(schedule_model["model"], read_in(schedule_model["model"][next], counter)))
+
 	return schedule!
 
 Element function get_possible_bindings(host_model : Element, schedule_model : Element, current_element : String, map : Element):
@@ -69,6 +78,7 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 	String typename
 	String original_typename
 
+
 	options = create_node()
 
 	typename = read_type(schedule_model, current_element)
@@ -250,8 +260,9 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 
 	mappings = create_node()
 	set_add(mappings, initial_mapping)
-	while (bool_and(read_nr_out(schedule) > 0, read_nr_out(mappings) > 0)):
+	while (read_nr_out(schedule) > 0):
 		current_element = list_pop(schedule, 0)
+		log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = create_node()
 
 		while (read_nr_out(mappings) > 0):
@@ -265,6 +276,11 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 				set_add(new_mappings, new_map)
 
 		mappings = new_mappings
+		log("Remaining options: " + cast_v2s(read_nr_out(mappings)))
+
+		if (read_nr_out(mappings) == 0):
+			// Stop because we have no more options remaining!
+			return create_node()!
 
 	// Finished, so try the global constraint
 	String constraint
@@ -439,6 +455,7 @@ Boolean function transform_composite(host_model : Element, schedule_model : Elem
 
 	current = set_pop(allAssociationDestinations(schedule_model, composite, "Initial"))
 	while (is_nominal_instance(schedule_model, current, "Rule")):
+		log("Executing " + current)
 		// Still a rule that we must execute
 		typename = read_type(schedule_model, current)
 		if (typename == "Atomic"):
@@ -491,6 +508,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		result = False
 
+	log("Matches in forall: " + cast_v2s(read_nr_out(mappings)))
 	while (read_nr_out(mappings) > 0):
 		mapping = set_pop(mappings)
 		// TODO check if there are actually no deletions happening in the meantime of other matched elements...

+ 7 - 0
core/core_algorithm.alc

@@ -528,6 +528,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 		schedule_model = get_full_model(transformation_id)
 
 		// 1) Create empty instance of merged metamodel
+		log("T1")
 
 		ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
 		trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
@@ -541,6 +542,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 			merged_model = instantiate_model(get_full_model(merged_metamodel_id))
 
 			// 2) Merge source models
+			log("T2")
 
 			String key
 			Element keys
@@ -553,10 +555,13 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 				model_join(merged_model, get_full_model(get_model_id(inputs[key])), string_join(types[key], "/"))
 
 			// 3) Transform
+			log("T3")
 
 			result = transform(merged_model, schedule_model)
+			log("Transformation result: " + cast_e2s(result))
 
 			// 4) Split in different files depending on type
+			log("T4")
 
 			String desired_metamodel_id
 			Element split_off_model
@@ -568,6 +573,8 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 				split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
 
 				// Check if the destination model already exists
+				log("Write result to " + cast_v2s(outputs[key]))
+				log("Model size: " + cast_v2s(read_nr_out(split_off_model["model"])))
 				if (get_model_id(outputs[key]) == ""):
 					// New model
 					model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")

+ 1 - 5
core/mini_modify.alc

@@ -218,6 +218,7 @@ Element function modify(model : Element, write : Boolean):
 			Element attr_keys
 			String attr_key
 
+			// TODO change log to output
 			keys_m = dict_keys(model["model"])
 
 			while (read_nr_out(keys_m) > 0):
@@ -225,10 +226,8 @@ Element function modify(model : Element, write : Boolean):
 				type = read_type(model["metamodel"], read_type(model, v_m))
 
 				if (bool_or(type == "Class", type == "Association")):
-					output((("  " + v_m) + " : ") + read_type(model, v_m))
 					log((("  " + v_m) + " : ") + read_type(model, v_m))
 					if (type == "Association"):
-						output((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
 						log((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
 
 					// Defines attributes
@@ -236,7 +235,6 @@ Element function modify(model : Element, write : Boolean):
 					attr_keys = dict_keys(attr_list)
 					while (0 < read_nr_out(attr_keys)):
 						attr_key = set_pop(attr_keys)
-						output(((("      " + attr_key) + " : ") + cast_v2s(attr_list[attr_key])))
 						log(((("      " + attr_key) + " : ") + cast_v2s(attr_list[attr_key])))
 
 					// Has attributes
@@ -245,10 +243,8 @@ Element function modify(model : Element, write : Boolean):
 					while (0 < read_nr_out(attr_keys)):
 						attr_key = set_pop(attr_keys)
 						if (element_eq(read_attribute(model, v_m, attr_key), read_root())):
-							output(((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = (undefined)")
 							log(((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = (undefined)")
 						else:
-							output((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
 							log((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
 
 		elif (cmd == "list"):

+ 2 - 3
integration/utils.py

@@ -167,7 +167,7 @@ def run_file(files, parameters, expected, wait=False):
                     # Modelverse has already terminated, which isn't a good sign!
                     raise Exception("Modelverse died!")
 
-                print("Got %s, expect %s" % (val, e))
+                #print("Got %s, expect %s" % (val, e))
                 if isinstance(e, set):
                     assert val in e
                     if val not in e:
@@ -248,7 +248,6 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
 
         counter = 0
         for e in expected:
-            print("Expect " + str(e))
             c = len(e) if isinstance(e, set) else 1
             for _ in range(c):
                 try:
@@ -265,7 +264,7 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
                     else:
                         raise
 
-                print("Got %s, expect %s" % (val, e))
+                #print("Got %s, expect %s" % (val, e))
                 if isinstance(e, set):
                     assert val in e
                     if val not in e:

+ 0 - 1
kernel/modelverse_kernel/primitives.py

@@ -1,4 +1,3 @@
-
 class PrimitiveFinished(Exception):
     """Exception to indicate the result value of a primitive, as a return cannot be used."""
     def __init__(self, value):

+ 1 - 79
models/plant_model.mvc

@@ -1,19 +1,7 @@
 B C{
-    PW_Plant/NormalState lt {
-        name = "low_top"
-        isInitial = False
-    }
-    PW_Plant/NormalState mt {
-        name = "medium_top"
-        isInitial = False
-    }
-    PW_Plant/NormalState ht {
-        name = "high_top"
-        isInitial = False
-    }
     PW_Plant/NormalState lm {
         name = "low_medium"
-        isInitial = False
+        isInitial = True
     }
     PW_Plant/ErrorState mm {
         name = "medium_medium"
@@ -23,91 +11,25 @@ B C{
         name = "high_medium"
         isInitial = False
     }
-    PW_Plant/NormalState lb {
-        name = "low_bottom"
-        isInitial = False
-    }
-    PW_Plant/NormalState mb {
-        name = "medium_bottom"
-        isInitial = False
-    }
-    PW_Plant/NormalState hb {
-        name = "high_bottom"
-        isInitial = True
-    }
 
-    PW_Plant/OnUp (hb, mb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnUp (mb, lb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnUp (lb, lm) {
-        objPresent = "*"
-    }
-    PW_Plant/OnUp (lm, lt) {
-        objPresent = "N"
-    }
     PW_Plant/OnUp (lm, mm) {
         objPresent = "Y"
     }
     PW_Plant/OnUp (mm, hm) {
         objPresent = "Y"
     }
-    PW_Plant/OnUp (lt, mt) {
-        objPresent = "*"
-    }
-    PW_Plant/OnUp (mt, ht) {
-        objPresent = "*"
-    }
 
-    PW_Plant/OnDown (ht, mt) {
-        objPresent = "*"
-    }
-    PW_Plant/OnDown (mt, lt) {
-        objPresent = "*"
-    }
-    PW_Plant/OnDown (lt, lm) {
-        objPresent = "*"
-    }
     PW_Plant/OnDown (hm, mm) {
         objPresent = "*"
     }
     PW_Plant/OnDown (mm, lm) {
         objPresent = "*"
     }
-    PW_Plant/OnDown (lm, lb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnDown (lb, mb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnDown (mb, hb) {
-        objPresent = "*"
-    }
 
-    PW_Plant/OnNeutral (hb, mb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnNeutral (mb, lb) {
-        objPresent = "*"
-    }
-    PW_Plant/OnNeutral (hm, mm) {
-        objPresent = "*"
-    }
     PW_Plant/OnNeutral (mm, lm) {
         objPresent = "*"
     }
     PW_Plant/OnNeutral (hm, mm) {
         objPresent = "*"
     }
-    PW_Plant/OnNeutral (mm, lm) {
-        objPresent = "*"
-    }
-    PW_Plant/OnNeutral (ht, mt) {
-        objPresent = "*"
-    }
-    PW_Plant/OnNeutral (mt, lt) {
-        objPresent = "*"
-    }
 }

+ 17 - 2
models/plant_to_EPN.mvc

@@ -13,7 +13,7 @@ A B {
                     label = "00"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "down"!
+                            return "up"!
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
@@ -24,7 +24,7 @@ A B {
                     label = "10"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "down"!
+                            return "up"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_10, post_ports_00) {
@@ -240,6 +240,10 @@ A B {
                 }
                 Pre_Encapsulated_PetriNet/Place pre_ct_7 {
                     label = "7"
+                    constraint_name = $
+                        Boolean function constraint(value : String):
+                            return (bool_or(bool_or(value == "up", value == "neutral"), value == "down"))!
+                        $
                 }
                 Pre_Encapsulated_PetriNet/Port pre_ct_8 {
                     label = "8"
@@ -258,14 +262,21 @@ A B {
                         String port_name
                         transition_type = read_type(model, mapping["2"])
                         port_name = read_attribute(model, mapping["8"], "name")
+
+                        log("TT     " + transition_type)
+                        log("PN     " + port_name)
                         
                         if (transition_type == "PW_Plant/OnUp"):
+                            log(cast_v2s(port_name == "up"))
                             return (port_name == "up")!
                         elif (transition_type == "PW_Plant/OnNeutral"):
+                            log(cast_v2s(port_name == "neutral"))
                             return (port_name == "neutral")!
                         elif (transition_type == "PW_Plant/OnDown"):
+                            log(cast_v2s(port_name == "down"))
                             return (port_name == "down")!
                         else:
+                            log("FALSE")
                             return False!
                         $
             }
@@ -355,6 +366,10 @@ A B {
                 }
                 Pre_Encapsulated_PetriNet/Port pre_co_11 {
                     label = "11"
+                    constraint_name = $
+                        Boolean function constraint(value : String):
+                            return (bool_or(value == "objPresent", value == "no_objPresent"))!
+                        $
                 }
                 Pre_Encapsulated_PetriNet/PortPlace (pre_co_11, pre_co_8) {
                     label = "12"