def update_state(self, params): Algorithm.update_state(self, params) self.best_solution = None if not params["best_solution"] else solution( params["best_solution"]) self.current_solution = solution(params["current_solution"]) self.T = params["T"] self.T0 = params["T0"] self.Tf = params["Tf"] self.alpha = params["alpha"] self.iterations = params["iterations"] self.trial = params["trial"] self.trials_per_cycle = params["trials_per_cycle"]
def update_state(self, params = {}): if params == {}: return self.max_evals = params["max_evals"] self.init_steps = params["init_steps"] self.iterations = params["iterations"] self.constraints = params["constraints"] self.training_set = map(lambda s: solution(s), params["training_set"]) self.testing_set = params["testing_set"] self.additional_solutions = map(lambda s: solution(s), params["additiona_small_input_solutions"]) self.selected_solutions = params["selected_configurations"] self.failed_set = map(lambda s: solution(s), params["failed_set"]) self.model.restore(params["mathematical_model"])
def update_state(self, params={}): self.solutions = [] sol_info = params["solutions"] for s in sol_info: self.solutions.append(solution(s)) self.max_evals = params["max_evals"] self.init_steps = params["init_steps"] self.x_size = params["x_size"]
def init_parameters(self): self.current_solution = solution() self.best_solution = None self.T = None self.T0 = None self.Tf = None self.alpha = None self.iterations = 0 self.trial = 0 self.trials_per_cycle = 3
def run_step(self): self.check_state() if self.T: if self.stop_condition(): return 0 #else generate a number of solutions for the current temperature if self.trial == self.trials_per_cycle: self.update_temperature() #build new solution new_solution = solution() x = self.neighbor(self.current_solution.x, self.current_solution.gradient) #execute function which returns the cost as the product between the monetary cost and execution time #returns tuple (conf, cost) success, conf, cost, et, direction, monitor = self.function(x) print success if not success["Success"]: et = finfo(float).max return new_solution = solution({ "conf": conf, "x": x, "cost": cost, "et": et, "gradient": direction, "monitor": monitor, "success": success["Success"] }) self.solutions.append(new_solution) self.iterations += 1 if not self.T: #if the temperature has not been initialized then we are are in the random tries to init it return new_solution self.trial += 1 self.accept_or_reject_solution(new_solution) return self.best_solution
def run_step(self): #self.check_state() if self.stop_condition(): return 0 print "Running extrapolating step..." conf_to_test = self.testing_set[0] print "Testing conf:", conf_to_test success, var_order, cost, et, direction, monitor = self.app_execution_function_call(conf_to_test) print success if success["Success"]: self.training_set.append(solution({"conf" : conf_to_test, "x" : None, "cost" : cost, "et" : et, "gradient" : direction, "monitor" : monitor, "success" : success["Success"]})) self.iterations += 1 else: self.failed_set.append(solution({"conf" : conf_to_test, "x" : None, "cost" : cost, "et" : et, "gradient" : direction, "monitor" : monitor, "success" : success["Success"]})) #add new conf to test in solutions bottlenecks = success["Bottleneck"] indexes = filter(lambda i : bottlenecks[i], range(len(bottlenecks))) if indexes == []: #can't detect the bottleneck from the utilisation print "Unknown failure." self.testing_set = self.testing_set[1:] return #derive the new configuration new_conf = copy.deepcopy(conf_to_test) print indexes for ind in indexes: #store bound in constraints self.constraints[var_order[i]] = conf_to_test[var_order[i]] #get a higher value for the bottleneck resource new_conf[var_order[i]] = self.mapper.get_next_value_from(var_order[i], conf_to_test[var_order[i]]) if new_conf[var_order[i]] == None: raise Exception("Field %s has no valid value for extrapolation." %(var_order[i])) return pf = map(lambda x:x["conf"], self.profiling_solutions) small_input = self.benchmark_input #if new_conf hasn't been discovered during profiling we must test the small input size if not (new_conf in pf): #run the small input on the new configuration success, var_order, cost, et, direction, monitor = self.app_execution_function_call(new_conf, small_input) print success if success["Success"]: self.additional_solutions.append(solution({"conf" : conf_to_test, "x" : None, "cost" : cost, "et" : et, "gradient" : direction, "monitor" : monitor, "success" : success["Success"]})) else: print "Invalid solution for benchmarking input. Remove the current tested solution." self.testing_set = self.testing_set[1:] return #store the new configuration to be tested self.testing_set[0] = new_conf return self.generate_model() #remove configuration from the testing set self.testing_set = self.testing_set[1:] print "Failed : ", len(self.failed_set)