xs = np.atleast_2d(xs) return (-2.60 - 0.03 * xs[:, 0] - 0.02 * xs[:, 1] - (0.01 / (1.39 - xs[:, 0]**2)) - (0.30 / (1.39 - xs[:, 1]**2))) def f3(xs): xs = np.atleast_2d(xs) return -8.21 + (0.71 / (1.09 - xs[:, 0]**2)) def f4(xs): xs = np.atleast_2d(xs) return -0.96 + (0.96 / (1.09 - xs[:, 1]**2)) def objectives(xs): return np.stack((f1(xs), f2(xs), f3(xs), f4(xs))).T obj1 = _ScalarObjective("obj1", f1) obj2 = _ScalarObjective("obj2", f2) obj3 = _ScalarObjective("obj3", f3) obj4 = _ScalarObjective("obj4", f4) objkaikki = VectorObjective("obj", objectives) # variables var_names = ["x1", "x2" ] # Make sure that the variable names are meaningful to you. initial_values = np.array([0.5, 0.5]) lower_bounds = [0.3, 0.3] upper_bounds = [1.0, 1.0] bounds = np.stack((lower_bounds, upper_bounds)) variables = variable_builder(var_names, initial_values, lower_bounds,
def f_3(x): res = 8.21 - 0.71 / (1.09 - x[:, 0]**2) return -res def f_4(x): res = 0.96 - 0.96 / (1.09 - x[:, 1]**2) return -res def f_5(x): return np.max([np.abs(x[:, 0] - 0.65), np.abs(x[:, 1] - 0.65)], axis=0) def c_1(x, f=None): x = x.squeeze() return (x[0] + x[1]) - 0.5 f1 = _ScalarObjective(name="f1", evaluator=f_1) f2 = _ScalarObjective(name="f2", evaluator=f_2) f3 = _ScalarObjective(name="f3", evaluator=f_3) f4 = _ScalarObjective(name="f4", evaluator=f_4) f5 = _ScalarObjective(name="f5", evaluator=f_5) varsl = variable_builder( ["x_1", "x_2"], initial_values=[0.5, 0.5], lower_bounds=[0.3, 0.3], upper_bounds=[1.0, 1.0], ) c1 = ScalarConstraint("c1", 2, 5, evaluator=c_1) problem = MOProblem(variables=varsl, objectives=[f1, f2, f3, f4, f5], constraints=[c1])
def f_4(x): # min res = -0.96 + 0.96 / (1.09 - x[:, 1]**2) return res # def f_5(x): # return -0.96 + 0.96 / (1.09 - x[:, 1]**2) def f_5(x): # min return np.max([np.abs(x[:, 0] - 0.65), np.abs(x[:, 1] - 0.65)], axis=0) f1 = _ScalarObjective(name="f1", evaluator=f_1, maximize=[True]) f2 = _ScalarObjective(name="f2", evaluator=f_2, maximize=[True]) f3 = _ScalarObjective(name="f3", evaluator=f_3, maximize=[True]) f4 = _ScalarObjective(name="f4", evaluator=f_4) f5 = _ScalarObjective(name="f5", evaluator=f_5) varsl = variable_builder( ["x_1", "x_2"], initial_values=[0.5, 0.5], lower_bounds=[0.3, 0.3], upper_bounds=[1.0, 1.0], ) problem = MOProblem(variables=varsl, objectives=[f1, f2, f3, f4, f5]) evolver = RVEA(problem, interact=True, n_iterations=10, n_gen_per_iter=100)
def f_1(x): # min x_1 + x_2 + x_3 res = x[:, 0] + x[:, 1] + x[:, 2] return res def f_2(x): # max x_1 + x_2 + x_3 res = x[:, 0] + x[:, 1] + x[:, 2] return res def f_3(x): # max x_1 + x_2 - x_3 res = -x[:, 0] - x[:, 1] - x[:, 2] return res f1 = _ScalarObjective(name="Price", evaluator=f_1, maximize=False) f2 = _ScalarObjective(name="Quality", evaluator=f_2, maximize=True) f3 = _ScalarObjective(name="Size", evaluator=f_3, maximize=True) objl = [f1, f2, f3] # define the variables, bounds -5 <= x_1 and x_2 <= 5 varsl = variable_builder(["x_1", "x_2", "x_3"], initial_values=[0.5, 0.5, 0.5], lower_bounds=[-5, -5, -5], upper_bounds=[5, 5, 5]) # define constraints def c_1(x, f=None): x = x.squeeze() # x_1 < 2
-10 * np.exp(-0.2 * np.sqrt(xs[:, :-1]**2 + xs_plusone[:, :-1]**2)), axis=1) def f_2(xs: np.ndarray): xs = np.atleast_2d(xs) return np.sum(np.abs(xs)**0.8 + 5 * np.sin(xs**3), axis=1) varsl = variable_builder( ["x_1", "x_2", "x_3"], initial_values=[0, 0, 0], lower_bounds=[-5, -5, -5], upper_bounds=[5, 5, 5], ) f1 = _ScalarObjective(name="f1", evaluator=f_1) f2 = _ScalarObjective(name="f2", evaluator=f_2) #For AI_DM ranges are always defined as IDEAL, NADIR. f1_range = [-20, -14] f2_range = [-14, 0.5] x1 = np.linspace(min(f1_range), max(f1_range), 1000) x2 = np.linspace(min(f2_range), max(f2_range), 1000) y = np.linspace(0, 0, 1000) problem = MOProblem(variables=varsl, objectives=[f1, f2], ideal=np.array([-20, -12]), nadir=np.array([-14, 0.5])) from desdeo_mcdm.interactive.NIMBUS import NIMBUS