Пример #1
0
    def create_solution(self) -> FloatSolution:
        new_solution = FloatSolution(self.number_of_variables, self.number_of_objectives, self.number_of_constraints,
                                     self.lower_bound, self.upper_bound)
        new_solution.variables = \
            [random.uniform(self.lower_bound[i]*1.0, self.upper_bound[i]*1.0) for i in range(self.number_of_variables)]

        return new_solution
Пример #2
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        value = solution.variables[0]

        solution.objectives[0] = value**2
        solution.objectives[1] = (value - 2)**2

        return solution
Пример #3
0
    def create_solution(self) -> FloatSolution:
        new_solution = FloatSolution(self.number_of_variables, self.number_of_objectives, self.number_of_constraints,
                                     self.lower_bound, self.upper_bound)
        new_solution.variables = \
            [random.uniform(self.lower_bound[i]*1.0, self.upper_bound[i]*1.0) for i in range(self.number_of_variables)]

        return new_solution
Пример #4
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        value = solution.variables[0]

        solution.objectives[0] = value ** 2
        solution.objectives[1] = (value - 2) ** 2

        return solution
Пример #5
0
        def evaluate_constraints(self, solution: FloatSolution) -> None:
            constraints = [0.0 for _ in range(self.number_of_constraints)]

            alpha = solution.variables[0]
            beta = solution.variables[1]
            delta = solution.variables[2]
            gamma = solution.variables[3]

            constraints[0] = (alpha + beta - 1) - tolerance
            constraints[1] = -(alpha + beta - 1) - tolerance
            constraints[2] = (delta + gamma - 1) - tolerance
            constraints[3] = -(delta + gamma - 1) - tolerance

            overall_constraint_violation = 0.0
            number_of_violated_constraints = 0.0

            for constrain in constraints:
                if constrain > 0.0:
                    overall_constraint_violation += constrain
                    number_of_violated_constraints += 1

            # print("{} {}".format(overall_constraint_violation, number_of_violated_constraints))
            solution.attributes[
                'overall_constraint_violation'] = overall_constraint_violation
            solution.attributes[
                'number_of_violated_constraints'] = number_of_violated_constraints
Пример #6
0
        def evaluate_constraints(self, solution: FloatSolution) -> None:
            constraints = [0.0 for _ in range(self.number_of_constraints)]
            rho = solution.variables[0]
            nu = solution.variables[1]
            e = solution.variables[2]
            t = solution.variables[3]
            v = solution.variables[4]
            d = solution.variables[5]
            r = solution.variables[6]
            constraints[0] = rho - 1
            constraints[1] = r + d + t + v + e - 1 - tolerance
            constraints[2] = 1 - (r - d - v - t - e) - tolerance

            overall_constraint_violation = 0.0
            number_of_violated_constraints = 0.0

            for constrain in constraints:
                if constrain > 0.0:
                    overall_constraint_violation += constrain
                    number_of_violated_constraints += 1

            # print("{} {}".format(overall_constraint_violation, number_of_violated_constraints))
            solution.attributes[
                'overall_constraint_violation'] = overall_constraint_violation
            solution.attributes[
                'number_of_violated_constraints'] = number_of_violated_constraints
Пример #7
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        solution.objectives[0] = solution.variables[0]
        solution.objectives[1] = solution.variables[1]

        self.__evaluate_constraints(solution)

        return solution
Пример #8
0
    def create_solution(self) -> CompositeSolution: # INICIALIZAÇÂO DO PROBLEMA
        attributes_solution = IntegerSolution(self.int_lower_bound_attribute, self.int_upper_bound_attribute,
                                              self.number_of_objectives, self.number_of_constraints)

        labels_solution = IntegerSolution(self.int_lower_bound_label, self.int_upper_bound_label,
                                          self.number_of_objectives, self.number_of_constraints)

        points_solution = FloatSolution(self.lower_centroids, self.upper_centroids,
                                        self.number_of_objectives, self.number_of_constraints)
        if self.isSeed:
            attributes_solution.variables = self.antecedentes
            labels_solution.variables = self.consequentes
            points_solution.variables = self.centroids
            self.isSeed = False
        else:
            attributes_solution.variables = \
                [random.randint(self.int_lower_bound_attribute[i], self.int_upper_bound_attribute[i]) for i in
                 range(len(self.int_lower_bound_attribute))]

            labels_solution.variables = \
                [random.randint(self.int_lower_bound_label[i], self.int_upper_bound_label[i]) for i in
                 range(len(self.int_lower_bound_label))]

            points_solution.variables = \
                [random.uniform(self.lower_centroids[i], self.upper_centroids[i]) for i
                 in range(len(self.lower_centroids))]

        return CompositeSolution([attributes_solution, labels_solution, points_solution])
