Browse Source

Added LoLa service script

Yentl Van Tendeloo 8 years ago
parent
commit
abfaf56b78
2 changed files with 164 additions and 4 deletions
  1. 125 0
      models/lola.alc
  2. 39 4
      wrappers/modelverse_SCCD.py

+ 125 - 0
models/lola.alc

@@ -0,0 +1,125 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+include "services.alh"
+
+Boolean function lola_format(model : Element):
+	Element all_places
+	String place
+	String name
+	Integer tokens
+	String transition
+	Element all_transitions
+	Element associations
+	Element association
+	String weight
+	String lola_net
+	String query
+	String place_output
+	String marking_output
+	String transition_output
+
+	all_places = allInstances(model, "PN/Place")
+	log("ALL PLACES")
+	log(cast_i2s(list_len(all_places)))
+	place_output = "PLACE "
+	marking_output = "MARKING "
+	while (set_len(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+		tokens = read_attribute(model, place, "tokens")
+
+		place_output = string_join(place_output, name)
+
+		if tokens > 0:
+			if marking_output != "MARKING ":
+				marking_output = string_join(marking_output, ", ")
+			marking_output = string_join(marking_output, name)
+			marking_output = string_join(marking_output, ": ")
+			marking_output = string_join(marking_output, cast_i2s(tokens))
+	
+		if list_len(all_places) == 0:
+			place_output = string_join(place_output, ";")
+			marking_output = string_join(marking_output, ";")
+		else:
+			place_output = string_join(place_output, ", ")
+
+	lola_net = string_join(place_output, marking_output)
+
+	all_transitions = allInstances(model, "PN/Transition")
+	transition_output = ""
+	while (set_len(all_transitions) > 0):
+		transition = set_pop(all_transitions)
+		name = read_attribute(model, transition, "name")
+
+		transition_output = string_join(transition_output, " TRANSITION ")
+		transition_output = string_join(transition_output, name)
+		transition_output = string_join(transition_output, " CONSUME ")
+
+		associations = allIncomingAssociationInstances(model, transition, "PN/P2T")
+		while (set_len(associations) > 0):
+			association = set_pop(associations)
+			place = readAssociationSource(model, association)
+			weight = read_attribute(model, association, "weight")
+			if cast_s2i(weight) > 0:
+				transition_output = string_join(transition_output, read_attribute(model, place, "name"))
+				transition_output = string_join(transition_output, ": ")
+				transition_output = string_join(transition_output, weight)
+
+			if list_len(associations) == 0:
+				transition_output = string_join(transition_output, ";")
+			else:
+				transition_output = string_join(transition_output, ", ")
+
+		transition_output = string_join(transition_output, " PRODUCE ")
+
+		associations = allOutgoingAssociationInstances(model, transition, "PN/T2P")
+		while (set_len(associations) > 0):
+			association = set_pop(associations)
+			place = readAssociationDestination(model, association)
+			weight = read_attribute(model, association, "weight")
+			if cast_s2i(weight) > 0:
+				transition_output = string_join(transition_output, read_attribute(model, place, "name"))
+				transition_output = string_join(transition_output, ": ")
+				transition_output = string_join(transition_output, weight)
+
+			if list_len(associations) == 0:
+				transition_output = string_join(transition_output, ";")
+			else:
+				transition_output = string_join(transition_output, ", ")
+
+	lola_net = string_join(lola_net, transition_output)
+
+	all_places = allInstances(model, "Query/Place")
+	if set_len(all_places) > 0:
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+		tokens = read_attribute(model, place, "tokens")
+		query = string_join(name, ' = ')
+		query = string_join(query, cast_i2s(tokens))
+
+	log("PETRINET OUTPUT")
+	log(lola_net)
+	log("\n QUERY OUTPUT")
+	log(query)
+	output = string_join("{\"petrinet\":\"", lola_net)
+	output = string_join(output, "\" , \"query\":\"")
+	output = string_join(output, query)
+	output = string_join(output, "\"}")
+
+	log("\n JSON OUTPUT")
+	log(output)
+
+	String port
+	port = comm_connect("lola")
+	comm_set(port, output)
+
+	String result
+	String path
+	result = comm_get(port)
+	path = comm_get(port)
+	log("\nLola safety query analysis result: " + result)
+	log("\nLola path: "+path)
+	comm_close(port)
+
+	return True!

+ 39 - 4
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Thu Nov  9 08:24:57 2017
+Date:   Thu Nov  9 09:30:59 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
@@ -572,11 +572,15 @@ class Modelverse(RuntimeClassBase):
         self.states["/initialized/behaviour/leaving_manual"] = State(126, "/initialized/behaviour/leaving_manual", self)
         self.states["/initialized/behaviour/leaving_manual"] = State(126, "/initialized/behaviour/leaving_manual", self)
         self.states["/initialized/behaviour/leaving_manual"].setEnter(self._initialized_behaviour_leaving_manual_enter)
         self.states["/initialized/behaviour/leaving_manual"].setEnter(self._initialized_behaviour_leaving_manual_enter)
         
         
+        # state /initialized/behaviour/leaving_manual_drop
+        self.states["/initialized/behaviour/leaving_manual_drop"] = State(127, "/initialized/behaviour/leaving_manual_drop", self)
+        self.states["/initialized/behaviour/leaving_manual_drop"].setEnter(self._initialized_behaviour_leaving_manual_drop_enter)
+        
         # state /initialized/queue
         # state /initialized/queue
-        self.states["/initialized/queue"] = State(127, "/initialized/queue", self)
+        self.states["/initialized/queue"] = State(128, "/initialized/queue", self)
         
         
         # state /initialized/queue/queue
         # state /initialized/queue/queue
-        self.states["/initialized/queue/queue"] = State(128, "/initialized/queue/queue", self)
+        self.states["/initialized/queue/queue"] = State(129, "/initialized/queue/queue", self)
         
         
         # add children
         # add children
         self.states[""].addChild(self.states["/init"])
         self.states[""].addChild(self.states["/init"])
@@ -593,6 +597,7 @@ class Modelverse(RuntimeClassBase):
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/going_manual"])
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/going_manual"])
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/going_scripted"])
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/going_scripted"])
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/leaving_manual"])
         self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/leaving_manual"])
+        self.states["/initialized/behaviour"].addChild(self.states["/initialized/behaviour/leaving_manual_drop"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/connect_http_client"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/connect_http_client"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/waiting_http_client"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/waiting_http_client"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/wait_for_taskname_ack"])
         self.states["/initialized/behaviour/init"].addChild(self.states["/initialized/behaviour/init/wait_for_taskname_ack"])
@@ -1677,10 +1682,14 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_manual_0_guard)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_manual_0_guard)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_manual_0)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_manual_0)
-        _initialized_behaviour_wait_for_action_modelling_recognized_manual_1 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"], [self.states["/initialized/behaviour/leaving_manual"]])
+        _initialized_behaviour_wait_for_action_modelling_recognized_manual_1 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"], [self.states["/initialized/behaviour/leaving_manual_drop"]])
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_1.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_1.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_1.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_manual_1_guard)
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_1.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_manual_1_guard)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_manual_1)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_manual_1)
+        _initialized_behaviour_wait_for_action_modelling_recognized_manual_2 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"], [self.states["/initialized/behaviour/leaving_manual"]])
+        _initialized_behaviour_wait_for_action_modelling_recognized_manual_2.setTrigger(None)
+        _initialized_behaviour_wait_for_action_modelling_recognized_manual_2.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_manual_2_guard)
+        self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_manual_2)
         
         
         # transition /initialized/behaviour/wait_for_action/modelling/recognized/scripted
         # transition /initialized/behaviour/wait_for_action/modelling/recognized/scripted
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"], [self.states["/initialized/behaviour/operations/store_on_scripted/history"]])
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"], [self.states["/initialized/behaviour/operations/store_on_scripted/history"]])
@@ -1688,6 +1697,11 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0.setTrigger(None)
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_guard)
         _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_guard)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_scripted_0)
         self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_scripted_0)
