Просмотр исходного кода

Merge branch 'master' into testing

Yentl Van Tendeloo 8 лет назад
Родитель
Сommit
bd1b143d9e

+ 45 - 48
addis/PM_MetaModel.mvc

@@ -2,7 +2,6 @@ include "primitives.alh"
 include "object_operations.alh"
 include "modelling.alh"
 
-
 SimpleAttribute String {}
 SimpleAttribute MvCName {
     constraint = $
@@ -37,15 +36,6 @@ Class Edge {
 Class Start : Activity {
     lower_cardinality = 1
     upper_cardinality = 1
-    constraint = $
-        String function constraint(model : Element, name : String):
-            Element outgoing_edges
-            outgoing_edges = allOutgoingAssociationInstances(model, name, "Next")
-            if list_len(outgoing_edges) !=1:
-                return "A start node should have one outgoing control flow"!
-            else:
-                return "OK"!
-        $
 }
 Class Finish : Activity {
     lower_cardinality = 1
@@ -53,8 +43,8 @@ Class Finish : Activity {
         String function constraint(model : Element, name : String):
             Element incoming_edges
             incoming_edges = allIncomingAssociationInstances(model, name, "Next")
-            if (list_len(incoming_edges) !=1):
-                return "A finish node should have either one incoming control flow or decision flow"!
+            if list_len(incoming_edges) !=1:
+                return "A finish node should have exactly one incoming control-flow at " + name!
             else:
                 return "OK"!
         $
@@ -62,26 +52,31 @@ Class Finish : Activity {
 Class Fork : Activity {
     constraint = $
         String function constraint(model : Element, name : String):
-            Element outgoing_edges
             Element incoming_edges
-            outgoing_edges = allOutgoingAssociationInstances(model, name, "Next")
             incoming_edges = allIncomingAssociationInstances(model, name, "Next")
-            if bool_or(list_len(outgoing_edges) <2, list_len(incoming_edges) !=1):
-                return "All Fork nodes should have one incoming control flow and at least two outgoing control flows"!
+            if list_len(incoming_edges) <1:
+                return "A Fork node should have at-least one incoming control-flow at " + name!
             else:
                 return "OK"!
         $
 }
-
 Class Join : Activity {
     constraint = $
         String function constraint(model : Element, name : String):
-            Element outgoing_edges
             Element incoming_edges
-            outgoing_edges = allOutgoingAssociationInstances(model, name, "Next")
+            Element source
+            String type
             incoming_edges = allIncomingAssociationInstances(model, name, "Next")
-            if bool_or(list_len(outgoing_edges) !=1, list_len(incoming_edges) <2):
-                return "All Join nodes should have at least two incoming and one outgoing control flow"!
+            if list_len(incoming_edges) >0:
+                Integer i
+                i = 0
+                while i < list_len (incoming_edges):
+                    source = readAssociationSource(model, list_read(incoming_edges, i))
+                    type = read_type(model, source)
+                    if type == "Start":
+                        return "A join node can not have a Start node as an incoming flow at "+name!
+            if list_len(incoming_edges) <2:
+                return "A Join node should have at least two incoming control flows at " + name!
             else:
                 return "OK"!
         $
@@ -89,61 +84,63 @@ Class Join : Activity {
 Class Decision : Activity {
     constraint = $
         String function constraint(model : Element, name : String):
-            Element outgoing_edges
             Element incoming_edges
-            Element consumes
-            consumes = allOutgoingAssociationInstances(model, name, "DecisionConsumes")
-            outgoing_edges = allOutgoingAssociationInstances(model, name, "Next")
             incoming_edges = allIncomingAssociationInstances(model, name, "Next")
-            if bool_or(list_len(outgoing_edges) <2, list_len(incoming_edges) !=1):
-                return "All Decision nodes should have at least one incoming flow and two outgoing flows"!
-            elif list_len(consumes) != 1:
-                return "All Decision nodes should have exactly one incoming data flow"!
+            if list_len(incoming_edges) <1:
+                return "A Decision node should have at least one incoming control-flows at " + name!
             else:
                 return "OK"!
         $
 }
-
 Class Exec : Activity {
     name : MvCName
     sccd_class_id ?: String
     lower_cardinality = 1
     constraint = $
         String function constraint(model : Element, name : String):
-            Element outgoing_edges
             Element incoming_edges
-            outgoing_edges = allOutgoingAssociationInstances(model, name, "Next")
             incoming_edges = allIncomingAssociationInstances(model, name, "Next")
-            if bool_or(list_len(outgoing_edges) !=1, list_len(incoming_edges) !=1):
-                return "All Executable nodes should have exactly one incoming and one outgoing control flow"!
+            if list_len(incoming_edges) <1:
+                return "An Executable node should have at-least one incoming control-flow at " + name!
             else:
                 return "OK"!
         $
 }
-
 Class Data {
     id : String
     name : MvCName
     type : MvCName
-    constraint = $
-        String function constraint(model : Element, name : String):
-            Element outgoing_edges
-            Element incoming_edges
-            outgoing_edges = allIncomingAssociationInstances(model, name, "Consumes")
-            incoming_edges = allIncomingAssociationInstances(model, name, "Produces")
-            if bool_or(list_len(outgoing_edges) <1, list_len(incoming_edges) <1):
-                return "All Data nodes should have al-least one incoming Produces and one outgoing Consumes flow"!
-            else:
-                return "OK"!
-        $
 }
 
-Association Produces : Edge (Exec, Data) {}
+Association Produces : Edge (Exec, Data) {
+    source_lower_cardinality = 1
+}
 Association Consumes : Edge (Exec, Data) {}
-Association DecisionConsumes : Edge (Decision, Data) {}
+Association DecisionConsumes : Edge (Decision, Data) {
+    target_lower_cardinality = 1
+    target_upper_cardinality = 1
+}
 Association Next : Edge (Activity, Activity) {
     value ?: MvCName
 }
+Association S2A : Next(Start, Activity){
+    target_lower_cardinality = 1
+    target_upper_cardinality = 1
+}
+Association E2A : Next(Exec, Activity){
+    target_lower_cardinality = 1
+    target_upper_cardinality = 1
+}
+Association F2A : Next(Fork, Activity){
+    target_lower_cardinality = 2
+}
+Association J2A : Next(Join, Activity){
+    target_lower_cardinality = 1
+    target_upper_cardinality = 1
+}
+Association D2A : Next(Decision, Activity){
+    target_lower_cardinality = 2
+}
 
 Class CanvasPosition{
     x1: Natural

+ 97 - 0
addis/PM_example2.mvc

@@ -0,0 +1,97 @@
+Start start {
+    id = "start"
+}
+Exec A {
+    name = "A"
+    id = "A"
+}
+S2A (start, A){
+    id ="start_A"
+}
+Fork fork_1 {
+    id = "fork_1"
+}
+E2A (A, fork_1){
+    id = "A_fork_1"
+}
+Exec B {
+    name = "B"
+    id = "B"
+}
+Exec C {
+    name = "C"
+    id = "C"
+}
+Exec E {
+    name = "E"
+    id = "E"
+}
+F2A (fork_1, B){
+    id = "fork_1_B"
+}
+F2A (fork_1, C){
+    id = "fork_1_C"
+}
+F2A (fork_1, E){
+    id = "fork_1_E"
+}
+Data data {
+    id = "data"
+    name = "bool"
+    type = "Boolean"
+}
+Produces (E, data){
+    id = "E_data"
+}
+Join join_1 {
+    id = "join_1"
+}
+Join join_2 {
+    id = "join_2"
+}
+E2A (B,join_1){
+    id = "B_join_1"
+}
+E2A (C,join_1){
+    id = "C_join_1"
+}
+Exec D {
+    name = "D"
+    id = "D"
+}
+J2A (join_1, D){
+    id = "join_1_D"
+}
+E2A (D, join_2){
+    id = "D_join_2"
+}
+E2A (E, join_2){
+    id = "E_join_2"
+}
+Exec F {
+    name = "F"
+    id = "F"
+}
+J2A (join_2, F){
+    id = "join_2_f"
+}
+Decision decision_1 {
+    id = "decision_1"
+}
+DecisionConsumes (decision_1, data) {
+    id = "decision_1_data"
+}
+E2A (F, decision_1){
+    id = "F_decision_1"
+}
+D2A (decision_1, A){
+    id = "decision_1_A"
+    value = "True"
+}
+Finish end {
+    id = "finish"
+}
+D2A (decision_1, end){
+    id = "decision_1_end"
+    value = "False"
+}

Разница между файлами не показана из-за своего большого размера
+ 884 - 302
addis/PM_to_SCCD.mvc


+ 396 - 6
addis/SCCD_Example.mvc

@@ -1,16 +1,406 @@
-
-Diagram SCCD_Example {
+include "primitives.alh"
+Diagram SCCD_my_PM {
     name = "SCCD example "
     {diagram_classes} Class A {
         name = "A"
-
-        {behaviour} CompositeState manager_main {
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_a {
+            name = "main"
+            isInitial = True
+            {composite_children} BasicState initial_a {
+                name = "Init"
+                isInitial = True
+            }
+            {composite_children} BasicState running_a {
+                name = "Running"
+                isInitial = False
+            }
+            {composite_children} BasicState done_a {
+                name = "Done"
+                isInitial = False
+            }
+        }
+    }
+    {diagram_classes} Class B {
+        name = "B"
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_b {
+            name = "main"
+            isInitial = True
+            {composite_children} BasicState initial_b {
+                name = "Init"
+                isInitial = True
+            }
+            {composite_children} BasicState running_b {
+                name = "Running"
+                isInitial = False
+            }
+            {composite_children} BasicState done_b {
+                name = "Done"
+                isInitial = False
+            }
+        }
+    }
+    {diagram_classes} Class C {
+        name = "C"
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_c {
+            name = "main"
+            isInitial = True
+            {composite_children} BasicState initial_c {
+                name = "Init"
+                isInitial = True
+            }
+            {composite_children} BasicState running_c {
+                name = "Running"
+                isInitial = False
+            }
+            {composite_children} BasicState done_c {
+                name = "Done"
+                isInitial = False
+            }
+        }
+    }
+    {diagram_classes} Class E {
+        name = "E"
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_e {
             name = "main"
             isInitial = True
-            {composite_children} BasicState manager_main_start {
-                name = "start"
+            {composite_children} BasicState initial_e {
+                name = "Init"
                 isInitial = True
             }
+            {composite_children} BasicState running_e {
+                name = "Running"
+                isInitial = False
+                {state_onentry_raises} Raise {
+                    event = "save"
+                    scope = "narrow"
+                    target = $
+                        Element function raise(attributes : Element):
+                            return attributes["parent_id"]!
+                        $
+                    parameters = $
+                        Element function raise(attributes : Element):
+                            Element result
+                            result = list_create()
+                            list_append(result, "bool")
+                            list_append(result, "E")
+                            return result!
+                    $
+                }
+            }
+            {composite_children} BasicState done_e {
+                name = "Done"
+                isInitial = False
+            }
         }
     }
+    {diagram_classes} Class D {
+        name = "D"
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_d {
+            name = "main"
+            isInitial = True
+            {composite_children} BasicState initial_d {
+                name = "Init"
+                isInitial = True
+            }
+            {composite_children} BasicState running_d {
+                name = "Running"
+                isInitial = False
+            }
+            {composite_children} BasicState done_d {
+                name = "Done"
+                isInitial = False
+            }
+        }
+    }
+    {diagram_classes} Class F {
+        name = "F"
+        constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                dict_add(attributes, "id", '')
+                dict_add(attributes, "parent_id", '')
+                return !
+        $
+        {behaviour} CompositeState root_f {
+            name = "main"
+            isInitial = True
+            {composite_children} BasicState initial_f {
+                name = "Init"
+                isInitial = True
+            }
+            {composite_children} BasicState running_f {
+                name = "Running"
+                isInitial = False
+            }
+            {composite_children} BasicState done_f {
+                name = "Done"
+                isInitial = False
+            }
+        }
+    }
+
+}
+transition (initial_a, running_a){
+    event = "set_id"
+    script = $
+            Void function script(attributes : Element, parameters : Element):
+                dict_overwrite(attributes, "id", parameters[0])
+                dict_overwrite(attributes, "parent_id", parameters[1])
+                log("CREATED ---- A")
+                return!
+        $
+}
+transition (running_a, done_a){
+    after = $
+            Float function after(attributes : Element):
+                return 0.5!
+        $
+    script = $
+            Void function script(attributes : Element, parameters : Element):
+                log("FINISHED ---- A")
+                return!
+        $
+    {transition_raises} Raise {
+        scope = "narrow"
+        event = "terminated"
+        target = $
+            String function raise(attributes : Element):
+                return attributes["parent_id"]!
+            $
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, 'A')
+                return result!
+        $
+    }
+    {transition_raises} Raise {
+        scope = "cd"
+        event = "delete_instance"
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes["id"])
+                return result!
+        $
+    }
+}
+transition (initial_b, running_b){
+    event = "set_id"
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            dict_overwrite(attributes, "id", parameters[0])
+            dict_overwrite(attributes, "parent_id", parameters[1])
+            log("CREATED ---- B")
+            return!
+    $
+}
+transition (running_b, done_b){
+    after = $
+        Float function after(attributes : Element):
+            return 0.9!
+    $
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            log("FINISHED ---- B")
+            return!
+    $
+    {transition_raises} Raise {
+        scope = "narrow"
+        event = "terminated"
+        target = $
+            Element function raise(attributes : Element):
+                return attributes["parent_id"]!
+            $
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, 'B')
+                return result!
+        $
+    }
+    {transition_raises} Raise {
+        scope = "cd"
+        event = "delete_instance"
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes["id"])
+                return result!
+        $
+    }
+}
+transition (initial_c, running_c){
+    event = "set_id"
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            dict_overwrite(attributes, "id", parameters[0])
+            dict_overwrite(attributes, "parent_id", parameters[1])
+            log("CREATED ---- C")
+            return!
+    $
+}
+transition (running_c, done_c){
+    after = $
+        Float function after(attributes : Element):
+            return 0.5!
+    $
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            log("FINISHED ---- C")
+            return!
+    $
+    {transition_raises} Raise {
+        scope = "narrow"
+        event = "terminated"
+        target = $
+            Element function raise(attributes : Element):
+                return attributes["parent_id"]!
+            $
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, "C")
+                return result!
+        $
+    }
+    {transition_raises} Raise {
+        scope = "cd"
+        event = "delete_instance"
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes["id"])
+                return result!
+        $
+    }
+}
+transition (initial_e, running_e){
+    event = "set_id"
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            dict_overwrite(attributes, "id", parameters[0])
+            dict_overwrite(attributes, "parent_id", parameters[1])
+            log("CREATED ---- E")
+            return!
+    $
+}
+transition (running_e, done_e){
+    after = $
+        Float function after(attributes : Element):
+            return 0.5!
+    $
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            log("FINISHED ---- E")
+            return!
+    $
+    {transition_raises} Raise {
+        scope = "narrow"
+        event = "terminated"
+        target = $
+            Element function raise(attributes : Element):
+                return attributes["parent_id"]!
+            $
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, "E")
+                return result!
+        $
+    }
+    {transition_raises} Raise {
+        scope = "cd"
+        event = "delete_instance"
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes["id"])
+                return result!
+        $
+    }
+}
+transition (initial_f, running_f){
+    event = "set_id"
+    script = $
+        Void function script(attributes : Element, parameters : Element):
+            dict_overwrite(attributes, "id", parameters[0])
+            dict_overwrite(attributes, "parent_id", parameters[1])
+            log("CREATED ---- F")
+            return!
+    $
+}
+transition (running_f, done_f){
+    after = $
+            Float function after(attributes : Element):
+                return 0.5!
+        $
+    script = $
+            Void function script(attributes : Element, parameters : Element):
+                log("FINISHED ---- F")
+                return!
+        $
+    {transition_raises} Raise {
+        scope = "narrow"
+        event = "terminated"
+        target = $
+            Element function raise(attributes : Element):
+                return attributes["parent_id"]!
+            $
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes['id'])
+                return result!
+        $
+    }
+    {transition_raises} Raise {
+        scope = "cd"
+        event = "delete_instance"
+        parameters = $
+            Element function raise(attributes : Element, parameters : Element):
+                Element result
+                result = list_create()
+                list_append(result, attributes["id"])
+                return result!
+        $
+    }
 }

+ 13 - 12
addis/SCCD_MetaModel.mvc

@@ -2,7 +2,7 @@ include "primitives.alh"
 include "object_operations.alh"
 include "modelling.alh"
 
-
+SimpleAttribute Action {}
 SimpleAttribute Neutral {}
 SimpleAttribute Boolean {
     constraint = $
@@ -78,8 +78,8 @@ Association diagram_outports(Diagram, Outport){}
 
 Class Class{
     name : String
-    constructor_body ?: String
-    destructor ?: String
+    constructor_body ?: Action
+    destructor ?: Action
     default ?: Boolean
     external ?: Boolean
     class_behaviour_items ?: String
@@ -96,7 +96,7 @@ Association class_attributes(Class, Attribute){}
 
 Class Method{
     name : String
-    body : String
+    body : Action
     return_type ?: String
 }
 
@@ -156,9 +156,9 @@ Association state_position(State, CanvasPosition){
 }
 
 Class BasicState : State{
-    isInitial : Boolean
-    onEntryScript ?: String
-    onExitScript ?: String
+    isInitial ?: Boolean
+    onEntryScript ?: Action
+    onExitScript ?: Action
 }
 
 Class ActualParameter{
@@ -170,6 +170,7 @@ Class Raise{
     scope ?: EventScope
     port ?: String
     target ?: String
+    parameter ?: Action
 }
 Association raise_parameters(Raise, ActualParameter){
     order : Natural
@@ -178,7 +179,7 @@ Association state_onentry_raises(BasicState, Raise){
     order : Natural
 }
 Association state_onexit_raises(BasicState, Raise){
-    order : Natural
+    order ?: Natural
 }
 
 Class CompositeState : BasicState{}
@@ -203,9 +204,9 @@ Class HistoryState : State{
 }
 
 Association transition(State, State){
-    name: String
-    cond ?: String
-    script ?: String
+    name ?: String
+    cond ?: Action
+    script ?: Action
     after ?: PositiveFloat
     event ?: String
     port ?: String
@@ -267,4 +268,4 @@ GlobalConstraint {
 
                 return "OK"!
         $
-    }
+    }

+ 22 - 13
addis/Test_PM2SCCD.py

@@ -15,22 +15,31 @@ except Exception as e:
 
 if "my_PM" in [i[0] for i in model_list()]:
     model_delete("my_PM")
-model_add("my_PM", "PM", open("addis/PM_Example.mvc", 'r').read())
+model_add("my_PM", "PM", open("addis/PM_example2.mvc", 'r').read())
+print "PM instance model added"
+#print verify('my_PM')
 if "SCCD_my_PM" in [i[0] for i in model_list()]:
     model_delete("SCCD_my_PM")
 model_add("SCCD_my_PM", "SCCD", open("addis/SCCD_Example.mvc", 'r').read())
-
+print "SCCD instance model added"
+print verify('SCCD_my_PM')
 
 def Activity2State():
     instantiate(None, "Association", ("PM/Activity", "SCCD/CompositeState"), ID="Activity2State_link")
-print "before mt"
-transformation_add_MT({"PM":"PM","SCCD":"SCCD"}, {"SCCD":"SCCD"}, "PM2SCCD", open("addis/PM_to_SCCD.mvc", "r").read(), Activity2State)
-print model_list()
-transformation_execute_MT("PM2SCCD", {"PM":"my_PM", "SCCD":"SCCD_my_PM"}, {"SCCD":"PM_2_SCCD_output"})
-
-
-
-
-
-
-
+print "before mt_add"
+print transformation_add_MT({"PM":"PM","SCCD":"SCCD"}, {"SCCD":"SCCD"}, "PM2SCCD", open("addis/PM_to_SCCD.mvc", "r").read(), Activity2State)
+print "mt_add_finished"
+print transformation_execute_MT("PM2SCCD", {"PM":"my_PM", "SCCD":"SCCD_my_PM"}, {"SCCD":"PM_2_SCCD_output"})
+
+alter_context("PM_2_SCCD_output", "SCCD")
+model =  element_list_nice("PM_2_SCCD_output")
+for m in model:
+    print m
+
+
+print("Upload SCCD execution semantics")
+# Add SCCD execution semantics
+transformation_add_AL({"SCCD": "SCCD"}, {}, "SCCD_execute", open("models/SCCD_execute.alc", 'r').read())
+print("DONE")
+#transformation_execute_AL("SCCD_execute", {"SCCD": "PM_2_SCCD_output"}, {})
+print("Executed")

+ 3 - 0
bootstrap/compiler.alc

@@ -26,6 +26,9 @@ Element function generic_compile(code : String, port : String):
 		return read_root()!
 
 Element function compile_code(code : String):
+	// TODO to test performance impact
+	return code!
+
 	String port
 	port = comm_connect("compiler")
 	comm_set(port, "code")

Разница между файлами не показана из-за своего большого размера
+ 259 - 135
bootstrap/core_algorithm.alc


+ 5 - 3
bootstrap/transform.alc

@@ -432,12 +432,14 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 				func = get_func_AL_model(import_node(value))
 				result = func(host_model, new_mapping[label], mapping)
 
-				if (has_value(result)):
+				if (element_eq(result, read_root())):
+					unset_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1))
+				elif (has_value(result)):
 					// New value defined, so assign!
 					instantiate_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1), result)
 				else:
-					// Non-value return means to destroy the attribute!
-					unset_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1))
+					// Try to interpret as code
+					instantiate_attribute_code(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1), result)
 
 		// Do the global action of each element
 		action = read_attribute(schedule_model, RHS_map[label], "action")