Пример #9
0
    def create_initial_solutions(self) -> List[S]:
        if self.problem.config.iteration_round == 0:
            # print(self.problem.config.iteration_round, self.population_size)
            return [
                self.population_generator.new(self.problem)
                for _ in range(self.population_size)
            ]

            # return [self.problem.create_solution() for _ in range(self.population_size)]  ## random generator
        else:
            population = [
                self.population_generator.new(self.problem)
                for _ in range(int(0.5 * self.population_size))
            ]
            # existing_population = []
            for i in range(self.population_size -
                           int(0.5 * self.population_size)):
                new_solution = FloatSolution(
                    self.problem.lower_bound, self.problem.upper_bound,
                    self.problem.number_of_objectives,
                    self.problem.number_of_constraints)
                new_solution.variables = self.initial_population[
                    self.problem.config.goal_selection_index][i]
                # print(i, self.initial_population[self.problem.config.goal_selection_index][i])
                population.append(new_solution)
            return population
Пример #10
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(self):
        operator = Polynomial(0.0)
        solution = FloatSolution(2, 1, 0, [-5, -5, -5], [5, 5, 5])
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)
        self.assertEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Пример #11
0
    def test_should_the_solution_change_if_the_probability_is_one(self):
        operator = SimpleRandomMutation(1.0)
        solution = FloatSolution([-5, -5, -5], [5, 5, 5], 1)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)
        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Пример #12
0
def lorenz_map(swarm_size, number_of_variables, number_of_objectives,
               number_of_constraints, lower_bound, upper_bound):
    #lorenz map initialization
    chaos_limits = {
        "x_high": 22.0,
        "x_low": -22.0,
        "y_high": 30.0,
        "y_low": -30.0,
        "z_high": 55.0,
        "z_low": 0.0
    }
    lorenz_sets = number_of_variables // 3 + 1
    chaos_set = {}
    for it in range(lorenz_sets):
        chaos_set["xs_list_" + str(it + 1)] = []
        chaos_set["ys_list_" + str(it + 1)] = []
        chaos_set["zs_list_" + str(it + 1)] = []
        dt = 0.02
        xs = np.empty((swarm_size + 1))
        ys = np.empty((swarm_size + 1))
        zs = np.empty((swarm_size + 1))
        xs[0], ys[0], zs[0] = (np.random.rand(), np.random.rand(),
                               np.random.rand())
        for i in range(swarm_size):
            # Derivatives of the X, Y, Z state
            x_dot, y_dot, z_dot = lorenz(xs[i], ys[i], zs[i])
            xs[i + 1] = xs[i] + (x_dot * dt)
            ys[i + 1] = ys[i] + (y_dot * dt)
            zs[i + 1] = zs[i] + (z_dot * dt)
        chaos_set["xs_list_" + str(it + 1)].extend(xs)
        chaos_set["ys_list_" + str(it + 1)].extend(ys)
        chaos_set["zs_list_" + str(it + 1)].extend(zs)
    choices = list(chaos_set.keys())
    #print(chaos_set)
    random.shuffle(choices)
    result = []
    for i in range(swarm_size):
        temp = []
        for i_1 in range(number_of_variables):
            temp.append(((chaos_set[choices[i_1]][i] -
                          chaos_limits[choices[i_1][0] + "_low"]) /
                         (chaos_limits[choices[i_1][0] + "_high"] -
                          chaos_limits[choices[i_1][0] + "_low"])) *
                        (upper_bound[i_1] - lower_bound[i_1]) +
                        lower_bound[i_1])
            #print(chaos_set[choices[i_1]][i],chaos_limits[choices[i_1][0]+"_low"],(chaos_limits[choices[i_1][0]+"_high"],upper_bound[i_1],lower_bound[i_1]),((chaos_set[choices[i_1]][i] - chaos_limits[choices[i_1][0]+"_low"])/(chaos_limits[choices[i_1][0]+"_high"] - chaos_limits[choices[i_1][0]+"_low"])) * (upper_bound[i_1] - lower_bound[i_1]) + lower_bound[i_1])
            #input()
            #print(chaos_set[sel_list[i_1][0]+ "s_list_" + str(sel_list[i_1][1])][i_1])
        new_solution = FloatSolution(number_of_variables, number_of_objectives,
                                     number_of_constraints, lower_bound,
                                     upper_bound)
        #print(temp)
        #input()
        new_solution.variables = temp
        result.append(new_solution)
        #print(temp)
    #print(result)

    return result
