Browse Source

Extended test to annotation, printing, and simulation (step)

Yentl Van Tendeloo 8 years ago
parent
commit
ad8af56fb2

BIN
bootstrap/bootstrap.m.gz


BIN
bootstrap/minimal.m.gz


+ 1 - 0
bootstrap/modelling.alc

@@ -186,6 +186,7 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 	String attr_type
 	String attr_name
 
+	log("Adding attribute " + attribute_name)
 	attr_type = find_attribute_type(model, element, attribute_name)
 
 	if (attr_type == ""):

+ 0 - 17
bootstrap/transform.alc

@@ -100,40 +100,24 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 		Element oc
 		String poll
 
-		log("Finding in/out for " + current_element)
-		log("Current mapping: " + set_to_string(map))
 		ic = allIncomingAssociationInstances(schedule_model, current_element, "Pre_Element")
 		oc = allOutgoingAssociationInstances(schedule_model, current_element, "Pre_Element")
 
-		log("Incoming: " + set_to_string(ic))
-		log("Outgoing: " + set_to_string(oc))
-
-		log("Check incoming")
 		while (bool_and(read_nr_out(ic) > 0, read_nr_out(options) == 0)):
 			poll = set_pop(ic)
-			log("Checking if already bound " + poll)
 			if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
 				// This incoming link is already defined, so we just have one option: the destination of the link we matched
-				log("Got match!")
 				set_add(options, readAssociationDestination(host_model, map[read_attribute(schedule_model, poll, "label")]))
 			
-		log("Check outgoing")
 		while (bool_and(read_nr_out(oc) > 0, read_nr_out(options) == 0)):
 			poll = set_pop(oc)
-			log("Checking if already bound " + poll)
 			if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
 				// This incoming link is already defined, so we just have one option: the destination of the link we matched
-				log("Got match!")
 				set_add(options, readAssociationSource(host_model, map[read_attribute(schedule_model, poll, "label")]))
 
 		if (read_nr_out(options) == 0):
 			// Is a node and no connections, so we just pick all options
-			log("NO, so find new instances anyway")
 			options = allInstances(host_model, original_typename)
-		else:
-			log("YES, so got instance already")
-
-		log("Returned options: " + set_to_string(options))
 
 	// Filter options further
 	Element filtered_options
@@ -404,7 +388,6 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 
 	while (read_nr_out(mappings) > 0):
 		mapping = set_pop(mappings)
-		log("Apply for mapping: " + dict_to_string(mapping))
 		// TODO check if there are actually no deletions happening in the meantime of other matched elements...
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "AtomicRHS"))
 		rewrite(host_model, schedule_model, RHS, mapping)

+ 1 - 1
integration/code/pn_interface.alc

@@ -471,7 +471,7 @@ Element function main():
 				schedule = input()
 				if (dict_in(root, schedule)):
 					result = transform(root[name], root[schedule])
-					output("Transformation result: " + cast_e2s(result))
+					output("Transformation result: " + cast_v2s(result))
 				else:
 					output("Unknown transformation selected!")
 			else:

+ 220 - 8
integration/test_pn_interface.py

