def CylinderProblem(): """Return a simple cylinder ScalarMOProblem. Note: In this problem consider a cell shaped like a cylinder with a circular cross-section. The shape of the cell is here determined by two quantities, its radius `r` and its height `h`. We want to maximize the volume of the cylinder and minimize the surface area. In addition to this, cylinder's height should be close to 15 units, i.e. we minimize the absolute difference between the height and 15. Finally the cylinder's height must be greater or equal to its width. Thus there are 2 decision variables, 3 objectives and 1 constraint in this problem. """ # Variables r := x[0], h := x[1] variables = [] variables.append(Variable("radius", 10, 5, 15)) variables.append(Variable("height", 10, 5, 25)) # Objectives objectives = [] objectives.append( ScalarObjective("Volume", lambda x: np.pi * x[0] ** 2 * x[1]) ) objectives.append( ScalarObjective( "Surface area", lambda x: -(2 * np.pi * x[0] ** 2 + 2 * np.pi * x[0] * x[1]), ) ) objectives.append( ScalarObjective("Height Difference", lambda x: abs(x[1] - 15.0)) ) # Constraints constraints = [] constraints.append( ScalarConstraint( "Height greater than width", len(variables), len(objectives), constraint_function_factory( lambda x, f: 2 * x[0] - x[1], 0.0, "<" ), ) ) # problem problem = ScalarMOProblem(objectives, variables, constraints) return problem
def scalar_objectives(): def fun1(d_vars): return d_vars[0] + d_vars[1] + d_vars[2] def fun2(d_vars): return d_vars[3] - d_vars[1] * d_vars[2] def fun3(d_vars): return d_vars[2] obj_1 = ScalarObjective("f1", fun1) obj_2 = ScalarObjective("f2", fun2) obj_3 = ScalarObjective("f3", fun3) return [obj_1, obj_2, obj_3]
def RiverPollutionProblem(): """Return the river pollution problem as defined in `Miettinen 2010`_ .. _Miettinen 2010: Miettinen, K.; Eskelinen, P.; Ruiz, F. & Luque, M. NAUTILUS method: An interactive technique in multiobjective optimization based on the nadir point Europen Joural of Operational Research, 2010, 206, 426-434 """ # Variables variables = [] variables.append(Variable("x_1", 0.5, 0.3, 1.0)) variables.append(Variable("x_2", 0.5, 0.3, 1.0)) # Objectives objectives = [] objectives.append(ScalarObjective("f_1", lambda x: -4.07 - 2.27 * x[0])) objectives.append( ScalarObjective( "f_2", lambda x: -2.60 - 0.03 * x[0] - 0.02 * x[1] - 0.01 / (1.39 - x[0] ** 2) - 0.30 / (1.39 - x[1] ** 2), ) ) objectives.append( ScalarObjective("f_3", lambda x: -8.21 + 0.71 / (1.09 - x[0] ** 2)) ) objectives.append( ScalarObjective("f_4", lambda x: -0.96 + 0.96 / (1.09 - x[1] ** 2)) ) # problem problem = ScalarMOProblem(objectives, variables, []) return problem
def DTLZ1_3D(): n = 3 variables = [] for i in range(n): variables.append(Variable("x{}".format(i), 0.5, 0, 1)) def g(x): return 100 * (n - 2) + 100 * ( np.sum((x[2:] - 0.5) ** 2 - np.cos(20 * np.pi * (x[2:] - 0.5))) ) objectives = [] objectives.append( ScalarObjective("f1", lambda x: (1 + g(x)) * x[0] * x[1]) ) objectives.append( ScalarObjective("f2", lambda x: (1 + g(x)) * x[0] * (1 - x[1])) ) objectives.append(ScalarObjective("f3", lambda x: (1 + g(x)) * (1 - x[0]))) constraints = [] for i in range(n): constraints.append( ScalarConstraint( "", len(variables), len(objectives), constraint_function_factory(lambda x, f: x[i], 0.0, ">"), ) ) constraints.append( ScalarConstraint( "", len(variables), len(objectives), constraint_function_factory(lambda x, f: x[i], 1.0, "<"), ) ) problem = ScalarMOProblem(objectives, variables, constraints) return problem
def scalar_obj_1(): def fun(vec): return vec[0] + vec[1] + vec[2] return ScalarObjective("Objective 1", fun, -10, 10)
def test_bad_bounds(): with pytest.raises(ObjectiveError): ScalarObjective("", None, -10.0, -11.0)
def test_default_bounds(): obj = ScalarObjective("", None) assert obj.lower_bound == -np.inf assert obj.upper_bound == np.inf