# This implements SDD dependencies
subroutine(sddvalue_as_string(node val), ());
#
# clear_value_cache()
#
# Purpose: This clears the cache of a value, so it will need to be recomputed on next use.
#
# Parameters val: the value show cache to clear
#
subroutine(clear_value_cache(node val), (
if (val?{"cached_value"}) then (
delete_node(val{"cached_value"});
);
)); # clear_value_cache()
#
# announce_sdd_parameter_change()
#
# Purpose: This announces the change of a parameter of an SDD. It causes all dependends' cached values to be cleared,
# so they will be recomputed when next needed.
#
subroutine(announce_sdd_parameter_change(node providersdd, string providervalname), (
# echo("announce_sdd_parameter_change; providersd=" . providersdd . "; providervalname=" . providervalname);
# If there are any dependencies of this SDD...
node parameter = providersdd{providervalname};
if (parameter?{"dependencies"}) then (
node dependencies = parameter{"dependencies"};
# ...then remove them from cache
node dependency;
foreach dependency (dependencies) (
node dependentsdd = @dependency{"dependentsdd"};
string dependentvalname = @dependency{"dependentvalname"};
node val = @dependentsdd{dependentvalname};
# Clear the cache for this value (forcing it to be recomputed next time it's used)
#echo("val: " . val);
#echo("val: " . node_as_string(val));
# if (val ne "NULL") then
if (val ne "NULL") then (
clear_value_cache(val);
#echo("Cleared value cache for val=" . sddvalue_as_string(val));
# If this is an "add" operation, follow it down to its parameters, in case those need to be recomputed also
# This is a narrow implementation; it probably needs to follow all examples like this; but for now I'm just
# trying to get to work in
. - GMF 2011-03-29
# Look for subnodes which appear to be sdd values, and clear their caches. Without this, if we have an sddadd which
# is the xmin of a dependent SDD, it may have a cached value even though its subvalues have changed; we need to clear
# the caches of all subvalues when clearing the SDD's cache in this case.
#if (false) then (
node subval;
#echo("val: " . node_as_string(val));
#echo("START");
foreach subval val (
# echo("subval: " . subval);
#echo("subval: " . node_as_string(subval));
#echo("@subval: " . node_as_string(@subval));
# echo("subval type: " . @(@subval){"type"});
#echo("node_type: " . node_type(subval));
#echo("?subval: " . node_exists(subval));
if (node_type(subval) eq "node") then (
#echo("subval: " . node_as_string(@subval));
#echo("subval{type}: " . @(@subval){"type"});
if ((@subval)?{"type"}) then (
clear_value_cache(@subval);
#echo("subval: " . node_as_string(@subval));
);
);
);
#echo("DONE");
#);
#if (@val{"type"} eq "add") then (
##echo("ADD");
# node value1 = @val{"value1"};
# node value2 = @val{"value2"};
#clear_value_cache(value1);
#clear_value_cache(value2);
#);
); # if val
# Propagate changes to any dependents of the dependent value
announce_sdd_parameter_change(dependentsdd, dependentvalname);
); # foreach dependency
); # if dependencies
)); # announce_sdd_parameter_change()
#
# register_sdd_dependency()
#
# Purpose: This registers a dependency of a value in one SDD on a value in another SDD
#
# Parameters: dependentsdd: the SDD whose value is dependent
# dependentvalname: the name of the dependent value
# providersdd: the SDD who provides the value to the dependent
# providervalname: the name of the value which provides to dependent
#
subroutine(register_sdd_dependency(node dependentsdd, string dependentvalname, node providersdd, string providervalname), (
string dependencyname = (dependentsdd + 0) . "_" . dependentvalname;
# Remember in the dependent SDD, that this value depends on the provider value
set_node_type(providersdd{providervalname}{"dependencies"}{dependencyname}{"dependentsdd"}, "node");
@providersdd{providervalname}{"dependencies"}{dependencyname}{"dependentsdd"} = dependentsdd;
@providersdd{providervalname}{"dependencies"}{dependencyname}{"dependentvalname"} = dependentvalname;
)); # register_dependency_value_on_sdd_parameter()
|