Bläddra i källkod

Add hierarchy and leaving of orthogonal components

Yentl Van Tendeloo 8 år sedan
förälder
incheckning
4853721a58
4 ändrade filer med 56 tillägg och 22 borttagningar
  1. 10 2
      bootstrap/utils.alc
  2. 15 0
      integration/code/minimal_SCCD.mvc
  3. 2 1
      interface/HUTN/includes/utils.alh
  4. 29 19
      models/SCCD_execute.alc

+ 10 - 2
bootstrap/utils.alc

@@ -100,7 +100,7 @@ Element function list_splice(lst : Element, start : Integer, end : Integer):
 
 	return result!
 
-Element function list_extend(lst : Element, ext : Element):
+Void function list_extend(lst : Element, ext : Element):
 	Integer i
 	i = 0
 
@@ -108,4 +108,12 @@ Element function list_extend(lst : Element, ext : Element):
 		list_append(lst, list_read(ext, i))
 		i = i + 1
 
-	return lst!
+	return!
+
+Void function set_difference(set1 : Element, set2 : Element):
+	set2 = set_copy(set2)
+
+	while (read_nr_out(set2) > 0):
+		set_remove(set1, set_pop(set2))
+
+	return!

+ 15 - 0
integration/code/minimal_SCCD.mvc

@@ -34,6 +34,16 @@ CompositeState main_statechart {
             $
     }
 
+    {composite_children} BasicState exit {
+        name = "exit"
+        isInitial = False
+        onEntryScript = $
+            Void function entry(attributes : Element):
+                log("ENTRY exit")
+                return!
+            $
+    }
+
     {composite_children} ParallelState main_parallel {
         name = "parallel"
         isInitial = False
@@ -130,5 +140,10 @@ transition (init, main_parallel) {
     event = "init"
 }
 
+transition (main_parallel, exit) {
+    name = "exit"
+    event = "exit"
+}
+
 diagram_classes (my_SCCD, main) {}
 behaviour (main, main_statechart) {}

+ 2 - 1
interface/HUTN/includes/utils.alh

@@ -2,4 +2,5 @@ String function JSON_print(model : Element)
 Element function input_timeout(timeout : Float)
 Element function list_reverse(lst : Element)
 Element function list_splice(lst : Element, start : Integer, end : Integer)
-Element function list_extend(lst : Element, ext : Element)
+Void function list_extend(lst : Element, ext : Element)
+Void function set_difference(set1 : Element, set2 : Element)

+ 29 - 19
models/SCCD_execute.alc

@@ -150,7 +150,6 @@ Void function start_class(model : Element, data : Element, class : String):
 
 Element function get_enabled_transitions(model : Element, state : String, data : Element, class : String):
 	// Returns all enabled transitions
-	// TODO ignore conditions and afters
 	Element result
 	Element to_filter
 	String attr
@@ -225,8 +224,6 @@ Element function execute_transition(model : Element, data : Element, class : Str
 	source_states = expand_current_state(model, readAssociationSource(model, transition), data["classes"][class]["states"])
 	target_states = expand_initial_state(model, readAssociationDestination(model, transition))
 
-	log("Source state expanded to: " + set_to_string(source_states))
-	log("Target state expanded to: " + set_to_string(target_states))
 	execute_actions(model, source_states, target_states, data["classes"][class]["attributes"])
 
 	return target_states!
@@ -241,6 +238,9 @@ Boolean function step_class(model : Element, data : Element, class : String):
 	Element transitions
 	String transition
 	Boolean transitioned
+	Element hierarchy
+	String current_state
+	Boolean found
 
 	states = set_copy(data["classes"][class]["states"])
 	new_states = create_node()
@@ -248,20 +248,31 @@ Boolean function step_class(model : Element, data : Element, class : String):
 
 	while (read_nr_out(states) > 0):
 		state = set_pop(states)
+		found = False
+
+		// Loop over the hierarchy of this state and try to apply transitions
+		hierarchy = find_hierarchy(model, state)
+		while (read_nr_out(hierarchy) > 0):
+			current_state = list_pop(hierarchy, 0)
+			transitions = get_enabled_transitions(model, current_state, data, class)
+
+			if (read_nr_out(transitions) > 0):
+				// Found an enabled transition, so store that one
+				transition = random_choice(transitions)
+				
+				// Execute transition
+				set_merge(new_states, execute_transition(model, data, class, transition))
+
+				// When leaving an orthogonal component, we must also pop all related states that might be processed in the future!
+				Element leaving
+				leaving = expand_current_state(model, current_state, data["classes"][class]["states"])
+				set_difference(states, leaving)
+
+				transitioned = True
+				found = True
+				break!
 
-		// Fetch transitions in this state specifically (NO parent)
-		transitions = get_enabled_transitions(model, state, data, class)
-		if (read_nr_out(transitions) != 0):
-			// Found an enabled transition, so store that one
-			transition = random_choice(transitions)
-			
-			// Execute transition
-			set_merge(new_states, execute_transition(model, data, class, transition))
-			transitioned = True
-		else:
-			// Try going to the parent
-			// TODO
-
+		if (bool_not(found)):
 			// Nothing found, so stay in the current state
 			set_add(new_states, state)
 			
@@ -317,8 +328,8 @@ Void function reschedule_timeouts(model : Element, data : Element, class : Strin
 
 String function get_parent(model : Element, state : String):
 	Element tmp_set
-	tmp_set = allAssociationOrigins(model, state, "composite_children")
-	set_merge(tmp_set, allAssociationOrigins(model, state, "parallel_children"))
+	tmp_set = allAssociationOrigins(model, state, "SCCD/composite_children")
+	set_merge(tmp_set, allAssociationOrigins(model, state, "SCCD/parallel_children"))
 	if (read_nr_out(tmp_set) > 0):
 		return set_pop(tmp_set)!
 	else:
@@ -396,7 +407,6 @@ Element function get_actions_to_execute(model : Element, source_states : Element
 		if (bool_not(finished)):
 			i = i + 1
 
-	log("Found difference at i = " + cast_v2s(i))
 	// Found the first differing element at position i
 
 	// All elements remaining in hierarchy_source are to be traversed in REVERSE order for the exit actions