Browse Source

Mostly fixed live modelling for FSA

Yentl Van Tendeloo 8 years ago
parent
commit
ca8fb0ddf8

+ 1 - 1
models/cbd_restartSim.alc

@@ -8,5 +8,5 @@ Boolean function main(model : Element):
 	root = read_root()
 	tasknames = set_copy(root[get_taskname()]["globals"]["pm_tasks"]["value"]["simulate"])
 	while (set_len(tasknames) > 0):
-		give_input_to_other(set_pop(tasknames), "")
+		give_input_to_other(set_pop(tasknames), "__EXIT__")
 	return True!

+ 2 - 0
models/fsa_design.mvc

@@ -1,10 +1,12 @@
 include "primitives.alh"
 
 Class String {}
+Class Boolean {}
 
 Class State {
     name = "State"
     name : String
+    initial : Boolean
 }
 
 Association Transition (State, State) {

+ 1 - 0
models/fsa_full_runtime.mvc

@@ -7,6 +7,7 @@ Class State {
     name = "State"
     name : String
     current : Boolean
+    initial : Boolean
 }
 
 Association Transition (State, State) {

+ 20 - 1
models/fsa_merge.alc

@@ -22,7 +22,19 @@ Boolean function main(model : Element):
 	Element all_states
 	String element_name
 	Boolean found_current
+	Boolean flag_initial
+	String new_current
+
 	found_current = False
+	new_current = read_root()
+
+	if (set_len(allInstances(model, "FullRuntime/State")) == 0):
+		// No execution in full runtime, so just flag the initial state
+		flag_initial = True
+		log("Searching for new initial state...")
+	else:
+		flag_initial = False
+		log("No searching for state!")
 
 	all_states = allInstances(model, "PartialRuntime/State")
 	while (set_len(all_states) > 0):
@@ -32,9 +44,13 @@ Boolean function main(model : Element):
             instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current"))
 			if (read_attribute(model, map_P2F(model, element_name), "current")):
 				found_current = True
+				new_current = element_name
 		else:
 			// New state, so assume that it is not current
-            instantiate_attribute(model, element_name, "current", False)
+			log("Read value: " + cast_value(read_attribute(model, element_name, "initial")))
+			if (bool_and(flag_initial, read_attribute(model, element_name, "initial"))):
+				log("FOUND IT!")
+				new_current = element_name
 			instantiate_link(model, "P2F_state", "", element_name, element_name)
 
 	Element all_elements
@@ -45,6 +61,9 @@ Boolean function main(model : Element):
 		if (string_startswith(read_type(model, elem), "PartialRuntime/")):
 			retype(model, elem, "NewFullRuntime/" + cast_string(list_read(string_split_nr(read_type(model, elem), "/", 1), 1)))
 
+			if (read_type(model, elem) == "NewFullRuntime/State"):
+				instantiate_attribute(model, elem, "current", elem == new_current)
+
 	String new_state
 	if (found_current == False):
 		if (False):

+ 1 - 0
models/fsa_partial_runtime.mvc

@@ -6,6 +6,7 @@ Class Boolean {}
 Class State {
     name = "State"
     name : String
+    initial : Boolean
 }
 
 Association Transition (State, State) {

+ 22 - 7
models/fsa_simulate.alc

@@ -10,11 +10,25 @@ Boolean function main(model : Element):
 	String input_value
 	Float start_time
 	String current_state
+	String old_state
 	Element transitions
 	String transition
 
 	start_time = time()
 
+	Element all_states
+	String element_name
+	all_states = allInstances(model, "FullRuntime/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		log("Check " + cast_value(read_attribute(model, element_name, "name")))
+		log("  Current: " + cast_value(read_attribute(model, element_name, "current")))
+		if (value_eq(read_attribute(model, element_name, "current"), True)):
+			log("Found current: " + cast_value(read_attribute(model, element_name, "current")))
+			current_state = element_name
+			old_state = element_name
+			break!
+
 	while (True):
 		if (has_input()):
 			input_value = input()
@@ -25,19 +39,20 @@ Boolean function main(model : Element):
 			transitions = allOutgoingAssociationInstances(model, current_state, "FullRuntime/Transition")
 			while (set_len(transitions) > 0):
 				transition = set_pop(transitions)
-				if (read_attribute(model, transition, "trigger") == input_value):
+				if (cast_string(read_attribute(model, transition, "trigger")) == input_value):
 					if (element_neq(read_attribute(model, transition, "raise"), read_root())):
-						log(cast_value(time() - start_time) + " ! " + cast_value(read_attribute(model, transition, "raise")))
-						output(cast_value(time() - start_time) + " ! " + cast_value(read_attribute(model, transition, "raise")))
-					instantiate_attribute(model, current_state, "current", False)
+						log(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
+						output(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
 					current_state = readAssociationDestination(model, transition)
-					instantiate_attribute(model, current_state, "current", True)
 					break!
 
-		log(cast_value(time() - start_time) + " : " + cast_value(read_attribute(model, current_state, "name")))
-		output(cast_value(time() - start_time) + " : " + cast_value(read_attribute(model, current_state, "name")))
+		log(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
+		output(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
 		sleep(0.2)
 
 	log("CLOSE")
 	output("CLOSE")
+	
+	instantiate_attribute(model, current_state, "current", True)
+	instantiate_attribute(model, old_state, "current", True)
 	return True!

+ 1 - 0
models/fsa_toRuntime.alc

@@ -35,6 +35,7 @@ Boolean function main(model : Element):
 		new_element_name = map_D2P(model, element_name)
         instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
         instantiate_attribute(model, new_element_name, "initial", read_attribute(model, element_name, "initial"))
+		log("Copied state initial: " + cast_value(new_element_name) + ", initial: " + cast_value(read_attribute(model, element_name, "initial")))
 
 	// Delete all existing transitions
     all_links = allInstances(model, "PartialRuntime/Transition")

+ 1 - 2
models/live_modelling.py

@@ -53,6 +53,7 @@ transformation_add_MT({"Design": "formalisms/CTCBD/Design_MM", "PartialRuntime":
 #transformation_add_AL({}, {}, "models/DTCBD/restartSim", open("models/cbd_restartSim.alc", 'r').read())
 
 model_add("models/live_modelling_CTCBD", "formalisms/ProcessModel", open("models/pm_live_CTCBD.mvc", 'r').read())
+"""
 
 ### live modelling FSA
 
@@ -77,5 +78,3 @@ transformation_add_AL({"FullRuntime": "formalisms/FSA/FullRuntime_MM"}, {"FullRu
 transformation_add_AL({}, {}, "models/FSA/restartSim", open("models/cbd_restartSim.alc", 'r').read())
 
 model_add("models/live_modelling_FSA", "formalisms/ProcessModel", open("models/pm_live_FSA.mvc", 'r').read())
-
-"""