planning with uncertainty self opt_policy[frozenset(context items())(var,thevalreturn maxres elsetotal for val in var domaintotal +self rc (dict_union({var:val},context)factorssplit_order[ :]self display( "rc branching on"var,"returning"totalreturn total we can combine the optimization for decision networks abovewith the improvements of recursive conditioning used for graphical models (section page decnnetworks py -(continued def rc(selfcontextfactorssplit_order)""returns the number \sum_{split_order\prod_{factorsgiven assignments in context context is variable:value dictionary factors is set of factors split_order is list of variables in factors that are not in context ""self display( ,"calling rc,",(context,factors)ce (frozenset(context items())frozenset(factors)key for the cache entry if ce in self cacheself display( ,"rc cache lookup",(context,factors)return self cache[ceif not factorsno factorsneeded if you don' have forgetting and caching return elif vars_not_in_factors :{var for var in context if not any(var in fac variables for fac in factors)}forget variables not in any factor self display( ,"rc forgetting variables"vars_not_in_factorsreturn self rc({key:val for (key,valin context items(if key not in vars_not_in_factors}factorssplit_orderelif to_eval :{fac for fac in factors if fac can_evaluate(context)}evaluate factors when all variables are assigned self display( ,"rc evaluating factors",to_evalval math prod(fac get_value(contextfor fac in to_evalif val = return elsereturn val self rc(context{fac for fac in factors if fac not in to_eval}split_orderversion june