Пример #13
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.__eval_g(solution)
        h = self.__eval_h(solution.variables[0], g)

        solution.objectives[0] = solution.variables[0]
        solution.objectives[1] = h * g

        return solution
Пример #14
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.__eval_g(solution)
        h = self.__eval_h(solution.variables[0], g)

        solution.objectives[0] = solution.variables[0]
        solution.objectives[1] = h * g

        return solution
Пример #15
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x1 = solution.variables[0]
        x2 = solution.variables[1]

        solution.objectives[0] = 2.0 + (x1 - 2.0) * (x1 - 2.0) + (x2 - 1.0) * (x2 - 1.0)
        solution.objectives[1] = 9.0 * x1 - (x2 - 1.0) * (x2 - 1.0)

        return solution
Пример #16
0
    def test_should_dominance_comparator_return_minus_one_if_the_two_solutions_have_one_objective_and_the_first_one_is_lower(self):
        solution = FloatSolution(3, 1, 0, [], [])
        solution2 = FloatSolution(3, 1, 0, [], [])

        solution.objectives = [1.0]
        solution2.objectives = [2.0]

        self.assertEqual(-1, self.comparator.compare(solution, solution2))
Пример #17
0
    def test_should_dominance_comparator_return_zero_if_the_two_solutions_have_one_objective_with_the_same_value(self):
        solution = FloatSolution(3, 1, 0, [], [])
        solution2 = FloatSolution(3, 1, 0, [], [])

        solution.objectives = [1.0]
        solution2.objectives = [1.0]

        self.assertEqual(0, self.comparator.compare(solution, solution2))
Пример #18
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x1 = solution.variables[0]
        x2 = solution.variables[1]

        solution.objectives[0] = 2.0 + (x1 - 2.0) * (x1 - 2.0) + (x2 - 1.0) * (x2 - 1.0)
        solution.objectives[1] = 9.0 * x1 - (x2 - 1.0) * (x2 - 1.0)

        return solution
Пример #19
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        n = self.number_of_variables
        solution.objectives[0] = 1 - exp(-sum([(x - 1.0 / n**0.5)**2
                                               for x in solution.variables]))
        solution.objectives[1] = 1 - exp(-sum([(x + 1.0 / n**0.5)**2
                                               for x in solution.variables]))

        return solution
Пример #20
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.__eval_g(solution, self.M - 1)

        solution.objectives[0] = self.__eval_f1(solution, g)
        solution.objectives[1] = self.__eval_fk(solution, g, 2)
        solution.objectives[2] = self.__eval_fm(solution, g)

        return solution
Пример #21
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        EvaluationResult = Evaluation.evaluateNetwork(self.network,
                                                      solution.variables)
        solution.objectives[0] = EvaluationResult[0]
        solution.objectives[1] = EvaluationResult[1]
        # solution.objectives[0] = solution.variables[0]
        # solution.objectives[1] = h * g

        return solution
Пример #22
0
    def test_should_the_solution_change_between_max_and_min_value(self):
        operator = SimpleRandom(1.0)
        solution = FloatSolution(4, 1, 0, [-1, 12, -3, -5], [1, 17, 3, -2])
        solution.variables = [-7.0, 3.0, 12.0, 13.4]

        mutated_solution = operator.execute(solution)
        for i in range(solution.number_of_variables):
            self.assertGreaterEqual(mutated_solution.variables[i], solution.lower_bound[i])
            self.assertLessEqual(mutated_solution.variables[i], solution.upper_bound[i])
Пример #23
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x = solution.variables

        solution.objectives[0] = 1.7057 * x[0] * (10 * self.g1(x) + 1)
        solution.objectives[1] = 1.7957 * (1 - sqrt(x[0])) * (10 * self.g2(x) + 1)

        self.evaluate_constraints(solution)

        return solution
Пример #24
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x = solution.variables

        solution.objectives[0] = x[0] + self.g1(x)
        solution.objectives[1] = 1 - sqrt(x[0]) + self.g2(x)

        self.evaluate_constraints(solution)

        return solution
