Browse Source

Add code to fetch RAMified metamodel

Yentl Van Tendeloo 8 years ago
parent
commit
68a1308495

+ 42 - 0
bootstrap/core_algorithm.alc

@@ -371,6 +371,7 @@ Boolean function pm_finished(worklist : Element, pm : String):
 	return False!
 
 Element function merge_models(models_dict : Element, operation_id : String):
+	log("Start merge")
 	// 0) Find operation signature
 
 	Element input_metamodels
@@ -422,11 +423,13 @@ Element function merge_models(models_dict : Element, operation_id : String):
 			output("Merged metamodel in operation is not of type SimpleClassDiagrams")
 			return read_root()!
 
+		log("Join OK")
 		return model_join(model_tuples, merged_metamodel, read_root())!
 	else:
 		return read_root()!
 
 Element function split_model(model : Element, metamodels_dict : Element):
+	log("Splitting model")
 	Element model_tuples
 	Element keys
 	String key
@@ -443,19 +446,58 @@ Element function split_model(model : Element, metamodels_dict : Element):
 			return read_root()!
 		set_add_node(model_tuples, create_tuple(key, mm))
 
+	log("Split OK")
 	return model_split(model, model_tuples, read_root())!
 
 Element function get_model(model_name : String, metamodel_name : String):
+	log("Fetching full model")
 	return get_full_model(get_model_id(model_name), get_model_id(metamodel_name))!
 
 Void function store_model(model_name : String, metamodel_name : String, model : Element):
+	log("Storing model")
 	if (get_model_id(model_name) == ""):
 		// New model
+		log("Create new model")
 		model_create(model, model_name, get_model_id(metamodel_name), "Model")
+		log("Created")
 	else:
+		log("Overwriting existing model")
 		model_overwrite(model, get_model_id(model_name), get_model_id(metamodel_name))
+		log("Done")
 	return!
 
+String function get_ramified_metamodel(model_name : String):
+	log("Executed get_ramified_metamodel!")
+	String operation_id
+	Element trace_links
+	String merged_metamodel_id
+	String trace_link_id
+	String ramified_metamodel_id
+
+	operation_id = get_model_id(model_name)
+	log("Reading tracability links for " + cast_v2s(read_attribute(core, operation_id, "name")))
+	trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
+	merged_metamodel_id = ""
+
+	while (set_len(trace_links) > 0):
+		trace_link_id = set_pop(trace_links)
+
+		if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
+			merged_metamodel_id = readAssociationDestination(core, trace_link_id)
+			log("Reading extra tracability links for " + cast_v2s(read_attribute(core, merged_metamodel_id, "name")))
+			trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
+			ramified_metamodel_id = ""
+
+			while (set_len(trace_links) > 0):
+				trace_link_id = set_pop(trace_links)
+				if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
+					ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
+
+					log("Returning: " + cast_v2s(read_attribute(core, ramified_metamodel_id, "name")))
+					return read_attribute(core, ramified_metamodel_id, "name")!
+	log("None found")
+	return read_root()!
+
 Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
 	// Operations are always in-place and uses only a single metamodel
 	// Therefore, we must:

+ 0 - 1
hybrid_server/classes/mvkcontroller.xml

@@ -334,7 +334,6 @@
                                 <parameter expr="self.sc_map[task]"/>
                             </raise>
                             <script>
-                                print("Delete task")
                                 del self.sc_map[task]
                             </script>
                         </transition>

+ 1 - 0
interface/HUTN/includes/core_algorithm.alh

@@ -6,6 +6,7 @@ Element function merge_models(models_dict : Element, operation_id : String)
 Element function split_model(model : Element, metamodels_dict : Element)
 Element function get_model(model_name : String, metamodel_name : String)
 Void function store_model(model_name : String, metamodel_name : String, model : Element)
+String function get_ramified_metamodel(model_name : String)
 
 // This should be removed, as it allows everyone to alter the core...
 Element core

+ 8 - 6
models/test_operations_in_SCCD.mvc

@@ -1,5 +1,7 @@
 include "primitives.alh"
 include "core_algorithm.alh"
