gm is graphical model to query "" def __init__(self,gm=none)self gm gm self cache {(frozenset()frozenset()): #self max_display_level def optimize(selfsplit_order=none)"""computes expected utilityand creates optimal decision functionswhere elim_order is list of the non-observed non-query variables in gm ""if split_order =nonesplit_order self gm split_order(self opt_policy {return self rc({}self gm factorssplit_orderthe following us the simplest search-based algorithm it is exponential in the number of variablesso is not very useful howeverit is simpleand useful to understand before looking at the more complicated algorithm note that the above code does not call rc you will need to change the self rc to self rc in above code to use it decnnetworks py -(continued def rc (selfcontextfactorssplit_order)"""simplest search algorithm""self display( ,"calling rc ,",(context,factors),"with so",split_orderif not factorsreturn elif to_eval :{fac for fac in factors if fac can_evaluate(context)}self display( ,"rc evaluating factors",to_evalval math prod(fac get_value(contextfor fac in to_evalreturn val self rc (contextfactors-to_evalsplit_orderelsevar split_order[ self display( "rc branching on"varif isinstance(var,decisionvariable)assert set(context<set(var parents) "cannot optimize {varin context {context}maxres -math inf for val in var domainself display( ,"in rc branching on",var,"=",valnewres self rc (dict_union({var:val},context)factorssplit_order[ :]if newres maxresmaxres newres theval val version june