Browse Source

Fixes for PN and CTCBD and DTCBD transformations

Yentl Van Tendeloo 3 years ago
parent
commit
48d70a2c90

BIN
bootstrap/bootstrap.m.gz


+ 11 - 3
examples/upload_simple_formalisms.py

@@ -12,11 +12,19 @@ model_add("formalisms/DTCBD/MM", "formalisms/SimpleClassDiagrams", open("models/
 transformation_add_AL({"DTCBD": "formalisms/DTCBD/MM"}, {}, "formalisms/DTCBD/simulate", open("models/DTCBD/transformations/simple_simulate.alc", 'r').read())
 
 model_add("formalisms/CTCBD/MM", "formalisms/SimpleClassDiagrams", open("models/CTCBD/metamodels/CTCBD_MM.mvc", 'r').read())
-transformation_add_MT({"Design": "formalisms/CTCBD/MM"}, {"PartialRuntime": "formalisms/DTCBD/MM"}, "formalisms/CTCBD/discretize", open("models/CTCBD/transformations/to_partial_runtime.mvc", 'r').read())
+def trace_D2P(model):
+    instantiate(model, "Association", ("Design/Block", "PartialRuntime/Block"), ID="D2P_block")
+transformation_add_MT({"Design": "formalisms/CTCBD/MM"}, {"PartialRuntime": "formalisms/DTCBD/MM"}, "formalisms/CTCBD/discretize", open("models/CTCBD/transformations/to_partial_runtime.mvc", 'r').read(), trace_D2P)
 
 model_add("formalisms/PN/MM", "formalisms/SimpleClassDiagrams", open("models/PetriNets/metamodels/PetriNets.mvc", 'r').read())
-transformation_add_AL({"PN": "formalisms/PN/MM"}, {"PN": "formalisms/PN/MM"}, "formalisms/PN/simulate", open("models/PetriNets/transformations/simple_simulate.alc", 'r').read())
+transformation_add_AL({"PetriNet": "formalisms/PN/MM"}, {"PetriNet": "formalisms/PN/MM"}, "formalisms/PN/simulate", open("models/PetriNets/transformations/simple_simulate.alc", 'r').read())
 
 model_add("formalisms/Query", "formalisms/SimpleClassDiagrams", open("models/SafetyQuery/metamodels/query.mvc", 'r').read())
 model_add("formalisms/PNPath", "formalisms/SimpleClassDiagrams", open("models/PNPath/metamodels/PNPath.mvc", 'r').read())
-transformation_add_AL({"PN": "formalisms/PN/MM", "Query": "formalisms/Query"}, {"Path": "formalisms/PNPath"}, "models/analyze_lola", open("models/PetriNets/transformations/analyze_lola.alc", 'r').read())
+transformation_add_AL({"PN": "formalisms/PN/MM", "Query": "formalisms/Query"}, {"Path": "formalisms/PNPath"}, "formalisms/PN/analyze", open("models/PetriNets/transformations/analyze_lola.alc", 'r').read())
+
+model_add("models/FSA/alarm", "formalisms/FSA/MM", open("models/FiniteStateAutomata/models/alarm.mvc", 'r').read())
+model_add("models/DTCBD/loop", "formalisms/DTCBD/MM", open("models/DTCBD/models/simple_equation.mvc", 'r').read())
+model_add("models/CTCBD/spring", "formalisms/CTCBD/MM", open("models/CTCBD/models/spring.mvc", 'r').read())
+model_add("models/PN/critical", "formalisms/PN/MM", open("models/PetriNets/models/critical_section_with_check.mvc", 'r').read())
+model_add("models/Query/error", "formalisms/Query", open("models/SafetyQuery/models/both_criticals_enabled.mvc", 'r').read())

+ 12 - 2
kernel/modelverse_kernel/main.py

@@ -354,6 +354,7 @@ class ModelverseKernel(object):
                                 ("RD", [inst, "body"])]
             (prev_cond, instruction_cond), = yield [("CALL_ARGS", [self.print_instruction, (cond, 0, indent+1)])]
             (prev_body, instruction_body), = yield [("CALL_ARGS", [self.print_instruction, (body, indent+1)])]
+            """
             instruction = "  " * indent + "__counter_%s = 0\n" % inst + \
                           "  " * indent + "while 1:\n" + prev_cond + \
                           "  " * (indent + 1) + "if 'value' not in %s:\n" % instruction_cond + \
@@ -362,10 +363,20 @@ class ModelverseKernel(object):
                           "  " * (indent + 2) + "break\n" + \
                           "  " * (indent + 1) + "else:\n" + \
                           "  " * (indent + 2) + "__counter_%s += 1\n" % inst + \
-                          "  " * (indent + 2) + "if __counter_%s > 20:\n" % inst + \
+                          "  " * (indent + 2) + "if __counter_%s > 5:\n" % inst + \
                           "  " * (indent + 3) + "yield None\n" + \
                           "  " * (indent + 3) + "__counter_%s = 0\n" % inst + \
                           prev_body + instruction_body
+            """
+            instruction = \
+                          "  " * indent + "while 1:\n" + prev_cond + \
+                          "  " * (indent + 1) + "if 'value' not in %s:\n" % instruction_cond + \
+                          "  " * (indent + 2) + "%s['value'], = yield [('RV', [%s['id']])]\n" % (instruction_cond, instruction_cond) + \
+                          "  " * (indent + 1) + "if not (%s['value']):\n" % instruction_cond + \
+                          "  " * (indent + 2) + "break\n" + \
+                          "  " * (indent + 1) + "else:\n" + \
+                          "  " * (indent + 2) + "yield None\n" + \
+                          prev_body + instruction_body
 
 
         next_inst, = yield [("RD", [inst, "next"])]
@@ -535,7 +546,6 @@ class ModelverseKernel(object):
 
             self.returnvalue = rv_value
             self.success = True
-            #print("OUTPUT: (%s, %s)" % (taskname, self.returnvalue))
         yield [("FINISH", [])]
 
     def set_input(self, taskname, value):

+ 5 - 2
models/DTCBD/transformations/simple_simulate.alc

@@ -24,6 +24,9 @@ Boolean function main(model : Element):
 	Element nodes
 	Element inputs
 	String node
+
+	model_define_attribute(model["metamodel"], "DTCBD/Block", "signal", True, "DTCBD/Float")
+
 	nodes = allInstances(model, "DTCBD/Block")
 	inputs = dict_create()
 	while (set_len(nodes) > 0):
@@ -31,7 +34,7 @@ Boolean function main(model : Element):
 		dict_add(inputs, node, allAssociationOrigins(model, node, "DTCBD/Link"))
 
 	while (bool_not(has_input())):
-		if (read_attribute(model, time, "start_time") == read_attribute(model, time, "current_time")):
+		if (current_time == 0.0):
 			schedule = schedule_init
 		else:
 			if (element_eq(schedule_run, read_root())):
@@ -40,7 +43,7 @@ Boolean function main(model : Element):
 		current_time = step_simulation(model, schedule, current_time, inputs)
 
 	output("CLOSE")
-	return True!
+	return False!
 
 Element function create_schedule(model : Element):
 	// Create nice graph first

+ 5 - 1
models/PetriNets/transformations/simple_simulate.alc

@@ -15,6 +15,7 @@ Boolean function main(model : Element):
 	while (set_len(transitions) > 0):
 		// Check if it is enabled
 		transition = set_pop(transitions)
+		log("Check transition " + cast_string(transition))
 
 		// Check all incoming P2T links
 		links = allIncomingAssociationInstances(model, transition, "PetriNet/P2T")
@@ -28,19 +29,22 @@ Boolean function main(model : Element):
 				break!
 
 		if (enabled):
+			log("Enabled!")
 			// All checks OK, so update the out locations
 			links = allOutgoingAssociationInstances(model, transition, "PetriNet/T2P")
 			while (set_len(links) > 0):
 				link = set_pop(links)
 				place = readAssociationDestination(model, link)
 				instantiate_attribute(model, place, "tokens", cast_integer(read_attribute(model, place, "tokens")) + cast_integer(read_attribute(model, link, "weight")))
+				log("New tokens TGT: " + cast_string(read_attribute(model, place, "tokens")))
 
 			// All checks OK, and update the in locations
-			links = allOutgoingAssociationInstances(model, transition, "PetriNet/P2T")
+			links = allIncomingAssociationInstances(model, transition, "PetriNet/P2T")
 			while (set_len(links) > 0):
 				link = set_pop(links)
 				place = readAssociationSource(model, link)
 				instantiate_attribute(model, place, "tokens", cast_integer(read_attribute(model, place, "tokens")) - cast_integer(read_attribute(model, link, "weight")))
+				log("New tokens SRC: " + cast_string(read_attribute(model, place, "tokens")))
 
 			return True!