def search(self, _demand_list, _objective): decision_path = dpath.DecisionPath() decision_path.set_decisions({}) for demand in _demand_list: LOG.debug("demand = {}".format(demand.name)) decision_path.current_demand = demand candidate_list = self._solve_constraints(decision_path) bound_value = 0.0 if _objective.goal == "min": bound_value = sys.float_info.max best_resource = None for candidate in candidate_list: decision_path.decisions[demand.name] = candidate _objective.compute(decision_path) if _objective.goal == "min": if decision_path.total_value < bound_value: bound_value = decision_path.total_value best_resource = candidate if best_resource is not None: decision_path.decisions[demand.name] = best_resource decision_path.total_value = bound_value else: return None return decision_path
def search(self, _demand_list, _objective): decision_path = dpath.DecisionPath() decision_path.set_decisions({}) ''' implement search algorithm ''' return decision_path
def search(self, _demand_list, _objective, _request): decision_path = dpath.DecisionPath() decision_path.set_decisions({}) _begin_time = int(round(time.time())) # Begin the recursive serarch return self._find_current_best( _demand_list, _objective, decision_path, _request, _begin_time)
def search(self, _demand_list, _request): decision_path = dpath.DecisionPath() decision_path.set_decisions({}) return self._find_current_best(_demand_list, decision_path, _request)
def search(self, _demand_list, _objective): dlist = copy.deepcopy(_demand_list) heuristic_solution = self._search_by_fit_first(dlist, _objective) if heuristic_solution is None: LOG.debug("no solution") return None open_list = [] close_paths = {} ''' for the decision length heuristic ''' # current_decision_length = 0 # create root path decision_path = dpath.DecisionPath() decision_path.set_decisions({}) # insert the root path into open_list open_list.append(decision_path) while len(open_list) > 0: p = open_list.pop(0) ''' for the decision length heuristic ''' # dl = len(p.decisions) # if dl >= current_decision_length: # current_decision_length = dl # else: # continue # if explored all demands in p, complete the search with p unexplored_demand = self._get_new_demand(p, _demand_list) if unexplored_demand is None: return p p.current_demand = unexplored_demand msg = "demand = {}, decisions = {}, value = {}" LOG.debug(msg.format(p.current_demand.name, p.decision_id, p.total_value)) # constraint solving candidate_list = self._solve_constraints(p) if len(candidate_list) > 0: for candidate in candidate_list: # create path for each candidate for given demand np = dpath.DecisionPath() np.set_decisions(p.decisions) np.decisions[p.current_demand.name] = candidate _objective.compute(np) valid_candidate = True # check closeness for this decision np.set_decision_id(p, candidate.name) if np.decision_id in close_paths.keys(): valid_candidate = False ''' for base comparison heuristic ''' # TODO(gjung): how to know this is about min if _objective.goal == "min": if np.total_value >= heuristic_solution.total_value: valid_candidate = False if valid_candidate is True: open_list.append(np) # sort open_list by value open_list.sort(key=operator.attrgetter("total_value")) else: LOG.debug("no candidates") # insert p into close_paths close_paths[p.decision_id] = p return heuristic_solution
def _search_by_fit_first(self, _demand_list, _objective): decision_path = dpath.DecisionPath() decision_path.set_decisions({}) return self._find_current_best(_demand_list, _objective, decision_path)