Procházet zdrojové kódy

Working multi-step until a stable state is reached

Yentl Van Tendeloo před 8 roky
rodič
revize
e143d3ac4e
1 změnil soubory, kde provedl 27 přidání a 22 odebrání
  1. 27 22
      models/SCCD_execute.alc

+ 27 - 22
models/SCCD_execute.alc

@@ -170,7 +170,7 @@ Element function execute_transition(model : Element, data : Element, class : Str
 	// Return new set of states
 	return expand_state(model, readAssociationDestination(model, transition))!
 
-Float function step_class(model : Element, data : Element, class : String):
+Boolean function step_class(model : Element, data : Element, class : String):
 	// Find enabled transitions in a class and execute it, updating the state
 	// Iterate over all current states, searching for enabled transitions
 	// Search for enabled transitions in higher levels as well!
@@ -179,9 +179,11 @@ Float function step_class(model : Element, data : Element, class : String):
 	String state
 	Element transitions
 	String transition
+	Boolean transitioned
 
 	states = set_copy(data["classes"][class]["states"])
 	new_states = create_node()
+	transitioned = False
 
 	while (read_nr_out(states) > 0):
 		state = set_pop(states)
@@ -194,6 +196,7 @@ Float function step_class(model : Element, data : Element, class : String):
 			
 			// Execute transition
 			set_merge(new_states, execute_transition(model, data, class, transition))
+			transitioned = True
 		else:
 			// Try going to the parent
 			// TODO
@@ -205,21 +208,7 @@ Float function step_class(model : Element, data : Element, class : String):
 	dict_overwrite(data["classes"][class], "states", new_states)
 	reschedule_timeouts(model, data, class)
 
-	// Find minimum timer for this class, and return that
-	Float t_min
-	Float t_current
-	Element keys
-	String key
-
-	t_min = time() + 99999.0
-	keys = dict_keys(data["classes"][class]["timers"])
-	while (read_nr_out(keys) > 0):
-		key = set_pop(keys)
-		t_current = data["classes"][class]["timers"][key]
-		if (t_current < t_min):
-			t_min = t_current
-
-	return t_min!
+	return transitioned!
 
 Void function reschedule_timeouts(model : Element, data : Element, class : String):
 	Element timed_transitions
@@ -270,7 +259,10 @@ Float function step(model : Element, data : Element):
 	Element classes
 	Element class
 	Float t_min
-	Float t_class
+	Float t_current
+	Boolean transitioned
+	Element keys
+	String key
 
 	t_min = time() + 99999.0
 	classes = dict_keys(data["classes"])
@@ -278,13 +270,26 @@ Float function step(model : Element, data : Element):
 	// TODO this should use simulated time or something
 	dict_overwrite(data, "start_time", time())
 
+	transitioned = False
 	while (read_nr_out(classes) > 0):
 		class = set_pop(classes)
-		t_class = step_class(model, data, class)
-		if (t_class < t_min):
-			t_min = t_class
-
-	return float_subtraction(t_min, data["start_time"])!
+		if (step_class(model, data, class)):
+			transitioned = True
+
+		if (bool_not(transitioned)):
+			// Find minimum timer for this class, and store that
+			keys = dict_keys(data["classes"][class]["timers"])
+			while (read_nr_out(keys) > 0):
+				key = set_pop(keys)
+				t_current = data["classes"][class]["timers"][key]
+				if (t_current < t_min):
+					t_min = t_current
+
+	if (transitioned):
+		// Do another step, as we can transition
+		return 0.0!
+	else:
+		return float_subtraction(t_min, data["start_time"])!
 
 Boolean function main(model : Element):
 	// Executes the provided SCCD model