Example #1
0
 def _process_binding(self, binding):
     assert binding.calls <= binding.visits # TODO: global DEBUG mode
     readd = is_new = False
     if binding.is_dominated():
         return readd, is_new
     if binding.is_fully_bound:
         action_plan = binding.skeleton.bind_action_plan(binding.mapping)
         self.store.add_plan(action_plan, binding.cost)
         is_new = True
         return readd, is_new
     binding.visits += 1
     instance = binding.result.instance
     if (REQUIRE_DOWNSTREAM and not binding.check_downstream()): # TODO: move check_complexity here
         # TODO: causes redundant plan skeletons to be identified (along with complexity using visits instead of calls)
         # Do I need to re-enable this stream in case another skeleton needs it?
         # TODO: should I perform this when deciding to sample something new instead?
         return STANDBY, is_new
     #if not is_instance_ready(self.evaluations, instance):
     #    raise RuntimeError(instance)
     if binding.up_to_date():
         new_results, _ = process_instance(self.store, self.domain, instance, disable=self.disable)
         is_new = bool(new_results)
     for new_binding in binding.update_bindings():
         self.push_binding(new_binding)
     readd = not instance.enumerated
     return readd, is_new
Example #2
0
 def _generate_results(self, instance):
     # assert(instance.opt_index == 0)
     if not is_instance_ready(self.evaluations, instance):
         raise RuntimeError(instance)
     is_new = bool(process_instance(self.store, self.domain, instance, disable=self.disable))
     for i, binding in enumerate(list(self.bindings_from_instance[instance])):
         #print(i, binding)
         # Maybe this list grows but not all the things are accounted for
         if self.is_enabled(binding):
             binding.update_instances()
             self.update_enabled(binding)
     #print()
     return is_new
Example #3
0
 def _process_binding(self, binding):
     is_new = False
     if binding.is_dominated():
         return False, is_new
     if binding.is_bound():
         action_plan = bind_action_plan(binding.skeleton.action_plan,
                                        binding.mapping)
         self.store.add_plan(action_plan, binding.cost)
         return False, True
     binding.attempts += 1
     instance = binding.result.instance
     if PRUNE_BINDINGS and not binding.do_evaluate():
         # TODO: causes redudant plan skeletons to be identified (along with complexity using attempts instead of calls)
         # Do I need to reenable this stream in case another skeleton needs it?
         # TODO: should I perform this when deciding to sample something new instead?
         #if instance.enumerated:
         #    return False, is_new
         return None, is_new
     #if not is_instance_ready(self.evaluations, instance):
     #    raise RuntimeError(instance)
     if binding.up_to_date():
         new_results, _ = process_instance(self.store,
                                           self.domain,
                                           instance,
                                           disable=self.disable)
         is_new = bool(new_results)
     for call_idx in range(binding.calls, instance.num_calls):
         for new_result in instance.results_history[
                 call_idx]:  # TODO: don't readd if successful already
             if new_result.is_successful():
                 new_mapping = update_bindings(binding.mapping,
                                               binding.result, new_result)
                 new_cost = update_cost(binding.cost, binding.result,
                                        new_result)
                 new_history = binding.history + [call_idx]
                 new_binding = Binding(binding.skeleton, new_cost,
                                       new_history, new_mapping,
                                       binding.index + 1)
                 binding.children.append(new_binding)
                 heappush(self.queue, new_binding.get_element())
     binding.calls = instance.num_calls
     binding.attempts = max(binding.attempts, binding.calls)
     binding.complexity = None
     readd = not instance.enumerated
     return readd, is_new