|
@@ -73,40 +73,28 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
typename = read_type(schedule_model, current_element)
|
|
|
original_typename = string_substr(typename, 4, string_len(typename))
|
|
|
|
|
|
- log("Getting possible bindings for " + current_element)
|
|
|
- log(" type: " + typename)
|
|
|
-
|
|
|
if (is_edge(schedule_model["model"][current_element])):
|
|
|
- log(" is_edge")
|
|
|
// Is an edge, so check for already bound source/target
|
|
|
src_label = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_src(schedule_model["model"][current_element])), "label")
|
|
|
dst_label = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_dst(schedule_model["model"][current_element])), "label")
|
|
|
|
|
|
if (bool_and(set_in(dict_keys(map), src_label), set_in(dict_keys(map), dst_label))):
|
|
|
// Source and destination are bound
|
|
|
- log(" SD bound")
|
|
|
options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
|
|
|
- log(" Outgoing associations instances: " + set_to_string(options))
|
|
|
- log(" Incoming associations instances: " + set_to_string(allIncomingAssociationInstances(host_model, map[dst_label], original_typename)))
|
|
|
options = set_overlap(options, allIncomingAssociationInstances(host_model, map[dst_label], original_typename))
|
|
|
|
|
|
elif (set_in(dict_keys(map), src_label)):
|
|
|
// Source is bound
|
|
|
- log(" S bound")
|
|
|
options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
|
|
|
|
|
|
elif (set_in(dict_keys(map), dst_label)):
|
|
|
// Destination is bound
|
|
|
- log(" D bound")
|
|
|
options = allIncomingAssociationInstances(host_model, map[dst_label], original_typename)
|
|
|
|
|
|
else:
|
|
|
// Neither is bound, so just get all of them
|
|
|
- log("ERROR: unbound source/target for association!")
|
|
|
- //TODO should actually return all
|
|
|
- return create_node()!
|
|
|
+ return allInstances(host_model, original_typename)!
|
|
|
else:
|
|
|
- log(" is_node")
|
|
|
// Is a node, so find whether or not there are some connections that are already resolved
|
|
|
Element ic
|
|
|
Element oc
|
|
@@ -117,21 +105,18 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
|
|
|
while (bool_and(read_nr_out(ic) > 0, read_nr_out(options) == 0)):
|
|
|
poll = set_pop(ic)
|
|
|
- log(" poll I " + poll)
|
|
|
if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
|
|
|
// This incoming link is already defined, so we just have one option: the destination of the link we matched
|
|
|
set_add(options, readAssociationDestination(host_model, map[read_attribute(schedule_model, poll, "label")]))
|
|
|
|
|
|
while (bool_and(read_nr_out(oc) > 0, read_nr_out(options) == 0)):
|
|
|
poll = set_pop(oc)
|
|
|
- log(" poll O " + poll)
|
|
|
if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
|
|
|
// This incoming link is already defined, so we just have one option: the destination of the link we matched
|
|
|
set_add(options, readAssociationSource(host_model, map[read_attribute(schedule_model, poll, "label")]))
|
|
|
|
|
|
if (read_nr_out(options) == 0):
|
|
|
// Is a node and no connections, so we just pick all options
|
|
|
- log(" empty")
|
|
|
options = allInstances(host_model, original_typename)
|
|
|
elif (read_nr_out(options) > 1):
|
|
|
// Multiple "only" options, which will not work out: no options!
|
|
@@ -142,8 +127,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
Element filtered_options
|
|
|
String option
|
|
|
|
|
|
- log(" Got options: " + set_to_string(options))
|
|
|
-
|
|
|
filtered_options = create_node()
|
|
|
while (read_nr_out(options) > 0):
|
|
|
option = set_pop(options)
|
|
@@ -166,9 +149,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
func = get_func_AL_model(constraint_function)
|
|
|
result = func(host_model, option)
|
|
|
|
|
|
- log("Execute constraint on " + dict_to_string(option))
|
|
|
- log("Result: " + cast_e2s(result))
|
|
|
-
|
|
|
if (result):
|
|
|
set_add(filtered_options, option)
|
|
|
|
|
@@ -181,16 +161,13 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
|
|
|
options = filtered_options
|
|
|
filtered_options = create_node()
|
|
|
- log("Checking options: " + set_to_string(options))
|
|
|
|
|
|
// Check whether all attributes have a satisfied condition
|
|
|
attributes_copy = dict_keys(getAttributeList(schedule_model, current_element))
|
|
|
- log("Defined attributes: " + set_to_string(attributes_copy))
|
|
|
|
|
|
while (read_nr_out(options) > 0):
|
|
|
option = set_pop(options)
|
|
|
attributes = set_copy(attributes_copy)
|
|
|
- log(" opt: " + option)
|
|
|
|
|
|
result = True
|
|
|
while (read_nr_out(attributes) > 0):
|
|
@@ -198,20 +175,12 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
if (bool_not(string_startswith(attribute, "constraint_"))):
|
|
|
continue!
|
|
|
|
|
|
- log("Check attribute: " + attribute)
|
|
|
value = read_attribute(schedule_model, current_element, attribute)
|
|
|
// Attribute might be undefined, so skip if it is
|
|
|
if (element_neq(value, read_root())):
|
|
|
- log("Read value: " + cast_e2s(value))
|
|
|
func = get_func_AL_model(value)
|
|
|
- log("Func: " + cast_e2s(func))
|
|
|
- log("EXEC")
|
|
|
- log("Read attribute with name: " + string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1))
|
|
|
- log("Value: " + cast_e2s(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1))))
|
|
|
result = func(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1)))
|
|
|
- log("Got result of constraint eval: " + cast_v2s(result))
|
|
|
else:
|
|
|
- log("Attribute unconstrained, so add always")
|
|
|
result = True
|
|
|
|
|
|
if (bool_not(result)):
|
|
@@ -219,10 +188,7 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
|
|
|
|
|
|
// Check value of last result, which will be True if all passed, or False otherwise
|
|
|
if (result):
|
|
|
- log("Adding")
|
|
|
set_add(filtered_options, option)
|
|
|
- else:
|
|
|
- log("Dropping")
|
|
|
|
|
|
options = filtered_options
|
|
|
return options!
|
|
@@ -313,9 +279,6 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
|
|
|
func = get_func_AL_model(constraint)
|
|
|
result = func(host_model, map)
|
|
|
|
|
|
- log("Execute global constraint on " + dict_to_string(map))
|
|
|
- log("Result: " + cast_e2s(result))
|
|
|
-
|
|
|
if (result):
|
|
|
set_add(new_mappings, map)
|
|
|
mappings = new_mappings
|
|
@@ -408,25 +371,17 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
|
|
|
if (bool_not(string_startswith(attribute, "value_"))):
|
|
|
continue!
|
|
|
|
|
|
- log("Execute attribute " + attribute)
|
|
|
value = read_attribute(schedule_model, RHS_map[label], attribute)
|
|
|
if (element_neq(value, read_root())):
|
|
|
func = get_func_AL_model(value)
|
|
|
- log("Func: " + cast_e2s(func))
|
|
|
- log("EXEC")
|
|
|
result = func(host_model, new_mapping[label], mapping)
|
|
|
- log("Got result of constraint eval: " + cast_v2s(result))
|
|
|
|
|
|
if (has_value(result)):
|
|
|
// New value defined, so assign!
|
|
|
instantiate_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1), result)
|
|
|
- log("Created new value for attribute!")
|
|
|
else:
|
|
|
// Non-value return means to destroy the attribute!
|
|
|
unset_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1))
|
|
|
- log("Deleted attribute!")
|
|
|
- else:
|
|
|
- log("Attribute undefined, so leave it be!")
|
|
|
|
|
|
// Do the global action of each element
|
|
|
action = read_attribute(schedule_model, RHS_map[label], "action")
|
|
@@ -486,7 +441,6 @@ Boolean function transform_composite(host_model : Element, schedule_model : Elem
|
|
|
while (is_nominal_instance(schedule_model, current, "Rule")):
|
|
|
// Still a rule that we must execute
|
|
|
typename = read_type(schedule_model, current)
|
|
|
- log("RULE: " + current)
|
|
|
if (typename == "Atomic"):
|
|
|
result = transform_atomic(host_model, schedule_model, current)
|
|
|
elif (typename == "Query"):
|
|
@@ -540,7 +494,6 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
|
|
|
while (read_nr_out(mappings) > 0):
|
|
|
mapping = set_pop(mappings)
|
|
|
// TODO check if there are actually no deletions happening in the meantime of other matched elements...
|
|
|
- log("Execute RHS for binding: " + dict_to_string(mapping))
|
|
|
RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))
|
|
|
rewrite(host_model, schedule_model, RHS, mapping)
|
|
|
|