+include "transform.alh"
+include "modelling.alh"
 
 Diagram dynamic_trafficlight {
     name = "Dynamic Traffic Light"
@@ -44,10 +46,10 @@ transition (manager_main_init, manager_main_did_transform) {
                 models = dict_create()
                 dict_add(models, "A", "ModelA")
                 dict_add(models, "B", "ModelB")
-                m = merge_models(models)
+                m = merge_models(models, get_model("TransformY", get_ramified_metamodel("TransformY")))
 
                 // Do transformation
-                transform(m, get_model("TransformY"))
+                transform(m, get_model("TransformY", get_ramified_metamodel("TransformY")))
 
                 // Split up the result
                 Element metamodels
@@ -55,7 +57,7 @@ transition (manager_main_init, manager_main_did_transform) {
                 metamodels = dict_create()
                 dict_add(models, "C", "MetamodelC")
                 dict_add(models, "B", "MetamodelB")
-                split = split_models(m, metamodels)
+                split = split_model(m, metamodels)
 
                 // Store the results
                 store_model("ModelC", "MetamodelC", split["C"])
@@ -76,11 +78,11 @@ transition (manager_main_did_transform, manager_main_did_actionlanguage) {
                 models = dict_create()
                 dict_add(models, "C", "ModelC")
                 dict_add(models, "B", "ModelB")
-                m = merge_models(models)
+                m = merge_models(models, get_model("OperationZ", "ActionLanguage"))
 
                 // Do transformation
                 Element func
-                func = get_func_AL_model(get_model("OperationZ"))
+                func = get_func_AL_model(get_model("OperationZ", "ActionLanguage"))
                 func(m)
 
                 // Split up the result
@@ -89,7 +91,7 @@ transition (manager_main_did_transform, manager_main_did_actionlanguage) {
                 metamodels = dict_create()
                 dict_add(models, "A", "MetamodelA")
                 dict_add(models, "B", "MetamodelB")
-                split = split_models(m, metamodels)
+                split = split_model(m, metamodels)
 
                 // Store the results
                 store_model("ModelA", "MetamodelA", split["A"])

+ 50 - 54
wrappers/test_modelverse.py

@@ -1,58 +1,54 @@
 from modelverse import *
-from random import random
-
-username = str(random())
-password = str(random())
-model_name = str(random())
-model_name2 = str(random())
 
 init()
-login(username, password)
+login("admin", "admin")
+
+model_add("MetamodelA", "SimpleClassDiagrams", """Class A {}""")
+model_add("MetamodelB", "SimpleClassDiagrams", """Class B {}""")
+model_add("MetamodelC", "SimpleClassDiagrams", """Class C {}""")
+model_add("ModelA", "MetamodelA", """A a1 {}""")
+model_add("ModelB", "MetamodelB", """B b1 {}""")
+
+model_add("SCCD", "SimpleClassDiagrams", open("models/SCCD.mvc", 'r').read())
+model_add("my_SCCD", "SCCD", open("models/test_operations_in_SCCD.mvc", 'r').read())
+
+transformation_add_MT({"A": "MetamodelA", "B": "MetamodelB"}, {"B": "MetamodelB", "C": "MetamodelC"}, "TransformY", \
+    """
+    Composite schedule {
+        {Contains} Failure fail {}
+        {Contains} Success success {}
+        {Contains} ForAll f {
+            LHS {
+                Pre_A/A {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_C/C {
+                    label = "1"
+                }
+            }
+        }
+    }
+    Initial (schedule, f) {}
+    OnSuccess (f, success) {}
+    OnFailure (f, fail) {}
+    """
+    )
+
+transformation_add_AL({"B": "MetamodelB", "C": "MetamodelC"}, {"B": "MetamodelB", "A": "MetamodelA"}, "OperationZ", \
+    """
+    include "primitives.alh"
+    include "object_operations.alh"
+    include "modelling.alh"
+
+    Boolean function size_of_model(model : Element):
+        log("Number of instances of A: " + cast_v2s(set_len(allInstances(model, "A/A"))))
+        log("Number of instances of B: " + cast_v2s(set_len(allInstances(model, "B/B"))))
+        log("Number of instances of C: " + cast_v2s(set_len(allInstances(model, "C/C"))))
+        return True!
+    """
+    )
+transformation_add_AL({"SCCD": "SCCD"}, {}, "SCCD_execute", open("models/SCCD_execute.alc", 'r').read())
 
-model_add(model_name, "SimpleClassDiagrams", open("models/petrinet_ports.mvc", "r").read())
-print(verify(model_name))
-print(element_list(model_name))
-print(model_list())
-print(types(model_name))
-try:
-    print(read("SimpleClassDiagrams", "Place"))
-    raise Exception("ERROR")
-except UnknownIdentifier:
-    print(read("SimpleClassDiagrams", "Class"))
-    try:
-        print(read_attrs("SimpleClassDiagrams", "Place"))
-        raise Exception("ERROR")
-    except UnknownIdentifier:
-        print(read_attrs("SimpleClassDiagrams", "Class"))
-        try:
-            print(instantiate("SimpleClassDiagrams", "Class", None))
-            raise Exception("ERROR")
-        except PermissionDenied:
-            print(("abc", "Class") not in element_list("SimpleClassDiagrams"))
-            print(verify(model_name))
-            print(element_list(model_name))
-            print(instantiate(model_name, "Class", None))
-            print(("abc", "Class") in element_list(model_name))
-            model_add(model_name2, model_name)
-            p1 = instantiate(model_name2, "Place")
-            p2 = instantiate(model_name2, "Place")
-            t1 = instantiate(model_name2, "Transition")
-            p2t = instantiate(model_name2, "P2T", (p1, t1))
-            t2p = instantiate(model_name2, "T2P", (t1, p2))
-            print(read_outgoing(model_name2, p1, "P2T"))
-            print(read_outgoing(model_name2, p2, "P2T"))
-            print(element_list(model_name2))
-            print(read_attrs(model_name2, p1))
-            attr_assign(model_name2, p1, "name", "p1")
-            attr_assign(model_name2, p1, "tokens", 1)
-            print(read_attrs(model_name2, p1))
-            print(verify(model_name2))
-            attr_assign(model_name2, p2, "name", "p2")
-            attr_assign(model_name2, p2, "tokens", 3)
-            print(verify(model_name2))
-            attr_assign(model_name2, t1, "name", "t1")
-            try:
-                attr_assign(model_name2, t2p, "weight", 2)
-                raise Exception("ERROR")
-            except NoSuchAttribute:
-                print(verify(model_name2))
+transformation_execute_AL("SCCD_execute", {"SCCD": "my_SCCD"}, {})