def plan_cost(universe, plan): if plan is None: return INF cost = universe.initial_cost for action, args in plan: instance = action.instantiate(args) increases = get_increases(instance.effect) # TODO - ensure that the last effect is used new_cost = 0 # 0 | INF if action.cost is not None: new_cost += action.cost for increase in increases: if increase.function == TotalCost(): if isinstance(increase.value, Atom): atom = increase.value if atom in universe.perm_functions: value = universe.evaluate_func(atom) elif atom in universe.temp_functions: value = universe.temp_functions[atom] else: raise ValueError(increase) else: value = increase.value new_cost += value #new_cost = min(new_cost, value) #new_cost = max(new_cost, value) #new_cost = value # TODO: several ways to handle repeated costs cost += new_cost return cost
def initial_pddl(self, costs): atoms = list(self.get_initial_atoms()) if costs: atoms.append(Initialize(TotalCost(), self.initial_cost)) return '(' + '\n\t'.join([':init'] + sorted([atom.pddl() for atom in atoms])) + ')'
def plan_cost(universe, plan): if plan is None: return INF cost = universe.initial_cost for action, args in plan: instance = action.instantiate(args) increases = get_increases(instance.effect) new_cost = 0 if action.cost is not None: new_cost += action.cost for increase in increases: if increase.function == TotalCost(): if isinstance(increase.value, Atom): if increase.value in universe.perm_functions: value = universe.perm_functions[increase.value] elif increase.value in universe.temp_functions: value = universe.temp_functions[increase.value] else: raise ValueError(increase) else: value = increase.value new_cost += value cost += new_cost return cost
def Cost(cost): # This is a shortcut """ Increase cost atom (increase total-cost F) which extends :class:`.Function` by setting ``function`` to be :class:`.TotalCost()`. :param cost: the numeric or :class:`.Function` amount that :class:`.TotalCost()` increases """ return Increase(TotalCost(), cost)
def problem_pddl(self, costs): s = '(define (problem %s)\n' % self.problem_name s += '(:domain %s)\n' % self.domain_name #s += '(:objects' + self.constants_pddl() + ')\n' # NOTE - don't need this s += self.initial_pddl(costs) + '\n' s += self.goal_pddl() + '\n' if costs: s += '(:metric minimize %s)' % TotalCost().pddl() return s + ')\n'
def problem_pddl(self, costs): s = '(define (problem %s)\n' % self.problem_name s += '(:domain %s)\n' % self.domain_name s += self.initial_pddl(costs) + '\n' s += self.goal_pddl() + '\n' if costs: s += '(:metric minimize %s)' % TotalCost().pddl() return s + ')\n'
def __init__(self, cost): """ :param cost: the numeric or :class:`.Function` amount that :class:`.TotalCost()` increases """ super(Cost, self).__init__(TotalCost(), cost)
def initial_pddl(self, costs): atoms = list(self.get_initial_atoms()) #atoms = list(apply_axioms(set(atoms), self.type_to_objects, instantiate_axioms(self))) if costs: atoms.append(Initialize(TotalCost(), self.initial_cost)) return '(' + '\n\t'.join([':init'] + sorted([atom.pddl() for atom in atoms])) + ')'