@@ -1139,8 +1139,10 @@ Void function action(host_model : Element, name : String, mapping : Element):
             SimpleClassDiagrams (Inheritance) PetriNets_Runtime{
                 Class Natural {}
                 Class Boolean {}
+                Class String {}
                 Class Place {
                     tokens : Natural
+                    name : String
                 }
                 Class Transition {
                     executing : Boolean
@@ -1186,11 +1188,11 @@ Void function action(host_model : Element, name : String, mapping : Element):
             export pn to models/pn
             """
 
-        schedule_model = \
+        schedule_model_annotate = \
             """
-            import models/PetriNets_SCHEDULE as PN_Transform
+            import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
 
-            PN_Transform annotate {
+            RAM_PN_DR annotate {
                 Composite schedule {
                     {Contains} Failure failure {}
                     {Contains} Success success {}
@@ -1236,6 +1238,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                     include "modelling.alh"
                                     Void function action(host_model : Element, name : String, mapping : Element):
                                         instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
+                                        instantiate_attribute(host_model, name, "name", mapping["0"])
                                         return!
                                     $
                             }
@@ -1375,6 +1378,212 @@ Void function action(host_model : Element, name : String, mapping : Element):
             export annotate to models/pn_annotate
             """
 
+        schedule_model_print = \
+            """
+            import models/RAM_PetriNets_Runtime as RAM_PN_R
+
+            RAM_PN_R print {
+                Composite schedule {
+                    {Contains} Success success {}
+                    {Contains} ForAll print_tokens {
+                        LHS {
+                            Pre_Place {
+                                label = "0"
+                            }
+                        }
+                        RHS {
+                            Post_Place {
+                                label = "0"
+                                action = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Void function action(host_model : Element, name : String, mapping : Element):
+                                        output((cast_v2s(read_attribute(host_model, name, "name")) + " --> ") + cast_v2s(read_attribute(host_model, name, "tokens")))
+                                        return!
+                                    $
+                            }
+                        }
+                    }
+                }
+                OnSuccess (print_tokens, success) {}
+                OnFailure (print_tokens, success) {}
+                Initial (schedule, print_tokens) {}
+            }
+
+            export print to models/pn_print
+            """
+
+        schedule_model_simulate = \
+            """
+            import models/RAM_PetriNets_Runtime as RAM_PN_R
+
+            RAM_PN_R s {
+                Composite schedule {
+                    {Contains} Failure failure {}
+                    {Contains} Success success {}
+                    {Contains} Atomic mark {
+                        LHS {
+                            Pre_Transition {
+                                label = "1"
+                                constraint = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    include "object_operations.alh"
+                                    Boolean function constraint(host_model : Element, name : String):
+                                        Element links
+                                        String link
+                                        String place
+                                        links = allIncomingAssociationInstances(host_model, name, "P2T")
+                                        while (read_nr_out(links) > 0):
+                                            link = set_pop(links)
+                                            place = readAssociationSource(host_model, link)
+                                            if (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
+                                                return False!
+                                        return True!
+                                    $
+                            }
+                        }
+                        RHS {
+                            Post_Transition {
+                                label = "1"
+                                action = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Void function action(host_model : Element, name : String, mapping : Element):
+                                        unset_attribute(host_model, name, "executing")
+                                        instantiate_attribute(host_model, name, "executing", True)
+                                        return!
+                                    $
+                            }
+                        }
+                    }
+                    {Contains} ForAll consume {
+                        LHS {
+                            Pre_Transition lhs_consume_t{
+                                label = "0"
+                                constraint = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Boolean function constraint(host_model : Element, name : String):
+                                        // Check if this node is executing currently
+                                        return value_eq(read_attribute(host_model, name, "executing"), True)!
+                                    $
+                            }
+                            Pre_Place lhs_consume_p{
+                                label = "1"
+                            }
+                            Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
+                                label = "2"
+                            }
+                        }
+                        RHS {
+                            Post_Transition rhs_consume_t {
+                                label = "0"
+                            }
+                            Post_Place rhs_consume_p {
+                                label = "1"
+                                action = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Void function action(host_model : Element, name : String, mapping : Element):
+                                        Integer tokens
+                                        Integer weight
+                                        tokens = read_attribute(host_model, name, "tokens")
+                                        weight = read_attribute(host_model, mapping["2"], "weight")
+                                        unset_attribute(host_model, name, "tokens")
+                                        instantiate_attribute(host_model, name, "tokens", tokens - weight)
+                                        return!
+                                    $
+                            }
+                            Post_P2T (rhs_consume_p, rhs_consume_t){
+                                label = "2"
+                            }
+                        }
+                    }
+                    {Contains} ForAll produce {
+                        LHS {
+                            Pre_Transition lhs_produce_t{
+                                label = "0"
+                                constraint = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Boolean function constraint(host_model : Element, name : String):
+                                        // Check if this node is executing currently
+                                        return value_eq(read_attribute(host_model, name, "executing"), True)!
+                                    $
+                            }
+                            Pre_Place lhs_produce_p{
+                                label = "1"
+                            }
+                            Pre_T2P (lhs_produce_t, lhs_produce_p){
+                                label = "2"
+                            }
+                        }
+                        RHS {
+                            Post_Transition rhs_produce_t{
+                                label = "0"
+                            }
+                            Post_Place rhs_produce_p{
+                                label = "1"
+                                action = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Void function action(host_model : Element, name : String, mapping : Element):
+                                        Integer tokens
+                                        Integer weight
+                                        tokens = read_attribute(host_model, name, "tokens")
+                                        weight = read_attribute(host_model, mapping["2"], "weight")
+                                        unset_attribute(host_model, name, "tokens")
+                                        instantiate_attribute(host_model, name, "tokens", tokens + weight)
+                                        return!
+                                    $
+                            }
+                            Post_T2P (rhs_produce_t, rhs_produce_p){
+                                label = "2"
+                            }
+                        }
+                    }
+                    {Contains} Atomic unmark_transition {
+                        LHS {
+                            Pre_Transition {
+                                label = "0"
+                                constraint = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Boolean function constraint(host_model : Element, name : String):
+                                        // Check if this node is executing currently
+                                        return value_eq(read_attribute(host_model, name, "executing"), True)!
+                                    $
+                            }
+                        }
+                        RHS {
+                            Post_Transition {
+                                label = "0"
+                                action = $
+                                    include "primitives.alh"
+                                    include "modelling.alh"
+                                    Void function action(host_model : Element, name : String, mapping : Element):
+                                        unset_attribute(host_model, name, "executing")
+                                        instantiate_attribute(host_model, name, "executing", False)
+                                        return!
+                                    $
+                            }
+                        }
+                    }
+                }
+                OnSuccess (mark, consume) {}
+                OnFailure (mark, failure) {}
+                OnSuccess (consume, produce) {}
+                OnFailure (consume, produce) {}
+                OnSuccess (produce, unmark_transition) {}
+                OnFailure (produce, unmark_transition) {}
+                OnSuccess (unmark_transition, success) {}
+                OnFailure (unmark_transition, failure) {}
+                Initial (schedule, mark) {}
+            }
+
+            export s to models/pn_simulate
+            """
         self.assertTrue(run_file(all_files,
             get_model_constructor(PN_runtime) + \
                 get_model_constructor(PN_model) + [
@@ -1384,12 +1593,15 @@ Void function action(host_model : Element, name : String, mapping : Element):
                     "instantiate", "Association", "PlaceLink", "SOURCE_Place", "TARGET_Place",
                     "instantiate", "Association", "TransitionLink", "SOURCE_Transition", "TARGET_Transition",
                     "exit",
-                "ramify", "PetriNets_SCHEDULE", "PetriNets_Design_to_Runtime",
-                ] + get_model_constructor(schedule_model) + [
+                "ramify", "RAM_PetriNets_Design_Runtime", "PetriNets_Design_to_Runtime",
+                "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
+                ] + get_model_constructor(schedule_model_annotate) + [
+                ] + get_model_constructor(schedule_model_print) + [
+                ] + get_model_constructor(schedule_model_simulate) + [
                 "transform", "pn", "pn_annotate",
                 "split", "pn", "PetriNets_Runtime", "TARGET_",
-                "load", "pn",
-                    "verify",
-                    "exit",
+                "transform", "pn", "pn_print",
+                "transform", "pn", "pn_simulate",
+                "transform", "pn", "pn_print",
             ],
           None, "PO"))

+ 0 - 1
integration/utils.py

@@ -293,6 +293,5 @@ def get_model_constructor(code):
         f.flush()
 
     constructors = ["upload"] + do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M") + ["exit"]
-    print(constructors)
 
     return constructors