|
@@ -3,6 +3,7 @@ include "modelling.alh"
|
|
include "object_operations.alh"
|
|
include "object_operations.alh"
|
|
include "utils.alh"
|
|
include "utils.alh"
|
|
include "random.alh"
|
|
include "random.alh"
|
|
|
|
+include "library.alh"
|
|
|
|
|
|
Void function print_states(model : Element, data : Element):
|
|
Void function print_states(model : Element, data : Element):
|
|
Element classes
|
|
Element classes
|
|
@@ -15,11 +16,13 @@ Void function print_states(model : Element, data : Element):
|
|
while (read_nr_out(classes) > 0):
|
|
while (read_nr_out(classes) > 0):
|
|
class = set_pop(classes)
|
|
class = set_pop(classes)
|
|
log(string_join(string_join(string_join(" ", class["ID"]), " : "), read_attribute(model, class["type"], "name")))
|
|
log(string_join(string_join(string_join(" ", class["ID"]), " : "), read_attribute(model, class["type"], "name")))
|
|
|
|
+ log(" Attributes: " + dict_to_string(class["attributes"]))
|
|
|
|
|
|
states = set_copy(class["states"])
|
|
states = set_copy(class["states"])
|
|
|
|
+ log(" States:")
|
|
while (read_nr_out(states) > 0):
|
|
while (read_nr_out(states) > 0):
|
|
state = set_pop(states)
|
|
state = set_pop(states)
|
|
- log(string_join(" ", read_attribute(model, state, "name")))
|
|
|
|
|
|
+ log(string_join(" ", read_attribute(model, state, "name")))
|
|
|
|
|
|
return!
|
|
return!
|
|
|
|
|
|
@@ -97,14 +100,14 @@ Void function start_class(model : Element, data : Element, class : String):
|
|
Element attrs
|
|
Element attrs
|
|
attrs = allAssociationDestinations(model, class, "SCCD/class_attributes")
|
|
attrs = allAssociationDestinations(model, class, "SCCD/class_attributes")
|
|
while (read_nr_out(attrs) > 0):
|
|
while (read_nr_out(attrs) > 0):
|
|
- dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), create_node())
|
|
|
|
|
|
+ dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), read_root())
|
|
dict_add(class_handle, "attributes", attributes)
|
|
dict_add(class_handle, "attributes", attributes)
|
|
|
|
|
|
- set_add(data["classes"], class_handle)
|
|
|
|
|
|
+ dict_add(data["classes"], class_handle["ID"], class_handle)
|
|
|
|
|
|
return!
|
|
return!
|
|
|
|
|
|
-Element function get_enabled_transitions(model : Element, state : String, interrupt : Element):
|
|
|
|
|
|
+Element function get_enabled_transitions(model : Element, state : String, data : Element, class : String):
|
|
// Returns all enabled transitions
|
|
// Returns all enabled transitions
|
|
// TODO ignore conditions and afters
|
|
// TODO ignore conditions and afters
|
|
Element result
|
|
Element result
|
|
@@ -119,30 +122,39 @@ Element function get_enabled_transitions(model : Element, state : String, interr
|
|
while (read_nr_out(to_filter) > 0):
|
|
while (read_nr_out(to_filter) > 0):
|
|
transition = set_pop(to_filter)
|
|
transition = set_pop(to_filter)
|
|
attr = read_attribute(model, transition, "event")
|
|
attr = read_attribute(model, transition, "event")
|
|
- if (bool_or(element_eq(attr, read_root()), value_eq(attr, interrupt))):
|
|
|
|
|
|
+ log("Check attr in event list: " + set_to_string(data["events"]))
|
|
|
|
+ if (bool_or(element_eq(attr, read_root()), set_in(data["events"], attr))):
|
|
// Event is OK
|
|
// Event is OK
|
|
cond = read_attribute(model, transition, "cond")
|
|
cond = read_attribute(model, transition, "cond")
|
|
- log("Resolved condition")
|
|
|
|
if (element_neq(cond, read_root())):
|
|
if (element_neq(cond, read_root())):
|
|
- log("Result = " + cast_e2s(cond))
|
|
|
|
- cond = get_func_AL_model(cond)
|
|
|
|
- log("Resolved = " + cast_e2s(cond))
|
|
|
|
|
|
+ cond = get_func_AL_model(import_node(cond))
|
|
// Execute condition
|
|
// Execute condition
|
|
- if (bool_not(cond(create_node()))):
|
|
|
|
- log("Evaluated to True")
|
|
|
|
|
|
+ if (bool_not(cond(data["classes"][class]["attributes"]))):
|
|
// Condition false, so skip
|
|
// Condition false, so skip
|
|
continue!
|
|
continue!
|
|
- else:
|
|
|
|
- log("Evaluated to False")
|
|
|
|
- else:
|
|
|
|
- log("NO condition")
|
|
|
|
- // Condition is OK
|
|
|
|
|
|
|
|
|
|
+ // Condition is OK
|
|
set_add(result, transition)
|
|
set_add(result, transition)
|
|
|
|
|
|
return result!
|
|
return result!
|
|
|
|
|
|
-Float function step_class(model : Element, data : Element, class : Element, interrupt : Element):
|
|
|
|
|
|
+Element function execute_transition(model : Element, data : Element, class : String, transition : String):
|
|
|
|
+ // Execute the script (if any)
|
|
|
|
+ Element script
|
|
|
|
+ script = read_attribute(model, transition, "script")
|
|
|
|
+ if (element_neq(script, read_root())):
|
|
|
|
+ script = get_func_AL_model(import_node(script))
|
|
|
|
+ log("Calling script with attributes: " + dict_to_string(data["classes"][class]["attributes"]))
|
|
|
|
+ script(data["classes"][class]["attributes"])
|
|
|
|
+ log("Called script with attributes: " + dict_to_string(data["classes"][class]["attributes"]))
|
|
|
|
+
|
|
|
|
+ // Raise events
|
|
|
|
+ // TODO
|
|
|
|
+
|
|
|
|
+ // Return new set of states
|
|
|
|
+ return expand_state(model, readAssociationDestination(model, transition))!
|
|
|
|
+
|
|
|
|
+Float function step_class(model : Element, data : Element, class : String):
|
|
// Find enabled transitions in a class and execute it, updating the state
|
|
// Find enabled transitions in a class and execute it, updating the state
|
|
// Iterate over all current states, searching for enabled transitions
|
|
// Iterate over all current states, searching for enabled transitions
|
|
// Search for enabled transitions in higher levels as well!
|
|
// Search for enabled transitions in higher levels as well!
|
|
@@ -154,18 +166,21 @@ Float function step_class(model : Element, data : Element, class : Element, inte
|
|
Float t_min
|
|
Float t_min
|
|
Float t_current
|
|
Float t_current
|
|
|
|
|
|
- states = set_copy(class["states"])
|
|
|
|
|
|
+ log("Step class " + class)
|
|
|
|
+ states = set_copy(data["classes"][class]["states"])
|
|
new_states = create_node()
|
|
new_states = create_node()
|
|
|
|
|
|
while (read_nr_out(states) > 0):
|
|
while (read_nr_out(states) > 0):
|
|
state = set_pop(states)
|
|
state = set_pop(states)
|
|
|
|
|
|
// Fetch transitions in this state specifically (NO parent)
|
|
// Fetch transitions in this state specifically (NO parent)
|
|
- transitions = get_enabled_transitions(model, state, interrupt)
|
|
|
|
|
|
+ transitions = get_enabled_transitions(model, state, data, class)
|
|
if (read_nr_out(transitions) != 0):
|
|
if (read_nr_out(transitions) != 0):
|
|
// Found an enabled transition, so store that one
|
|
// Found an enabled transition, so store that one
|
|
transition = random_choice(transitions)
|
|
transition = random_choice(transitions)
|
|
- set_merge(new_states, expand_state(model, readAssociationDestination(model, transition)))
|
|
|
|
|
|
+
|
|
|
|
+ // Execute transition
|
|
|
|
+ set_merge(new_states, execute_transition(model, data, class, transition))
|
|
else:
|
|
else:
|
|
// Try going to the parent
|
|
// Try going to the parent
|
|
// TODO
|
|
// TODO
|
|
@@ -174,23 +189,24 @@ Float function step_class(model : Element, data : Element, class : Element, inte
|
|
set_add(new_states, state)
|
|
set_add(new_states, state)
|
|
|
|
|
|
// Update states
|
|
// Update states
|
|
- dict_overwrite(class, "states", new_states)
|
|
|
|
|
|
+ dict_overwrite(data["classes"][class], "states", new_states)
|
|
|
|
|
|
return 1.0!
|
|
return 1.0!
|
|
|
|
|
|
-Float function step(model : Element, data : Element, interrupt : Element):
|
|
|
|
|
|
+Float function step(model : Element, data : Element):
|
|
// Step through all classes
|
|
// Step through all classes
|
|
Element classes
|
|
Element classes
|
|
Element class
|
|
Element class
|
|
Float t_min
|
|
Float t_min
|
|
Float t_class
|
|
Float t_class
|
|
|
|
|
|
- t_min = 99999.0
|
|
|
|
- classes = set_copy(data["classes"])
|
|
|
|
|
|
+ t_min = 1.0
|
|
|
|
+ classes = dict_keys(data["classes"])
|
|
|
|
+ log("Got classes: " + set_to_string(classes))
|
|
|
|
|
|
while (read_nr_out(classes) > 0):
|
|
while (read_nr_out(classes) > 0):
|
|
class = set_pop(classes)
|
|
class = set_pop(classes)
|
|
- t_class = step_class(model, data, class, interrupt)
|
|
|
|
|
|
+ t_class = step_class(model, data, class)
|
|
if (t_class < t_min):
|
|
if (t_class < t_min):
|
|
t_min = t_class
|
|
t_min = t_class
|
|
|
|
|
|
@@ -223,12 +239,14 @@ Boolean function main(model : Element):
|
|
// Stop execution
|
|
// Stop execution
|
|
return True!
|
|
return True!
|
|
|
|
|
|
|
|
+ dict_overwrite(data, "events", create_node())
|
|
if (element_neq(interrupt, read_root())):
|
|
if (element_neq(interrupt, read_root())):
|
|
// Got interrupt
|
|
// Got interrupt
|
|
log("Got event: " + cast_v2s(interrupt))
|
|
log("Got event: " + cast_v2s(interrupt))
|
|
|
|
+ set_add(data["events"], interrupt)
|
|
output("Processed event, ready for more!")
|
|
output("Processed event, ready for more!")
|
|
|
|
|
|
- timeout = step(model, data, interrupt)
|
|
|
|
|
|
+ timeout = step(model, data)
|
|
|
|
|
|
// We should never get here!
|
|
// We should never get here!
|
|
return False!
|
|
return False!
|