def evaluate_constraints(self, solution: FloatSolution) -> FloatSolution: constraints = [0.0 for _ in range(self.number_of_constraints)] theta = -0.25 * pi n = 4.0 f0 = solution.objectives[0] f1 = solution.objectives[1] constraints[0] = f0 * sin(theta) + f1 * cos(theta) - sin( n * pi * (f0 * cos(theta) - f1 * sin(theta))) - 2.5 x_offset = 1.6 y_offset = 1.6 a = 1.5 b = 6.0 r = 0.1 constraints[1] = (pow(((f0 - x_offset) * cos(theta) - (f1 - y_offset) * sin(theta)) / a, 2) + pow( ((f0 - x_offset) * sin(theta) + (f1 - y_offset) * cos(theta)) / b, 2) - r) solution.constraints = constraints return solution
def classifier_solution(self, solution: FloatSolution) -> FloatSolution: c = self.classifier.classify(solution) c[1] = -0.5 * c[1] if c[1] > 0 else 0 c[2] = -c[2] if c[2] > 0 else 0 c[3] = -2 * c[3] if c[3] > 0 else 0 solution.constraints = c return solution
def evaluate_constraints(self, solution: FloatSolution) -> FloatSolution: constraints = [0.0 for _ in range(self.number_of_constraints)] f = sum([pow(solution.objectives[i], 2) for i in range(solution.number_of_objectives)]) constraints[0] = (f - 9) * (f - 4) constraints[1] = (f - 1.9 * 1.9) * (f - 1.8 * 1.8) solution.constraints = constraints return solution
def __evaluate_constraints(self, solution: FloatSolution) -> None: constraints = [0.0 for _ in range(self.number_of_constraints)] x1 = solution.variables[0] x2 = solution.variables[1] constraints[0] = x1 * x1 + x2 * x2 - 1.0 - 0.1 * cos( 16.0 * atan(x1 / x2)) constraints[1] = -2.0 * ((x1 - 0.5) * (x1 - 0.5) + (x2 - 0.5) * (x2 - 0.5) - 0.5) solution.constraints = constraints
def __evaluate_constraints(self, solution: FloatSolution) -> None: constraints = [0.0 for _ in range(self.number_of_constraints)] x = solution.variables constraints[0] = (x[0] + x[1]) / 2.0 - 1.0 constraints[1] = (6.0 - x[0] - x[1]) / 6.0 constraints[2] = (2.0 - x[1] + x[0]) / 2.0 constraints[3] = (2.0 - x[0] + 3.0 * x[1]) / 2.0 constraints[4] = (4.0 - (x[2] - 3.0) * (x[2] - 3.0) - x[3]) / 4.0 constraints[5] = ((x[4] - 3.0) * (x[4] - 3.0) + x[5] - 4.0) / 4.0 solution.constraints = constraints
def evaluate_constraints(self, solution: FloatSolution) -> FloatSolution: x = solution.variables constraints = [0.0 for _ in range(self.number_of_constraints)] a = 0.51 b = 0.5 constraints[0] = (a - self.g1(x)) * (self.g1(x) - b) constraints[1] = (a - self.g2(x)) * (self.g2(x) - b) solution.constraints = constraints return solution
def test_should_copy_work_properly(self) -> None: solution = FloatSolution([0.0, 3.5], [1.0, 5.0], 3, 2) solution.variables = [1.24, 2.66] solution.objectives = [0.16, -2.34, 9.25] solution.constraints = [-1.2, -0.25] solution.attributes["attr"] = "value" new_solution = copy.copy(solution) self.assertEqual(solution.number_of_variables, new_solution.number_of_variables) self.assertEqual(solution.number_of_objectives, new_solution.number_of_objectives) self.assertEqual(solution.variables, new_solution.variables) self.assertEqual(solution.objectives, new_solution.objectives) self.assertEqual(solution.lower_bound, new_solution.lower_bound) self.assertEqual(solution.upper_bound, new_solution.upper_bound) self.assertEqual(solution.constraints, new_solution.constraints) self.assertIs(solution.lower_bound, solution.lower_bound) self.assertIs(solution.upper_bound, solution.upper_bound) self.assertEqual(solution.attributes, new_solution.attributes)
def evaluate_constraints(self, solution: FloatSolution) -> FloatSolution: constraints = [0.0 for _ in range(self.number_of_constraints)] r = 0.1 theta = -0.25 * pi a_array = [2.0, 2.5, 2.5] b_array = [6.0, 12.0, 10.0] x_offset = [1.2, 2.25, 3.5] y_offset = [1.2, 2.25, 3.5] f1 = solution.objectives[0] f2 = solution.objectives[1] for i in range(len(x_offset)): constraints[i] = pow( ((f1 - x_offset[i]) * cos(theta) - (f2 - y_offset[i]) * sin(theta)) / a_array[i], 2) + \ pow( ((f1 - x_offset[i]) * sin(theta) + (f2 - y_offset[i]) * cos(theta)) / b_array[i], 2) - r solution.constraints = constraints return solution