+        _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"], [self.states["/initialized/behaviour/operations/store_on_scripted/history"]])
+        _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1.setAction(self._initialized_behaviour_wait_for_action_modelling_recognized_scripted_1_exec)
+        _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1.setTrigger(None)
+        _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1.setGuard(self._initialized_behaviour_wait_for_action_modelling_recognized_scripted_1_guard)
+        self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"].addTransition(_initialized_behaviour_wait_for_action_modelling_recognized_scripted_1)
         
         
         # transition /initialized/behaviour/going_manual/init
         # transition /initialized/behaviour/going_manual/init
         _initialized_behaviour_going_manual_init_0 = Transition(self, self.states["/initialized/behaviour/going_manual/init"], [self.states["/initialized/behaviour/going_manual/OK"]])
         _initialized_behaviour_going_manual_init_0 = Transition(self, self.states["/initialized/behaviour/going_manual/init"], [self.states["/initialized/behaviour/going_manual/OK"]])
@@ -1728,6 +1742,12 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_leaving_manual_0.setGuard(self._initialized_behaviour_leaving_manual_0_guard)
         _initialized_behaviour_leaving_manual_0.setGuard(self._initialized_behaviour_leaving_manual_0_guard)
         self.states["/initialized/behaviour/leaving_manual"].addTransition(_initialized_behaviour_leaving_manual_0)
         self.states["/initialized/behaviour/leaving_manual"].addTransition(_initialized_behaviour_leaving_manual_0)
         
         
