def comp_by_cv_and_fitness(pop, P, **kwargs): S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] # if at least one solution is infeasible if pop[a].CV > 0.0 or pop[b].CV > 0.0: S[i] = compare(a, pop[a].CV, b, pop[b].CV, method='smaller_is_better', return_random_if_equal=True) # both solutions are feasible just set random else: S[i] = compare(a, pop[a].F, b, pop[b].F, method='smaller_is_better', return_random_if_equal=True) return S[:, None].astype(np.int)
def comp_by_cv_and_clearing_fitness(pop, P, **kwargs): S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] # if at least one solution is infeasible if pop[a].CV > 0.0 or pop[b].CV > 0.0: S[i] = compare(a, pop[a].CV, b, pop[b].CV, method='smaller_is_better', return_random_if_equal=True) # first compare by the round the individual was selected else: S[i] = compare(a, pop[a].get("iter"), b, pop[b].get("iter"), method='smaller_is_better') # if it was the same round - then use the rank of the fitness directly if np.isnan(S[i]): S[i] = compare(a, pop[a].get("rank"), b, pop[b].get("rank"), method='smaller_is_better', return_random_if_equal=True) return S[:, None].astype(int)
def binary_tournament(pop, P, algorithm): if P.shape[1] != 2: raise ValueError("Only implemented for binary tournament!") tournament_type = algorithm.tournament_type S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] if tournament_type == 'comp_by_dom_and_crowding': rel = Dominator.get_relation(pop[a].F, pop[b].F) if rel == 1: S[i] = a elif rel == -1: S[i] = b elif tournament_type == 'comp_by_rank_and_crowding': S[i] = compare(a, pop[a].rank, b, pop[b].rank, method='smaller_is_better') else: raise Exception("Unknown tournament type.") if np.isnan(S[i]): S[i] = compare(a, pop[a].get("crowding"), b, pop[b].get("crowding"), method='larger_is_better', return_random_if_equal=True) return S[:, None].astype(np.int)
def comp_by_rank_and_ref_line_dist(pop, P, **kwargs): S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] # if at least one solution is infeasible if pop[a].CV > 0.0 or pop[b].CV > 0.0: S[i] = compare(a, pop[a].CV, b, pop[b].CV, method='smaller_is_better', return_random_if_equal=True) # both solutions are feasible else: # if in the same niche select by rank if pop[a].get("niche") == pop[b].get("niche"): if pop[a].get("rank") != pop[b].get("rank"): S[i] = compare(a, pop[a].get("rank"), b, pop[b].get("rank"), method='smaller_is_better') else: S[i] = compare(a, pop[a].get("dist_to_niche"), b, pop[b].get("dist_to_niche"), method='smaller_is_better') if np.isnan(S[i]): S[i] = np.random.choice([a, b]) return S[:, None].astype(np.int)
def binary_tournament(pop, P, algorithm, **kwargs): if P.shape[1] != 2: raise ValueError("Only implemented for binary tournament!") tournament_type = algorithm.tournament_type S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] # if at least one solution is infeasible if pop[a].CV > 0.0 or pop[b].CV > 0.0: S[i] = compare( a, pop[a].CV, b, pop[b].CV, method="smaller_is_better", return_random_if_equal=True, ) # both solutions are feasible else: if tournament_type == "comp_by_dom_and_crowding": rel = Dominator.get_relation(pop[a].F, pop[b].F) if rel == 1: S[i] = a elif rel == -1: S[i] = b elif tournament_type == "comp_by_rank_and_crowding": S[i] = compare( a, pop[a].rank, b, pop[b].rank, method="smaller_is_better" ) else: raise Exception("Unknown tournament type.") # if rank or domination relation didn't make a decision compare by crowding if np.isnan(S[i]): S[i] = compare( a, pop[a].get("crowding"), b, pop[b].get("crowding"), method="larger_is_better", return_random_if_equal=True, ) return S[:, None].astype(np.int)
def comp_by_rank(pop, P, **kwargs): S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] S[i] = compare(a, pop[a].get("rank"), b, pop[b].get("rank"), method='smaller_is_better', return_random_if_equal=True) return S[:, None].astype(np.int)
def binary_tournament(pop, P, algorithm, **kwargs): if P.shape[1] != 2: raise ValueError("Only implemented for binary tournament!") S = np.full(P.shape[0], np.nan) for i in range(P.shape[0]): a, b = P[i, 0], P[i, 1] # if at least one solution is infeasible if pop[a].CV > 0.0 or pop[b].CV > 0.0: S[i] = compare(a, pop[a].CV, b, pop[b].CV, method='smaller_is_better', return_random_if_equal=True) # both solutions are feasible else: S[i] = compare(a, pop[a].get("rank"), b, pop[b].get("rank"), method='smaller_is_better', return_random_if_equal=True) # if rank or domination relation didn't make a decision compare by crowding if np.isnan(S[i]): S[i] = compare(a, pop[a].get("apd"), b, pop[b].get("apd"), method='smaller_is_better', return_random_if_equal=True) return S[:, None].astype(np.int, copy=False)