def make_fact_repr_loc(fact): location = fact.location.value return { 'prior': fact.priority, 'sym_id': fact.sym_id, 'values': [term.value for term in fact.terms], 'rank': loc_rank(location), 'proc_id': loc_proc_id(location) }
def exec_rhs(): log_info(logger, "Applying rule %s" % rule_id) # sys.stdout.write("Local: ") # for goal in local_goals: # sys.stdout.write("%s, " % goal) # sys.stdout.write("\nExternal: ") # for goal in external_goals: # sys.stdout.write("%s, " % goal) # sys.stdout.write("\n\n") # add_goals(goals, local_goals) (local_goals,external_goals) = partition_goals_by_proc_id(rhs(), loc_proc_id(location.value)) spawn_new_locs() log_info(logger, "Sending internal goals: %s" % map(make_fact_repr_loc,local_goals) ) log_info(logger, "Sending external goals: %s" % map(make_fact_repr_loc,external_goals) ) goals.push_many( map(make_fact_repr,local_goals) ) send_goal_func( map(make_fact_repr_loc,external_goals) )
def partition_goals_by_proc_id(goals, proc_id): filtered = filter(lambda goal: loc_proc_id(goal.location.value) == proc_id ,goals) rest = filter(lambda goal: loc_proc_id(goal.location.value) != proc_id ,goals) return (filtered,rest)
def filter_goals_by_proc_id(goals, proc_id): return filter(lambda goal: loc_proc_id(goal.location.value) == proc_id ,goals)
def spawn_new_locs(): new_locations = exist_locs_func() log_info(logger, "Creating new %s locations: %s" % (len(new_locations),new_locations)) for location in new_locations: proc_id = loc_proc_id( location ) create_new_location_func( proc_id )
def make_fact_repr_loc(fact): location = fact.location.value return { 'prior':fact.priority, 'sym_id':fact.sym_id, 'values':[ term.value for term in fact.terms ] , 'rank':loc_rank(location), 'proc_id':loc_proc_id(location) }