+        # transition /initialized/behaviour/leaving_manual_drop
+        _initialized_behaviour_leaving_manual_drop_0 = Transition(self, self.states["/initialized/behaviour/leaving_manual_drop"], [self.states["/initialized/behaviour/wait_for_action/megamodelling"]])
+        _initialized_behaviour_leaving_manual_drop_0.setTrigger(None)
+        _initialized_behaviour_leaving_manual_drop_0.setGuard(self._initialized_behaviour_leaving_manual_drop_0_guard)
+        self.states["/initialized/behaviour/leaving_manual_drop"].addTransition(_initialized_behaviour_leaving_manual_drop_0)
+        
         # transition /initialized/queue/queue
         # transition /initialized/queue/queue
         _initialized_queue_queue_0 = Transition(self, self.states["/initialized/queue/queue"], [self.states["/initialized/queue/queue"]])
         _initialized_queue_queue_0 = Transition(self, self.states["/initialized/queue/queue"], [self.states["/initialized/queue/queue"]])
         _initialized_queue_queue_0.setAction(self._initialized_queue_queue_0_exec)
         _initialized_queue_queue_0.setAction(self._initialized_queue_queue_0_exec)
@@ -2171,6 +2191,9 @@ class Modelverse(RuntimeClassBase):
     def _initialized_behaviour_leaving_manual_enter(self):
     def _initialized_behaviour_leaving_manual_enter(self):
         self.raiseInternalEvent(Event("request", None, ['exit']))
         self.raiseInternalEvent(Event("request", None, ['exit']))
     
     
+    def _initialized_behaviour_leaving_manual_drop_enter(self):
+        self.raiseInternalEvent(Event("request", None, ['drop']))
+    
     def _initialized_behaviour_operations_0_exec(self, parameters):
     def _initialized_behaviour_operations_0_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownIdentifier', 'Element could not be found']))
         self.raiseInternalEvent(Event("exception", None, ['UnknownIdentifier', 'Element could not be found']))
         self.responses.pop(0)
         self.responses.pop(0)
@@ -3308,6 +3331,9 @@ class Modelverse(RuntimeClassBase):
         return self.expect_action(self.context, 'exit')
         return self.expect_action(self.context, 'exit')
     
     
     def _initialized_behaviour_wait_for_action_modelling_recognized_manual_1_guard(self, parameters):
     def _initialized_behaviour_wait_for_action_modelling_recognized_manual_1_guard(self, parameters):
+        return self.expect_action(self.context, 'drop')
+    
+    def _initialized_behaviour_wait_for_action_modelling_recognized_manual_2_guard(self, parameters):
         return self.actions[self.context] and self.actions[self.context][0]['parameters'][0] != self.current_model
         return self.actions[self.context] and self.actions[self.context][0]['parameters'][0] != self.current_model
     
     
     def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_exec(self, parameters):
     def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_exec(self, parameters):
@@ -3316,6 +3342,12 @@ class Modelverse(RuntimeClassBase):
     def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_guard(self, parameters):
     def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_0_guard(self, parameters):
         return self.expect_action(self.context, 'exit')
         return self.expect_action(self.context, 'exit')
     
     
+    def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1_exec(self, parameters):
+        self.raiseInternalEvent(Event("request", None, ['drop']))
+    
+    def _initialized_behaviour_wait_for_action_modelling_recognized_scripted_1_guard(self, parameters):
+        return self.expect_action(self.context, 'drop')
+    
     def _initialized_behaviour_going_manual_init_0_guard(self, parameters):
     def _initialized_behaviour_going_manual_init_0_guard(self, parameters):
         return self.current_model in self.registered_metamodel
         return self.current_model in self.registered_metamodel
     
     
@@ -3342,6 +3374,9 @@ class Modelverse(RuntimeClassBase):
     def _initialized_behaviour_leaving_manual_0_guard(self, parameters):
     def _initialized_behaviour_leaving_manual_0_guard(self, parameters):
         return self.expect_response('Success', pop=True)
         return self.expect_response('Success', pop=True)
     
     
+    def _initialized_behaviour_leaving_manual_drop_0_guard(self, parameters):
+        return self.expect_response('Success', pop=True)
+    
     def _initialized_queue_queue_0_exec(self, parameters):
     def _initialized_queue_queue_0_exec(self, parameters):
         action_name = parameters[0]
         action_name = parameters[0]
         ID = parameters[1]
         ID = parameters[1]