+ 1 - 2
hybrid_server/classes/mvkcontroller.xml

@@ -290,7 +290,7 @@
 
                         <transition cond="self.new_tasks" target="../create_SC"/>
                         <transition cond="not self.new_tasks and self.old_tasks" target="../remove_SC"/>
-                        <transition after="0.01" target="."/>
+                        <transition after="1.0" target="."/>
                     </state>
 
                     <state id="create_SC" initial="creating">
@@ -334,7 +334,6 @@
                                 <parameter expr="self.sc_map[task]"/>
                             </raise>
                             <script>
-                                print("Delete task")
                                 del self.sc_map[task]
                             </script>
                         </transition>

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

@@ -1,4 +1,12 @@
 Void function initialize_core()
 Void function new_task()
 String function get_service_id(name : String)
+
+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

+ 48 - 16
kernel/modelverse_kernel/compiled.py

@@ -3,7 +3,6 @@ import modelverse_jit.runtime as jit_runtime
 import time
 
 def reverseKeyLookupMulti(a, b, **remainder):
-    #PROFILE start = time.time()
     edges, b_val, result = yield [("RO", [a]), ("RV", [b]), ("CN", [])]
     expanded_edges = yield [("RE", [i]) for i in edges]
     values = yield [("RV", [i[1]]) for i in expanded_edges]