Пример #25
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.__eval_g(solution, self.M - 1)
        ft = 1.0 + 100.0 * pow(sin(0.5 * pi * self.time), 4.0)

        solution.objectives[0] = self.__eval_f1(solution, g, ft)
        solution.objectives[1] = self.__eval_fk(solution, g, 2, ft)
        solution.objectives[2] = self.__eval_fm(solution, g, ft)

        return solution
Пример #26
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.__eval_g(solution, self.limitInfII)
        h = self.__eval_h(solution.variables[0], g)

        solution.objectives[0] = self.__eval_f(solution, self.limitInfI,
                                               self.limitSupI)
        solution.objectives[1] = g * h

        return solution
Пример #27
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        solution.objectives[0] = (1.0 - exp(-4.0 * solution.variables[0]) *
                                  (sin(6.0 * pi * solution.variables[0]))**6.0)

        g = self.eval_g(solution)
        h = self.eval_h(solution.objectives[0], g)
        solution.objectives[1] = h * g

        return solution
Пример #28
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x = solution.variables

        solution.objectives[0] = x[0] + 10 * self.g1(x) + 0.7057
        solution.objectives[1] = 1 - x[0] * x[0] + 10 * self.g2(x) + 7057

        self.evaluate_constraints(solution)

        return solution
Пример #29
0
    def create_solution(self) -> FloatSolution:
        new_solution = FloatSolution(
            self.lower_bound,
            self.lower_bound,
            number_of_objectives=self.number_of_objectives)
        new_solution.variables[0] = random.uniform(self.lower_bound[0],
                                                   self.upper_bound[0])

        return new_solution
Пример #30
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x = solution.variables
        solution.objectives[0] = 4.0 * x[0] * x[0] + 4 * x[1] * x[1]
        solution.objectives[1] = (x[0] - 5.0) * (x[0] - 5.0) + (x[1] - 5.0) * (
            x[1] - 5.0)

        self.__evaluate_constraints(solution)

        return solution
Пример #31
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x = solution.variables

        solution.objectives[0] = (1.7057 + self.g1(x)) * cos(0.5 * pi * x[0]) * cos(0.5 * pi + x[1])
        solution.objectives[1] = (1.7057 + self.g1(x)) * cos(0.5 * pi * x[0]) * sin(0.5 * pi + x[1])
        solution.objectives[2] = (1.7057 + self.g1(x)) * sin(0.5 * pi + x[0])

        self.evaluate_constraints(solution)

        return solution
Пример #32
0
 def evaluate(self, solution: FloatSolution) -> FloatSolution:
     solution.objectives[0] = 1 - math.exp(-1 * sum([
         math.pow((solution.variables[i] - (1 / math.sqrt(3))), 2.0)
         for i in range(self.number_of_variables)
     ]))
     solution.objectives[1] = 1 - math.exp(-1 * sum([
         math.pow((solution.variables[i] + (1 / math.sqrt(3))), 2.0)
         for i in range(self.number_of_variables)
     ]))
     return solution
 def create_solution(self):
     """ Creates a new solution based on the bounds and variables. """
     new_solution = FloatSolution(self.lower_bound, self.upper_bound,
                                  self.number_of_objectives,
                                  self.number_of_constraints)
     new_solution.variables = np.random.uniform(
         self.lower_bound, self.upper_bound, self.number_of_variables
     ).tolist(
     ) if not self._initial_solutions else self._initial_solutions.pop()
     return new_solution
Пример #34
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        g = self.eval_g(solution)

        solution.objectives[
            0] = 0.5 * solution.variables[0] * solution.variables[1] * (1 + g)
        solution.objectives[1] = 0.5 * solution.variables[0] * (
            1 - solution.variables[1]) * (1 + g)
        solution.objectives[2] = 0.5 * (1 - solution.variables[0]) * (1 + g)

        return solution
Пример #35
0
    def test_should_the_solution_change__if_the_probability_is_one(self):
        operator = PolynomialMutation(1.0)
        solution = FloatSolution([-5, -5, -5], [5, 5, 5], 2)
        solution.variables = [1.0, 2.0, 3.0]
        FloatSolution.lower_bound = [-5, -5, -5]
        FloatSolution.upper_bound = [5, 5, 5]

        mutated_solution = operator.execute(solution)

        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Пример #36
0
    def test_should_dominance_comparator_work_properly_case_3(self):
        """ Case d: solution1 has objectives [-1.0, 5.0, 9.0] and solution2 has [-2.0, 5.0, 10.0]
        """
        solution = FloatSolution(3, 3, 0, [], [])
        solution2 = FloatSolution(3, 3, 0, [], [])

        solution.objectives = [-1.0, 5.0, 9.0]
        solution2.objectives = [-2.0, 5.0, 10.0]

        self.assertEqual(0, self.comparator.compare(solution, solution2))
