def translate_strips_operator(operator, dictionary, mod_effects_dict, ranges, comp_axioms): # NOTE: This function does not really deal with the intricacies of properly # encoding delete effects for grouped propositions in the presence of # conditional effects. It should work ok but will bail out in more # complicated cases even though a conflict does not necessarily exist. assert False, "Actions not supported, use durative actions" condition = translate_strips_conditions(operator.condition, dictionary, ranges, comp_axioms) if condition is None: return None effect, possible_add_conflict, mod_eff = translate_add_effects( operator.add_effects, dictionary, mod_effects_dict, ranges, comp_axioms, False) translate_del_effects(operator.del_effects, dictionary, ranges, effect, condition, comp_axioms, False, None) if possible_add_conflict: print operator.name assert not possible_add_conflict, "Conflicting add effects?" assign_effect, possible_assign_conflict = \ translate_assignment_effects(operator.assign_effects, dictionary, ranges, comp_axioms, False) if possible_assign_conflict: print operator.name assert not possible_assign_conflict, "Conflicting assign effects?" pre_post = [] for var in effect: for (post, eff_condition_lists) in effect[var].iteritems(): pre = condition.get(var, -1) if pre != -1: del condition[var] for eff_condition in eff_condition_lists: pre_post.append((var, pre, post, eff_condition)) prevail = condition.items() assign_effects = [] for var in assign_effect: for ((op, valvar), eff_condition_lists) in assign_effect[var].iteritems(): for eff_condition in eff_condition_lists: sas_effect = sas_tasks.SASAssignmentEffect( var, op, valvar, eff_condition) assign_effects.append(sas_effect) return sas_tasks.SASOperator(operator.name, prevail, pre_post, assign_effects)
def translate_temporal_strips_operator_aux(operator, dictionary, ranges, comp_axioms, condition, true_atoms, false_atoms): # NOTE: This function does not really deal with the intricacies of properly # encoding delete effects for grouped propositions in the presence of # conditional effects. It should work ok but will bail out in more # complicated cases even though a conflict does not necessarily exist. duration = translate_operator_duration(operator.duration, dictionary) if condition is None: print "operator condition is None (invalid)" return None effect = [] possible_add_conflict = False for time in range(2): eff, poss_conflict = translate_add_effects(operator.add_effects[time], dictionary, ranges, comp_axioms, True, true_atoms, false_atoms) translate_del_effects(operator.del_effects[time], dictionary, ranges, eff, condition, comp_axioms, True, time, true_atoms, false_atoms) effect.append(eff) possible_add_conflict |= poss_conflict if possible_add_conflict: print operator.name assert not possible_add_conflict assign_effect = [] possible_assign_conflict = False for time in range(2): eff, conflict = translate_assignment_effects( operator.assign_effects[time], dictionary, ranges, comp_axioms, True, true_atoms, false_atoms) assign_effect.append(eff) possible_assign_conflict |= conflict if possible_assign_conflict: print operator.name assert not possible_assign_conflict pre_post = [[], []] for time in range(2): cond_time = time * 2 # start -> start condition, end -> end_condition for var in effect[time]: for (post, eff_condition_lists) in effect[time][var].iteritems(): pre = condition[cond_time].get(var, -1) if pre != -1: del condition[cond_time][var] # substitute normal effect for conditional effects if it has only # one at-start condition on a binary variable which is equivalent # to the effect variable # example: temporal effect 1 6 0 0 0 6 -1 1 # becomes 0 0 0 6 0 1 # NOTE: this changes the applicability of the action, because we # introduce a "write operation" on the variable in the case, where # the original conditional effect does not trigger (hence not # affecting the variable) if len(eff_condition_lists) == 1: # only one conditon eff_condition = eff_condition_lists[0] if (eff_condition[1] == [] and eff_condition[2] == [] and len(eff_condition[0]) == 1): ecvar, ecval = eff_condition[0][0] if ecvar == var and ranges[var] == 2: eff_condition[0] = [] for eff_condition in eff_condition_lists: pre_post[time].append((var, pre, post, eff_condition)) prevail = [cond.items() for cond in condition] assign_effects = [[], []] for time in range(2): for var in assign_effect[time]: for ((op, valvar), eff_condition_lists) \ in assign_effect[time][var].iteritems(): for eff_condition in eff_condition_lists: sas_effect = sas_tasks.SASAssignmentEffect( var, op, valvar, eff_condition, True) assign_effects[time].append(sas_effect) return sas_tasks.SASTemporalOperator(operator.name, duration, prevail, pre_post, assign_effects)