@@ -19,11 +18,9 @@ def reverseKeyLookupMulti(a, b, **remainder):
     edges = yield [("CE", [result, result]) for value in values]
     yield [("CE", [edge, value[1]]) for edge, value in zip(edges, values)]
 
-    #PROFILE print("[COMPILED]reverseKeyLookupMulti : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(result)
 
 def reverseKeyLookup(a, b, **remainder):
-    #PROFILE start = time.time()
     edges_out, edges_in = yield [("RO", [a]), ("RI", [b])]
     options = set(edges_out) & set(edges_in)
     if options:
@@ -36,46 +33,36 @@ def reverseKeyLookup(a, b, **remainder):
         result = e[1]
     else:
         result, = yield [("CNV", [""])]
-    #PROFILE print("[COMPILED]reverseKeyLookup : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(result)
 
 def instantiated_name(a, b, **remainder):
-    #PROFILE start = time.time()
     name_value, = yield [("RV", [b])]
     if name_value == "":
         b, = yield [("CNV", ["__" + str(a)])]
-    #PROFILE print("[COMPILED]instantiated_name : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(b)
 
 def set_merge(a, b, **remainder):
-    #PROFILE start = time.time()
     keys, =         yield [("RDK", [b])]
     edges =         yield [("CE", [a, a]) for key in keys]
     _ =             yield [("CE", [edge, key]) for edge, key in zip(edges, keys)]
