def solve(self): # the result object to be finally returned res = Result() # call the algorithm to solve the problem self._solve(self.problem) # store the resulting population res.pop = self.pop # if the algorithm already set the optimum just return it, else filter it by default if self.opt is None: opt = filter_optimum(res.pop.copy(), least_infeasible=self.return_least_infeasible) else: opt = self.opt # get the vectors and matrices res.opt = opt if isinstance(opt, Population): X, F, CV, G = opt.get("X", "F", "CV", "G") elif isinstance(opt, Individual): X, F, CV, G = opt.X, opt.F, opt.CV, opt.G else: X, F, CV, G = None, None, None, None # set all the individual values res.X, res.F, res.CV, res.G = X, F, CV, G # create the result object res.problem, res.pf = self.problem, self.pf res.history = self.history return res
def solve(self): # the result object to be finally returned res = Result() # set the timer in the beginning of the call res.start_time = time.time() # call the algorithm to solve the problem self._solve(self.problem) # store the time when the algorithm as finished res.end_time = time.time() res.exec_time = res.end_time - res.start_time # store the resulting population res.pop = self.pop # get the optimal solution found opt = self.opt # if optimum is not set if len(opt) == 0: opt = None # if no feasible solution has been found elif not np.any(opt.get("feasible")): if self.return_least_infeasible: opt = filter_optimum(opt, least_infeasible=True) else: opt = None # set the optimum to the result object res.opt = opt # if optimum is set to none to not report anything if opt is None: X, F, CV, G = None, None, None, None # otherwise get the values from the population else: X, F, CV, G = self.opt.get("X", "F", "CV", "G") # if single-objective problem and only one solution was found - create a 1d array if self.problem.n_obj == 1 and len(X) == 1: X, F, CV, G = X[0], F[0], CV[0], G[0] # set all the individual values res.X, res.F, res.CV, res.G = X, F, CV, G # create the result object res.problem, res.pf = self.problem, self.pf res.history = self.history return res