Browse Source

Fixed FSA live modelling by falling back to the initial state

Yentl Van Tendeloo 6 years ago
parent
commit
bbb3e90df7
3 changed files with 26 additions and 4 deletions
  1. 17 4
      models/fsa_merge.alc
  2. 7 0
      models/fsa_toRuntime.alc
  3. 2 0
      models/live_modelling.py

+ 17 - 4
models/fsa_merge.alc

@@ -43,13 +43,15 @@ Boolean function main(model : Element):
 		// Copy the time though
 		element_name = instantiate_node(model, "NewFullRuntime/Time", "")
 		instantiate_attribute(model, element_name, "current_time", read_attribute(model, set_pop(allInstances(model, "FullRuntime/Time")), "current_time"))
+		log("Time copied OK")
 
+	log("Reading existing data")
 	all_states = allInstances(model, "PartialRuntime/State")
 	while (set_len(all_states) > 0):
 		element_name = set_pop(all_states)
 		if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_state")) > 0):
-			// Element already exists in full, so copy existing attributes
-            instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current"))
+			// Element already exists in full, so check whether this is the current state
+			log("Found existing state")
 			if (read_attribute(model, map_P2F(model, element_name), "current")):
 				found_current = True
 				new_current = element_name
@@ -60,7 +62,14 @@ Boolean function main(model : Element):
 				log("FOUND IT!")
 				new_current = element_name
 			instantiate_link(model, "P2F_state", "", element_name, element_name)
+	
+	log("Deleting elements...")
+	all_states = allInstances(model, "NewFullRuntime/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		model_delete_element(model, element_name)
 
+	log("Copying elements...")
 	Element all_elements
 	String elem
 	all_elements = dict_keys(model["model"])
@@ -72,13 +81,14 @@ Boolean function main(model : Element):
 			if (read_type(model, elem) == "NewFullRuntime/State"):
 				instantiate_attribute(model, elem, "current", elem == new_current)
 
+	log("Setting current state...")
 	String new_state
 	if (found_current == False):
 		if (False):
 			// Prompt for new state
 			output("FIX_NEW_STATE")
 			new_state = input()
-			all_states = allInstances(model, "PartialRuntime/State")
+			all_states = allInstances(model, "NewFullRuntime/State")
 			while (set_len(all_states) > 0):
 				element_name = set_pop(all_states)
 				if (value_eq(read_attribute(model, element_name, "name"), new_state)):
@@ -86,10 +96,13 @@ Boolean function main(model : Element):
 					break!
 		else:
 			// Reset to initial
-			all_states = allInstances(model, "PartialRuntime/State")
+			log("Resetting to initial state!")
+			all_states = allInstances(model, "NewFullRuntime/State")
 			while (set_len(all_states) > 0):
 				element_name = set_pop(all_states)
 				if (value_eq(read_attribute(model, element_name, "initial"), True)):
+					log("Found initial state: " + cast_value(read_attribute(model, element_name, "name")))
 					instantiate_attribute(model, element_name, "current", True)
 					break!
+	log("DONE!")
 	return True!

+ 7 - 0
models/fsa_toRuntime.alc

@@ -37,6 +37,13 @@ Boolean function main(model : Element):
         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")))
 
+	all_states = allInstances(model, "PartialRuntime/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_state")) == 0):
+			// Old partial runtime element, so remove
+			model_delete_element(model, element_name)
+
 	// Delete all existing transitions
     all_links = allInstances(model, "PartialRuntime/Transition")
     while (set_len(all_links) > 0):

+ 2 - 0
models/live_modelling.py

@@ -5,6 +5,7 @@ from modelverse import *
 init()
 login("admin", "admin")
 
+"""
 ### live modelling DTCBD
 
 model_add("formalisms/DTCBD/Design_MM", "formalisms/SimpleClassDiagrams", open("models/dtcbd_design.mvc", 'r').read())
@@ -28,6 +29,7 @@ transformation_add_AL({"FullRuntime": "formalisms/DTCBD/FullRuntime_MM"}, {"Full
 transformation_add_AL({}, {}, "models/DTCBD/restartSim", open("models/cbd_restartSim.alc", 'r').read())
 
 model_add("models/live_modelling_DTCBD", "formalisms/ProcessModel", open("models/pm_live_DTCBD.mvc", 'r').read())
+"""
 
 """
 ### live modelling CTCBD