-    #PROFILE print("[COMPILED]set_merge : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(a)
 
 def has_value(a, **remainder):
-    #PROFILE start = time.time()
     v, = yield [("RV", [a])]
     if v is None:
         result, = yield [("CNV", [False])]
     else:
         result, = yield [("CNV", [True])]
-    #PROFILE print("[COMPILED]has_value : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(result)
 
 def make_reverse_dictionary(a, **remainder):
-    #PROFILE start = time.time()
     reverse, = yield [("CN", [])]
     key_nodes, = yield [("RDK", [a])]
     values = yield [("RDN", [a, i]) for i in key_nodes]
     yield [("CD", [reverse, str(v), k]) for k, v in zip(key_nodes, values)]
-    #PROFILE print("[COMPILED]make_reverse_dictionary : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(reverse)
 
 def dict_eq(a, b, **remainder):
-    #PROFILE start = time.time()
     key_nodes, = yield [("RDK", [a])]
     key_values = yield [("RV", [i]) for i in key_nodes]
     values = yield [("RD", [a, i]) for i in key_values]
@@ -89,11 +76,9 @@ def dict_eq(a, b, **remainder):
     b_dict = dict(zip(key_values, values))
 
     result, = yield [("CNV", [a_dict == b_dict])]
-    #PROFILE print("[COMPILED]dict_eq : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(result)
 
 def string_substr(a, b, c, **remainder):