Пример #37
0
 def evaluate(self, solution: FloatSolution) -> FloatSolution:
     alpha = solution.variables[0]
     beta = solution.variables[1]
     constant_factor = solution.variables[-1]
     gamma = (constant_factor * alpha * escape_velocity) / radius
     solution.variables[2] = gamma
     delta = solution.variables[3]
     solution.objectives[0] = f1([alpha, beta])
     solution.objectives[1] = f2([gamma, delta])
     return solution
Пример #38
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        fx = [0.0 for _ in range(self.number_of_objectives)]
        for i in range(self.number_of_variables - 1):
            xi = solution.variables[i] * solution.variables[i]
            xj = solution.variables[i + 1] * solution.variables[i + 1]
            aux = -0.2 * sqrt(xi + xj)
            fx[0] += -10 * exp(aux)
            fx[1] += pow(abs(solution.variables[i]), 0.8) + 5.0 * sin(pow(solution.variables[i], 3.0))

        solution.objectives[0] = fx[0]
        solution.objectives[1] = fx[1]

        return solution
Пример #39
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        x0 = solution.variables[0]
        x1 = solution.variables[1]

        f1 = (x0 - 2) * (x0 - 2) / 2.0 + (x1 + 1) * (x1 + 1) / 13.0 + 3.0
        f2 = (x0 + x1 - 3.0) * (x0 + x1 - 3.0) / 36.0 + (-x0 + x1 + 2.0) * (-x0 + x1 + 2.0) / 8.0 - 17.0
        f3 = (x0 + 2 * x1 - 1) * (x0 + 2 * x1 - 1) / 175.0 + (2 * x1 - x0) * (2 * x1 - x0) / 17.0 - 13.0

        solution.objectives[0] = f1
        solution.objectives[1] = f2
        solution.objectives[2] = f3

        return solution
Пример #40
0
 def execute(self, solution: FloatSolution) -> FloatSolution:
     for i in range(solution.number_of_variables):
         rand = random.random()
         if rand <= self.probability:
             solution.variables[i] = solution.lower_bound[i] + \
                                     (solution.upper_bound[i] - solution.lower_bound[i]) * random.random()
     return solution
Пример #41
0
    def execute(self, solution: FloatSolution) -> FloatSolution:
        for i in range(solution.number_of_variables):
            rand = random.random()

            if rand <= self.probability:
                y = solution.variables[i]
                yl, yu = solution.lower_bound[i], solution.upper_bound[i]

                if yl == yu:
                    y = yl
                else:
                    delta1 = (y - yl) / (yu - yl)
                    delta2 = (yu - y) / (yu - yl)
                    rnd = random.random()
                    mut_pow = 1.0 / (self.distribution_index + 1.0)
                    if rnd <= 0.5:
                        xy = 1.0 - delta1
                        val = 2.0 * rnd + (1.0 - 2.0 * rnd) * (pow(xy, self.distribution_index + 1.0))
                        deltaq = pow(val, mut_pow) - 1.0
                    else:
                        xy = 1.0 - delta2
                        val = 2.0 * (1.0 - rnd) + 2.0 * (rnd - 0.5) * (pow(xy, self.distribution_index + 1.0))
                        deltaq = 1.0 - pow(val, mut_pow)

                    y += deltaq * (yu - yl)
                    if y < solution.lower_bound[i]:
                        y = solution.lower_bound[i]
                    if y > solution.upper_bound[i]:
                        y = solution.upper_bound[i]

                solution.variables[i] = y

        return solution
Пример #42
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        total = 0.0
        for x in solution.variables:
            total += x * x

        solution.objectives[0] = total

        return solution
Пример #43
0
    def read_front_from_file_as_solutions(file_path: str) -> List[S]:
        """ Reads a front from a file and returns a list of solution objects.

        :return: List of solution objects. """
        front = []
        if Path(file_path).is_file():
            with open(file_path) as file:
                for line in file:
                    vector = [float(x) for x in line.split()]
                    solution = FloatSolution(2, 2, 0, [], [])
                    solution.objectives = vector

                    front.append(solution)
        else:
            raise Exception('Reference front file was not found at {}'.format(file_path))

        return front
