def _create_problem_file(self, raw_problem_fname, use_cache=True): if (not use_cache) or (raw_problem_fname not in self._problem_files): problem_fname = os.path.split(raw_problem_fname)[-1] problem_fname = problem_fname.split('.pddl')[0] problem_fname += '_{}_with_diffs_{}.pddl'.format( self.domain_name, random.randint(0, 9999999)) problem_fname = os.path.join('/tmp', problem_fname) # Parse raw problem problem_parser = PDDLProblemParser(raw_problem_fname, self.domain_name.lower(), self._types, self._predicates, self._actions) new_initial_state = set(problem_parser.initial_state) # Add actions action_lits = set( self._action_space.all_ground_literals(State( new_initial_state, problem_parser.objects, problem_parser.goal), valid_only=False)) new_initial_state |= action_lits # Add 'Different' pairs for each pair of objects Different = Predicate('Different', 2) for obj1 in problem_parser.objects: for obj2 in problem_parser.objects: if obj1 == obj2: continue # if obj1.var_type != obj2.var_type: # continue diff_lit = Different(obj1, obj2) new_initial_state.add(diff_lit) # Write out new temporary problem file problem_parser.initial_state = frozenset(new_initial_state) problem_parser.write(problem_fname) # Add to cache self._problem_files[raw_problem_fname] = problem_fname return self._problem_files[raw_problem_fname]
def _create_problem_file(self, raw_problem_fname, use_cache=True): if (not use_cache) or (raw_problem_fname not in self._problem_files): problem_fname = os.path.split(raw_problem_fname)[-1] problem_fname = problem_fname.split('.pddl')[0] problem_fname += '_{}_with_diffs_{}.pddl'.format( self.domain_name, random.randint(0, 9999999)) problem_fname = os.path.join('/tmp', problem_fname) # Parse raw problem action_names = [ ] # purposely empty b/c we WANT action literals in there problem_parser = PDDLProblemParser(raw_problem_fname, self.domain_name.lower(), self._types, self._predicates, action_names) # Add action literals (in case they're not already present in the initial state) # which will be true when the original domain uses operators_as_actions init_state = State(problem_parser.initial_state, problem_parser.objects, None) act_lits = self._action_space.all_ground_literals(init_state, valid_only=False) problem_parser.initial_state = frozenset( act_lits | problem_parser.initial_state) # Add 'Different' pairs for each pair of objects Different = Predicate('Different', 2) init_state = set(problem_parser.initial_state) for obj1 in problem_parser.objects: for obj2 in problem_parser.objects: if obj1 == obj2: continue # if obj1.var_type != obj2.var_type: # continue diff_lit = Different(obj1, obj2) init_state.add(diff_lit) problem_parser.initial_state = frozenset(init_state) # Also add 'different' pairs for goal if it's existential if isinstance(problem_parser.goal, Exists): diffs = [] for var1 in problem_parser.goal.variables: for var2 in problem_parser.goal.variables: if var1 == var2: continue diffs.append(Different(var1, var2)) problem_parser.goal = Exists( problem_parser.goal.variables, type(problem_parser.goal.body)( problem_parser.goal.body.literals + diffs)) # If no objects, write a dummy one to make FF not crash. if not problem_parser.objects: problem_parser.objects.append("DUMMY") # Write out new temporary problem file problem_parser.write(problem_fname) # Add to cache self._problem_files[raw_problem_fname] = (problem_fname, problem_parser.objects) return self._problem_files[raw_problem_fname]