return utilr node_fr.assign_func(failure_risk) # create new network dbnet = Network("Soliman2014InfDiag") # add nodes to network dbnet.add_nodes([node_m, node_k] + aarray + marray + insparray + uiarray + rarray + urarray + [node_fr]) # add link: must be prior to defining nodes dbnet.add_link() # define nodes dbnet.define_nodes() # compile the net dbnet.compile_net() # enable autoupdate dbnet.set_autoupdate() # save the network dbnet.save_net("Soliman2014InfDiag.dne") #type 2 dbnet.retract_netfindings() dummy = dbnet.get_node_expectedutils(node_insp) dummy = dbnet.get_node_expectedutils(node_repair) decision = dbnet.get_node_funcstate(node_repair, [2, 4]) print 'If the inspection decision is {} and meausre is {}, the best repair decision is {}.\n'.format( node_insp.statenames[2], marray[0].statenames[4], node_repair.statenames[decision])
return utilr node_fr.assign_func(failure_risk) # create new network dbnet = Network("Soliman2014InfDiag") # add nodes to network dbnet.add_nodes([node_m, node_k]+aarray+marray+insparray+uiarray+rarray+urarray+[node_fr]) # add link: must be prior to defining nodes dbnet.add_link() # define nodes dbnet.define_nodes() # compile the net dbnet.compile_net() # enable autoupdate dbnet.set_autoupdate() # save the network dbnet.save_net("Soliman2014InfDiag.dne") #type 2 dbnet.retract_netfindings() dummy = dbnet.get_node_expectedutils(node_insp) dummy = dbnet.get_node_expectedutils(node_repair) decision = dbnet.get_node_funcstate(node_repair, [2,4]) print 'If the inspection decision is {} and meausre is {}, the best repair decision is {}.\n'.format( node_insp.statenames[2], marray[0].statenames[4], node_repair.statenames[decision])
# decision making # type 1 dbnet.enter_finding(forecast, 0) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is sunny, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) dbnet.retract_netfindings() dbnet.enter_finding(forecast, 1) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is cloudy, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) dbnet.retract_netfindings() dbnet.enter_finding(forecast, 2) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is rainy, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) #type 2 dbnet.retract_netfindings() dummy = dbnet.get_node_expectedutils(umbrella) for fs in range(forecast.nstates()): decision = dbnet.get_node_funcstate(umbrella, [fs]) print 'If the forecast is {}, the best decision is {}.\n'.format( forecast.statenames[fs], umbrella.statenames[decision])
dbnet.set_autoupdate() # save the network dbnet.save_net("BNdecision.dne") # decision making # type 1 dbnet.enter_finding(forecast, 0) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is sunny, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) dbnet.retract_netfindings() dbnet.enter_finding(forecast, 1) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is cloudy, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) dbnet.retract_netfindings() dbnet.enter_finding(forecast, 2) utils = dbnet.get_node_expectedutils(umbrella) print 'If the forecast is rainy, expected utility of {} is {}, of {} is {}\n'.format( umbrella.statenames[0], utils[0], umbrella.statenames[1], utils[1]) #type 2 dbnet.retract_netfindings() dummy = dbnet.get_node_expectedutils(umbrella) for fs in range(forecast.nstates()): decision = dbnet.get_node_funcstate(umbrella, [fs]) print 'If the forecast is {}, the best decision is {}.\n'.format( forecast.statenames[fs], umbrella.statenames[decision])