-    #PROFILE start = time.time()
     a_val, b_val, c_val = yield [("RV", [a]),
                                  ("RV", [b]),
                                  ("RV", [c])]
@@ -103,7 +88,6 @@ def string_substr(a, b, c, **remainder):
         new_value = ""
     
     result, = yield [("CNV", [new_value])]
-    #PROFILE print("[COMPILED]string_substr : %s : %s" % (time.time() - start, time.time() - start))
     raise PrimitiveFinished(result)
 
 def integer_gt(a, b, **remainder):
@@ -217,3 +201,51 @@ def set_overlap(a, b, **remainder):
     yield [("CD", [res, value, res]) for value in result]
 
     raise PrimitiveFinished(res)
+
+def get_superclasses(a, b, **remainder):
+    model, name = a, b
+    model_dict, tm_dict, name_value = yield [("RD", [a, "model"]), 
+                                             ("RD", [a, "type_mapping"]),
+                                             ("RV", [b])]
+
+    worklist = set([name_value])
+    found = set([])
+
+    while worklist:
+        name = worklist.pop()
+        if name in found:
+            continue
+        elem, = yield [("RD", [model_dict, name])]
+        found.add(name)
+
+        # Iterate over all outgoing links
+        outgoing, = yield [("RO", [elem])]
+        outgoing = set(outgoing)
+        while (outgoing):
+            link = outgoing.pop()
+
+            # If the link is typed by "Inheritance", we add its destination
+            link_name_node, = yield [("CALL_ARGS", [reverseKeyLookup, [model_dict, link]])]
+            link_name, = yield [("RV", [link_name_node])]
+            t_edge, = yield [("RD", [tm_dict, link_name])]
+            t_edge, = yield [("RV", [t_edge])]
+            if t_edge == "Inheritance":
+                edge, = yield [("RE", [link])]
+                src, dst = edge
+                # Look up dst's name and add it
+                dst_name, = yield [("CALL_ARGS", [reverseKeyLookup, [model_dict, dst]])]
+                dst_name_value, = yield [("RV", [dst_name])]
+                worklist.add(dst_name_value)
+
+    result, = yield [("CN", [])]
+    yield [("CD", [result, i, result]) for i in found]
+
+    raise PrimitiveFinished(result)
+
+def list_pop_final(a, **remainder):
+    lst, = yield [("RO", [a])]
+    length = len(lst)
+    result, result_edge = yield [("RD", [a, length - 1]),
+                                 ("RDE", [a, length -1])]
+    _, = yield [("DE", [result_edge])]
+    raise PrimitiveFinished(result)

