Example #1
0
 def _try_btsmooth_refine(self):
     bt = self._try_backtracking_refine()
     while True:
         fluent = next(bt)
         if fluent is None:
             break
         yield fluent
     llprob = LLProb(self.action_list)
     llprob.solve_at_priority(0, fix_sampled_params=True)
     llprob.solve_at_priority(2)
     fluents = [f for a in self.action_list for f in a.preconditions + a.postconditions]
     violated_fluents = self.find_violated_fluents(fluents, priority=2)
     assert len(violated_fluents) == 0
     self.total_cost = llprob.traj_cost
     yield None
Example #2
0
    def _try_joint_refine(self):
        sampled_params = self.world.get_sampled_params()
        sampled_params.sort(key=lambda p: p.sample_priority)
        recently_sampled = sampled_params
        for param in sampled_params:
            param.resample()

        llprob = LLProb(self.action_list)
        llprob.solve_at_priority(-1, recently_sampled=recently_sampled)
        all_useful_fluents = set()
        count = 0
        while True:
            count += 1
            llprob.solve_at_priority(0, recently_sampled=recently_sampled)
            for priority in JOINT_REF_PRIORITIES:
                llprob.solve_at_priority(priority)
                if llprob.recently_converged_vio_fluent is not None:
                    # early converged based on a violated fluent
                    violated_fluents = [llprob.recently_converged_vio_fluent]
                else:
                    fluents = [f for a in self.action_list for f in a.preconditions + a.postconditions]
                    violated_fluents = self.find_violated_fluents(fluents, priority)
                if len(violated_fluents) == 0:
                    if priority == JOINT_REF_PRIORITIES[-1]:
                        self.total_cost = llprob.traj_cost
                        yield None
                    continue
                else:
                    try:
                        self.save_useful_fluents(violated_fluents, all_useful_fluents)
                        recently_sampled = self.randomized_resample(sampled_params, violated_fluents, mode="fluent", count=count)
                    except StopIteration:
                        for f in all_useful_fluents:
                            self.remove_plots()
                            yield f
                        if len(all_useful_fluents) == 0:
                            print "Resampling all params, no violated fluents to raise..."
                            for p in sampled_params:
                                try:
                                    p.resample()
                                except StopIteration:
                                    p.reset_gen()
                                    p.resample()
                        # reset set of useful fluents, since we yielded them all
                        all_useful_fluents = set()
                        count = 0
                    break # out of for loop