def process_stream_plan(store, domain, disabled, stream_plan, action_plan, cost, bind=True, max_failures=0): # Bad old implementation of this method # The only advantage of this vs skeleton is that this can avoid the combinatorial growth in bindings if not is_plan(stream_plan): return stream_plan = [result for result in stream_plan if result.optimistic] free_objects = get_free_objects(stream_plan) bindings = {} bound_plan = [] for i, opt_result in enumerate(stream_plan): if (store.best_cost <= cost) or (max_failures < (i - len(bound_plan))): # TODO: this terminates early when bind=False break opt_inputs = [inp for inp in opt_result.instance.input_objects if inp in free_objects] if (not bind and opt_inputs) or not all(inp in bindings for inp in opt_inputs): continue bound_result = opt_result.remap_inputs(bindings) bound_instance = bound_result.instance if bound_instance.enumerated or not is_instance_ready(store.evaluations, bound_instance): continue # TODO: could remove disabled and just use complexity_limit new_results = process_instance(store, domain, bound_instance) if not bound_instance.enumerated: disabled.add(bound_instance) if not new_results: continue bound_plan.append(new_results[0]) bindings = update_bindings(bindings, bound_result, bound_plan[-1]) cost = update_cost(cost, opt_result, bound_plan[-1]) if len(stream_plan) == len(bound_plan): store.add_plan(bind_action_plan(action_plan, bindings), cost)
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
def process_stream_plan(store, domain, disabled, stream_plan, max_failures=INF): # TODO: had old implementation of these # TODO: could do version that allows bindings and is able to return # The only advantage of this vs skeleton is that this can avoid the combinatorial growth in bindings if not is_plan(stream_plan): return failures = 0 for result in stream_plan: if max_failures < failures: break instance = result.instance if instance.enumerated: raise RuntimeError(instance) if is_instance_ready(store.evaluations, instance): # TODO: could remove disabled and just use complexity_limit failures += not process_instance(store, domain, instance) if not instance.enumerated: disabled.add(instance)
def process_stream_plan_branch(store, domain, disabled, stream_plan, action_plan, cost): if not is_plan(stream_plan): return stream_plan = [result for result in stream_plan if result.optimistic] if not stream_plan: store.add_plan(action_plan, cost) return free_objects = get_free_objects(stream_plan) bindings = defaultdict(set) for opt_result in stream_plan: opt_inputs = [inp for inp in opt_result.instance.input_objects if inp in free_objects] inp_bindings = [bindings[inp] for inp in opt_inputs] for combo in product(*inp_bindings): bound_result = opt_result.remap_inputs(get_mapping(opt_inputs, combo)) bound_instance = bound_result.instance if bound_instance.enumerated or not is_instance_ready(store.evaluations, bound_instance): continue # Disabled new_results = process_instance(store, domain, bound_instance) if not bound_instance.enumerated: disabled.add(bound_instance) if isinstance(opt_result, StreamResult): for new_result in new_results: for out, obj in safe_zip(opt_result.output_objects, new_result.output_objects): bindings[out].add(obj)
def process_stream_plan(store, domain, disabled, stream_plan, action_plan, cost, bind=True, max_failures=0): # Bad old implementation of this method # The only advantage of this vs skeleton is that this can avoid the combinatorial growth in bindings if not is_plan(stream_plan): return if not stream_plan: store.add_plan(action_plan, cost) return stream_plan = [result for result in stream_plan if result.optimistic] free_objects = get_free_objects(stream_plan) bindings = {} bound_plan = [] for idx, opt_result in enumerate(stream_plan): if (store.best_cost <= cost) or (max_failures < (idx - len(bound_plan))): # TODO: this terminates early when bind=False break opt_inputs = [ inp for inp in opt_result.instance.input_objects if inp in free_objects ] if (not bind and opt_inputs) or not all(inp in bindings for inp in opt_inputs): continue bound_result = opt_result.remap_inputs(bindings) bound_instance = bound_result.instance if bound_instance.enumerated or not is_instance_ready( store.evaluations, bound_instance): continue # TODO: could remove disabled and just use complexity_limit new_results = process_instance(store, domain, bound_instance) if not bound_instance.enumerated: disabled.add(bound_instance) for new_result in new_results: if new_result.is_successful(): bound_plan.append(new_results[0]) bindings = update_bindings(bindings, bound_result, bound_plan[-1]) cost = update_cost(cost, opt_result, bound_plan[-1]) break if bind and (len(stream_plan) == len(bound_plan)): store.add_plan(bind_action_plan(action_plan, bindings), cost) # TODO: report back whether to try w/o optimistic values in the event that wild ################################################## # def process_stream_plan_branch(store, domain, disabled, stream_plan, action_plan, cost): # if not is_plan(stream_plan): # return # stream_plan = [result for result in stream_plan if result.optimistic] # if not stream_plan: # store.add_plan(action_plan, cost) # return # free_objects = get_free_objects(stream_plan) # bindings = defaultdict(set) # for opt_result in stream_plan: # opt_inputs = [inp for inp in opt_result.instance.input_objects if inp in free_objects] # inp_bindings = [bindings[inp] for inp in opt_inputs] # for combo in product(*inp_bindings): # bound_result = opt_result.remap_inputs(get_mapping(opt_inputs, combo)) # bound_instance = bound_result.instance # if bound_instance.enumerated or not is_instance_ready(store.evaluations, bound_instance): # continue # Disabled # new_results = process_instance(store, domain, bound_instance) # if not bound_instance.enumerated: # disabled.add(bound_instance) # if isinstance(opt_result, StreamResult): # for new_result in new_results: # for out, obj in safe_zip(opt_result.output_objects, new_result.output_objects): # bindings[out].add(obj) # #Binding = namedtuple('Binding', ['index', 'mapping']) # # TODO: after querying, search over all bindings of the produced sampled