+ 101 - 0
models/test_operations_in_SCCD.mvc

@@ -0,0 +1,101 @@
+include "primitives.alh"
+include "core_algorithm.alh"
+include "transform.alh"
+include "modelling.alh"
+
+Diagram dynamic_trafficlight {
+    name = "Dynamic Traffic Light"
+    author = "Yentl Van Tendeloo"
+}
+
+Class manager {
+    name = "Manager"
+    default = True
+    constructor_body = $
+            Void function constructor(attributes : Element, parameters : Element):
+                return !
+        $
+
+    {behaviour} CompositeState manager_main {
+        name = "main"
+        isInitial = True
+        {composite_children} BasicState manager_main_init {
+            name = "init"
+            isInitial = True
+        }
+        {composite_children} BasicState manager_main_did_transform {
+            name = "MT OK"
+            isInitial = False
+        }
+        {composite_children} BasicState manager_main_did_actionlanguage {
+            name = "AL OK"
+            isInitial = False
+        }
+    }
+}
+
+transition (manager_main_init, manager_main_did_transform) {
+    name = "model transformation"
+
+    script = $
+            Void function script(attributes : Element, parameters : Element):
+                Element m
+                Element models
+
+                // Merge models
+                models = dict_create()
+                dict_add(models, "A", "ModelA")
+                dict_add(models, "B", "ModelB")
+                m = merge_models(models, "TransformY")
+
+                // Do transformation
+                transform(m, get_model("TransformY", get_ramified_metamodel("TransformY")))
+
+                // Split up the result
+                Element metamodels
+                Element split
+                metamodels = dict_create()
+                dict_add(metamodels, "C", "MetamodelC")
+                dict_add(metamodels, "B", "MetamodelB")
+                split = split_model(m, metamodels)
+
+                // Store the results
+                store_model("ModelC", "MetamodelC", split["C"])
+                store_model("ModelB", "MetamodelB", split["B"])
+                return!
+        $
+}
+
+transition (manager_main_did_transform, manager_main_did_actionlanguage) {
+    name = "action language"
+
+    script = $
+            Void function script(attributes : Element, parameters : Element):
+                Element m
+                Element models
+
+                // Merge models
+                models = dict_create()
+                dict_add(models, "C", "ModelC")
+                dict_add(models, "B", "ModelB")
+                m = merge_models(models, "OperationZ")
+
+                // Do transformation
+                Element func
+                func = get_func_AL_model(get_model("OperationZ", "ActionLanguage"))
+                func(m)
+
+                // Split up the result
+                Element metamodels
+                Element split
+                metamodels = dict_create()
+                dict_add(metamodels, "A", "MetamodelA")
+                dict_add(metamodels, "B", "MetamodelB")
+                split = split_model(m, metamodels)
+
+                // Store the results
+                store_model("ModelA", "MetamodelA", split["A"])
+                store_model("ModelB", "MetamodelB", split["B"])
+                return!
+        $
+}

+ 1 - 1
wrappers/modelverse.py

@@ -72,7 +72,7 @@ def _get_metamodel(model):
     try:
         return registered_metamodels[model]
     except KeyError:
-        raise UnkownMetamodellingHierarchy(model)
+        raise UnknownMetamodellingHierarchy(model)
 
 def _check_type(value):
     if not isinstance(value, (int, long, float, str, unicode, bool)):

+ 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"}, {})