Пример #44
0
    def test_should_copy_work_properly(self) -> None:
        solution = FloatSolution(2, 3, 2, [0.0, 0.5], [1.0, 2.0])
        solution.variables = [1.24, 2.66]
        solution.objectives = [0.16, -2.34, 9.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.number_of_constraints, new_solution.number_of_constraints)
        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.assertIs(solution.lower_bound, solution.lower_bound)
        self.assertIs(solution.upper_bound, solution.upper_bound)
        self.assertEqual({}, new_solution.attributes)
Пример #45
0
    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)

        overall_constraint_violation = 0.0
        number_of_violated_constraints = 0.0

        for constrain in constraints:
            if constrain < 0.0:
                overall_constraint_violation += constrain
                number_of_violated_constraints += 1

        solution.attributes['overall_constraint_violation'] = overall_constraint_violation
        solution.attributes['number_of_violated_constraints'] = number_of_violated_constraints
Пример #46
0
    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] = 1.0 - (x1 * x1 + x2 * x2) / 225.0
        constraints[1] = (3.0 * x2 - x1) / 10.0 - 1.0

        overall_constraint_violation = 0.0
        number_of_violated_constraints = 0.0

        for constrain in constraints:
            if constrain < 0.0:
                overall_constraint_violation += constrain
                number_of_violated_constraints += 1

        solution.attributes['overall_constraint_violation'] = overall_constraint_violation
        solution.attributes['number_of_violated_constraints'] = number_of_violated_constraints
Пример #47
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        k = self.number_of_variables - self.number_of_objectives + 1

        g = sum([(x - 0.5) * (x - 0.5) for x in solution.variables[self.number_of_variables - k:]])

        solution.objectives = [1.0 + g] * self.number_of_objectives

        for i in range(self.number_of_objectives):
            for j in range(self.number_of_objectives - (i + 1)):
                solution.objectives[i] *= cos(solution.variables[j] * 0.5 * pi)

            if i != 0:
                solution.objectives[i] *= sin(0.5 * pi * solution.variables[self.number_of_objectives - (i + 1)])

        return solution
Пример #48
0
    def execute(self, solution: FloatSolution) -> FloatSolution:
        for i in range(solution.number_of_variables):
            rand = random.random()

            if rand <= self.probability:
                tmp = (random.random() - 0.5) * self.perturbation
                tmp += solution.variables[i]

                if tmp < solution.lower_bound[i]:
                    tmp = solution.lower_bound[i]
                elif tmp > solution.upper_bound[i]:
                    tmp = solution.upper_bound[i]

                solution.variables[i] = tmp

        return solution
Пример #49
0
    def test_should_dominance_comparator_work_properly_with_constrains_case_2(self):
        """ Case 2: solution1 has a lower degree of constraint violation than solution 2
        """
        solution1 = FloatSolution(3, 3, 0, [], [])
        solution2 = FloatSolution(3, 3, 0, [], [])
        solution1.attributes["overall_constraint_violation"] = -0.3
        solution2.attributes["overall_constraint_violation"] = -0.1

        solution1.objectives = [-1.0, 5.0, 9.0]
        solution2.objectives = [-2.0, 5.0, 10.0]

        self.assertEqual(1, self.comparator.compare(solution1, solution2))
Пример #50
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        k = self.number_of_variables - self.number_of_objectives + 1

        g = sum([(x - 0.5) * (x - 0.5) - cos(20.0 * pi * (x - 0.5))
                 for x in solution.variables[self.number_of_variables - k:]])

        g = 100 * (k + g)

        solution.objectives = [(1.0 + g) * 0.5] * self.number_of_objectives

        for i in range(self.number_of_objectives):
            for j in range(self.number_of_objectives - (i + 1)):
                solution.objectives[i] *= solution.variables[j]

            if i != 0:
                solution.objectives[i] *= 1 - solution.variables[self.number_of_objectives - (i + 1)]

        return solution
Пример #51
0
    def evaluate(self, solution: FloatSolution):
        solution.objectives[0] = 1.2
        solution.objectives[1] = 2.3

        return solution
Пример #52
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        n = self.number_of_variables
        solution.objectives[0] = 1 - exp(-sum([(x - 1.0 / n ** 0.5) ** 2 for x in solution.variables]))
        solution.objectives[1] = 1 - exp(-sum([(x + 1.0 / n ** 0.5) ** 2 for x in solution.variables]))

        return solution
Пример #53
0
    def evaluate(self, solution: FloatSolution) -> FloatSolution:
        solution.objectives[0] = solution.variables[0]
        solution.objectives[1] = solution.variables[1]

        return solution