コード例 #1
0
def Experiment(seedstrings):
    problem = MADM()
    seedset = []
    while len(seedset) <= N_seeds:
        for string in seedstrings:
            seed = problem.create_solution()
            seed.variables = string
            seedset.append(seed)

    max_evaluations = 100000
    #algorithm = SPEA2(
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=IntegerPolynomialMutation(probability=0.1),
        crossover=IntegerCrossover(probability=0.9),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        population_generator=InjectorGenerator(seedset))

    resultsets = algorithm.run()
    process = []
    for g in range(len(resultsets)):
        process.append(get_non_dominated_solutions(resultsets[g]))

    return process, algorithm.get_result()
コード例 #2
0
 def test_NSGAII(self):
     NSGAII(problem=self.problem,
            population_size=self.population_size,
            offspring_population_size=self.offspring_size,
            mutation=self.mutation,
            crossover=self.crossover,
            termination_criterion=StoppingByEvaluations(max=1000)).run()
コード例 #3
0
def run_optimization(max_eval, num_nodes, pop_size, offspring, trial_name, year):

    os_fold = os_sep()
    if not os.path.exists('results' + os_fold + year):
        os.makedirs('results' + os_fold + year)

    multiprocessing.freeze_support()
    problem = cequal()
    max_evaluations = max_eval


    algorithm = NSGAII(
        population_evaluator=MultiprocessEvaluator(num_nodes),
        problem=problem,
        population_size=pop_size,
        offspring_population_size=offspring,
        mutation=PolynomialMutation(probability= 0.2, distribution_index=20),
        crossover=SBXCrossover(probability=0.8, distribution_index=20),
        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
        dominance_comparator=DominanceComparator()
    )

    algorithm.observable.register(ProgressBarObserver(max=max_evaluations))
    algorithm.observable.register(observer=BasicObserver())

    algorithm.run()
    print(os.getcwd())
    front = algorithm.get_result()

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time/3600))

    print_function_values_to_file(front, 'results' + os_fold + year + os_fold + 'OBJ_' + algorithm.get_name() + "_" + trial_name + '.txt')
    print_variables_to_file(front, 'results' + os_fold + year + os_fold + 'VAR_' + algorithm.get_name() + "_" + trial_name + '.txt')
コード例 #4
0
ファイル: comparison.py プロジェクト: jMetal/jMetalPy
def configure_experiment(problems: dict, n_run: int):
    jobs = []
    max_evaluations = 25000

    for run in range(n_run):
        for problem_tag, problem in problems.items():
            jobs.append(
                Job(
                    algorithm=NSGAII(
                        problem=problem,
                        population_size=100,
                        offspring_population_size=100,
                        mutation=PolynomialMutation(
                            probability=1.0 / problem.number_of_variables,
                            distribution_index=20),
                        crossover=SBXCrossover(probability=1.0,
                                               distribution_index=20),
                        termination_criterion=StoppingByEvaluations(
                            max_evaluations=max_evaluations),
                    ),
                    algorithm_tag="NSGAII",
                    problem_tag=problem_tag,
                    run=run,
                ))
            jobs.append(
                Job(
                    algorithm=GDE3(
                        problem=problem,
                        population_size=100,
                        cr=0.5,
                        f=0.5,
                        termination_criterion=StoppingByEvaluations(
                            max_evaluations=max_evaluations),
                    ),
                    algorithm_tag="GDE3",
                    problem_tag=problem_tag,
                    run=run,
                ))
            jobs.append(
                Job(
                    algorithm=SMPSO(
                        problem=problem,
                        swarm_size=100,
                        mutation=PolynomialMutation(
                            probability=1.0 / problem.number_of_variables,
                            distribution_index=20),
                        leaders=CrowdingDistanceArchive(100),
                        termination_criterion=StoppingByEvaluations(
                            max_evaluations=max_evaluations),
                    ),
                    algorithm_tag="SMPSO",
                    problem_tag=problem_tag,
                    run=run,
                ))

    return jobs
コード例 #5
0
 def test_NSGAII(self):
     NSGAII(
         problem=self.problem,
         population_size=self.population_size,
         offspring_population_size=self.offspring_size,
         mutation=self.mutation,
         crossover=self.crossover,
         selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator()),
         termination_criterion=StoppingByEvaluations(max=1000)
     ).run()
コード例 #6
0
    def train(self):
        problem = BinProblem(X=self.Xtrain,
                             Y=self.Ytrain,
                             kernel=self.kernel,
                             gamma=self.gamma,
                             degree=self.degree,
                             C=self.C,
                             coef0=self.coef0)

        max_evaluations = self.maxEvaluations
        algorithm = NSGAII(
            problem=problem,
            population_size=self.popsize,
            offspring_population_size=self.popsize,
            mutation=BitFlipMutation(probability=1.0 /
                                     np.shape(self.Xtrain)[0]),
            crossover=SPXCrossover(probability=1.0),
            termination_criterion=StoppingByEvaluations(max=max_evaluations))

        algorithm.run()
        front = algorithm.get_result()

        normed_matrix = normalize(
            list(map(lambda result: result.objectives, front)))

        scores = list(map(lambda item: sum(item), normed_matrix))
        solution = front[scores.index(min(scores))]

        self.instances = solution.variables[0]
        self.attributes = solution.variables[1]

        X = self.Xtrain[self.instances, :]
        X = X[:, self.attributes]
        Y = self.Ytrain[self.instances]

        self.model = SVC(gamma=self.gamma,
                         C=self.C,
                         degree=self.degree,
                         kernel=self.kernel)
        self.model.fit(X=X, y=Y)

        return self.model
コード例 #7
0
    def configurar_NSGAII(self):


        algorithm = NSGAII(
                problem=self.problema,
                population_size=self.maxima_poblacion,
                offspring_population_size=self.maxima_poblacion,
                mutation=PolynomialMutation(probability = self.probabilidad , distribution_index=0.20),
                crossover=SBXCrossover(probability= self.probabilidad, distribution_index=20),
                termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones),
                dominance_comparator=DominanceComparator())
        return algorithm
コード例 #8
0
ファイル: ittest_algorithm.py プロジェクト: jMetal/jMetalPy
    def test_should_NSGAII_work_when_solving_problem_ZDT1_with_standard_settings(self):
        problem = ZDT1()

        max_evaluations = 25000

        algorithm = NSGAII(
            problem=problem,
            population_size=100,
            offspring_population_size=100,
            mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
            crossover=SBXCrossover(probability=1.0, distribution_index=20),
            termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
        )

        algorithm.run()
        front = algorithm.get_result()

        hv = HyperVolume(reference_point=[1, 1])
        value = hv.compute([front[i].objectives for i in range(len(front))])

        self.assertTrue(value >= 0.65)
コード例 #9
0
 def __NSGAII(self) -> None:
     assert 'mutation' in self.__option
     assert 'crossover' in self.__option
     assert 'max_evaluation' in self.__option
     assert 'tolerance' in self.__option
     self.__solver = NSGAII(
         problem=self.__problem,
         population_size=POPULATION_SIZE,
         offspring_population_size=OFFSPRING_SIZE,
         # mutation=BitFlipMutation(probability=1.0/self.__problem.number_of_variables),
         mutation=BitFlipMutation(probability=self.__option['mutation']),
         crossover=SPXCrossover(probability=self.__option['crossover']),
         termination_criterion=StoppingByEvaluations(max_evaluations=MAX_EVALUATION)
         # termination_criterion=Terminator(max_evaluation=self.__option['max_evaluation'], tolerance=self.__option['tolerance'])
     )
コード例 #10
0
ファイル: Teste.py プロジェクト: ASdOliveira/OTN_Mastering
def configure_experiment(problems: dict, n_run: int):
    jobs = []

    for run in range(n_run):
        for problem_tag, problem in problems.items():
            jobs.append(
                Job(
                    algorithm=NSGAII(
                        problem=problem,
                        population_size=20,
                        offspring_population_size=20,
                        mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20),
                        crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20),
                        # termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
                        termination_criterion=stopCriterion
                    ),
                    algorithm_tag='NSGAII',
                    problem_tag=problem_tag,
                    run=run,
                )
            )
            jobs.append(
                Job(
                    algorithm=SPEA2(
                        problem=problem,
                        population_size=20,
                        offspring_population_size=20,
                        mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20),
                        crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20),
                        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
                    ),
                    algorithm_tag='SPEA2',
                    problem_tag=problem_tag,
                    run=run,
                )
            )
    return jobs
コード例 #11
0
def nsgaii_train(particoes, regras, instancias, classes):
    problem = MixedIntegerFloatProblem(particoes, regras, instancias, classes)

    max_evaluations = 10
    algorithm = NSGAII(
        problem=problem,
        population_size=10,
        offspring_population_size=10,
        mutation=CompositeMutation([IntegerPolynomialMutation(0.05, 20),
                                    IntegerPolynomialMutation(0.05, 20),
                                    PolynomialMutation(0.05, 20.0)]),
        crossover=CompositeCrossover([IntegerSBXCrossover(probability=0.95, distribution_index=20),
                                      IntegerSBXCrossover(probability=0.95, distribution_index=20),
                                      SBXCrossover(probability=0.95, distribution_index=20)]),
        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
    )

    algorithm.run()
    front = get_non_dominated_solutions(algorithm.get_result())

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + algorithm.label)
    print_variables_to_file(front, 'VAR.' + algorithm.label)

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))

    minAcuracia = 0
    index = -1
    for i, f in enumerate(front):
        if minAcuracia > f.objectives[0]:
            minAcuracia =  f.objectives[0]
            index = i

    #for variable in front[index].variables:
       #print(variable.variables)


    particoes = problem.alterar_centroids(front[index].variables[2].variables)
    new_regras = problem.cromossomo_para_regras(front[index].variables[0].variables, front[index].variables[1].variables, problem.semente.qtdAntecedenteRegra, particoes)
    return particoes, new_regras
コード例 #12
0
ファイル: nsgaii_ssp.py プロジェクト: abfarr/moo2020
        5488, 1129, 1111, 7597, 5406, 2134, 7280, 6465, 4084, 8564, 2593, 9954,
        4731, 1347, 8984, 5057, 3429, 7635, 1323, 1146, 5192, 6547, 343, 7584,
        3765, 8660, 9318, 5098, 5185, 9253, 4495, 892, 5080, 5297, 9275, 7515,
        9729, 6200, 2138, 5480, 860, 8295, 8327, 9629, 4212, 3087, 5276, 9250,
        1835, 9241, 1790, 1947, 8146, 8328, 973, 1255, 9733, 4314, 6912, 8007,
        8911, 6802, 5102, 5451, 1026, 8029, 6628, 8121, 5509, 3603, 6094, 4447,
        683, 6996, 3304, 3130, 2314, 7788, 8689, 3253, 5920, 3660, 2489, 8153,
        2822, 6132, 7684, 3032, 9949, 59, 6669, 6334
    ]

    problem = SubsetSum(C, W)

    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=BitFlipMutation(probability=0.5),
        crossover=SPXCrossover(probability=0.8),
        termination_criterion=StoppingByEvaluations(max_evaluations=25000))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + algorithm.label)
    print_variables_to_file(front, 'VAR.' + algorithm.label)

    print(f'Algorithm: ${algorithm.get_name()}')
    print(f'Problem: ${problem.get_name()}')
    print(f'Computing time: ${algorithm.total_computing_time}')
コード例 #13
0
    def configurar_algoritmo(self,
                             hora_show: datetime,
                             hora_minima: datetime = datetime.time(0, 0),
                             algoritmo: str = 'MOGA',
                             mutation_probability: float = 0.25,
                             max_evaluations: int = 500,
                             population: int = 100):
        hora_minima, hora_show = self.restricciones_hora(
            hora_minima, hora_show)
        if (hora_minima == 0):
            hora_minima = hora_show - 180
        restricciones_baja = list([hora_minima, -100, -100, 0, 0])
        restricciones_alta = list([hora_show, 0, 0, 100, 100])

        self.problem = HVAC(lower_bound=restricciones_baja,
                            upper_bound=restricciones_alta,
                            number_of_configurations=3)

        print("algoritmo: ", algoritmo)
        if algoritmo == 'MOGA':
            algorithm = MOGA(problem=self.problem,
                             population_size=population,
                             offspring_population_size=population,
                             mutation=IntegerPolynomialMutationD(
                                 probability=mutation_probability,
                                 distribution_index=20),
                             crossover=SBXCrossoverD(
                                 probability=mutation_probability,
                                 distribution_index=20),
                             termination_criterion=StoppingByEvaluations(
                                 max=max_evaluations),
                             dominance_comparator=DominanceComparator())

        elif algoritmo == "NSGAII":
            algorithm = NSGAII(problem=self.problem,
                               population_size=population,
                               offspring_population_size=population,
                               mutation=IntegerPolynomialMutationD(
                                   probability=mutation_probability,
                                   distribution_index=20),
                               crossover=SBXCrossoverD(
                                   probability=mutation_probability,
                                   distribution_index=20),
                               termination_criterion=StoppingByEvaluations(
                                   max=max_evaluations),
                               dominance_comparator=DominanceComparator())

        elif algoritmo == 'OMOPSO':
            algorithm = OMOPSO(problem=self.problem,
                               swarm_size=population,
                               epsilon=0.0075,
                               uniform_mutation=UniformMutation(
                                   probability=mutation_probability,
                                   perturbation=0.5),
                               non_uniform_mutation=NonUniformMutation(
                                   probability=mutation_probability,
                                   perturbation=0.5),
                               leaders=CrowdingDistanceArchive(100),
                               termination_criterion=StoppingByEvaluations(
                                   max=max_evaluations))

        elif algoritmo == 'SMPSO':
            algorithm = SMPSO(problem=self.problem,
                              swarm_size=population,
                              mutation=IntegerPolynomialMutation(
                                  probability=mutation_probability,
                                  distribution_index=20),
                              leaders=CrowdingDistanceArchive(100),
                              termination_criterion=StoppingByEvaluations(
                                  max=max_evaluations))

        elif algoritmo == 'SPEA2':
            algorithm = SPEA2(problem=self.problem,
                              population_size=population,
                              offspring_population_size=population,
                              mutation=IntegerPolynomialMutationD(
                                  probability=mutation_probability,
                                  distribution_index=20),
                              crossover=SBXCrossoverD(
                                  probability=mutation_probability,
                                  distribution_index=20),
                              termination_criterion=StoppingByEvaluations(
                                  max=max_evaluations),
                              dominance_comparator=DominanceComparator())

        else:
            print("Algoritmo no válido. Creando MOGA por defecto...")
            algorithm = MOGA(problem=self.problem,
                             population_size=population,
                             offspring_population_size=population,
                             mutation=IntegerPolynomialMutationD(
                                 probability=mutation_probability,
                                 distribution_index=20),
                             crossover=SBXCrossoverD(
                                 probability=mutation_probability,
                                 distribution_index=20),
                             termination_criterion=StoppingByEvaluations(
                                 max=max_evaluations),
                             dominance_comparator=DominanceComparator())
        self.algoritmo = algorithm
        self.algoritmo.observable.register(observer=ProgressBarObserver(
            max=max_evaluations))

        return algorithm
コード例 #14
0
ファイル: gnsgaii.py プロジェクト: dg310012/Sequoya
    # creates the problem
    problem = BAliBASE(
        instance='BB20019',
        path='../resources',
        score_list=[SumOfPairs(),
                    PercentageOfTotallyConservedColumns()])

    # creates the algorithm
    max_evaluations = 25000
    reference_point = [-0.6, 11000]

    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=ShiftClosedGapGroups(probability=0.3),
        crossover=SPXMSA(probability=0.7),
        dominance_comparator=GDominanceComparator(reference_point),
        termination_criterion=StoppingByEvaluations(
            max_evaluations=max_evaluations))

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=PlotFrontToFileObserver(
        output_directory='fronts_zdt1'))

    algorithm.run()
    front = algorithm.get_result()

    # plot front
    plot_front = Plot(title='Pareto front approximation',
コード例 #15
0
ファイル: eacomparison.py プロジェクト: pg42862/mewpy
def configure_experiment(problems: dict, n_run: int):
    """Configures the experiments

    Args:
        problems (dict): The MEWpy optimization problem
        n_run (int): the number of runs of each MOEA

    Returns:
        a list of jobs
    """

    from mewpy.optimization.jmetal.operators import UniformCrossoverOU, GrowMutationOU, ShrinkMutation, \
        SingleMutationOU, MutationContainer
    crossover = UniformCrossoverOU(0.5, max_size=candidate_max_size)
    mutators = []
    mutators.append(GrowMutationOU(1.0, max_size=candidate_max_size))
    mutators.append(ShrinkMutation(1.0, min_size=candidate_max_size))
    mutators.append(SingleMutationOU(1.0))
    mutation = MutationContainer(0.3, mutators=mutators)

    jobs = []

    for run in range(n_run):
        for problem_tag, problem in problems.items():
            jobs.append(
                Job(
                    algorithm=NSGAII(
                        problem=problem,
                        population_evaluator=MultiprocessEvaluator(N_CPU),
                        population_size=100,
                        offspring_population_size=100,
                        mutation=mutation,
                        crossover=crossover,
                        termination_criterion=StoppingByEvaluations(
                            max_evaluations=max_evaluations)),
                    algorithm_tag='NSGAII',
                    problem_tag=problem_tag,
                    run=run,
                ))
            jobs.append(
                Job(algorithm=SPEA2(
                    problem=problem,
                    population_evaluator=MultiprocessEvaluator(N_CPU),
                    population_size=100,
                    offspring_population_size=100,
                    mutation=mutation,
                    crossover=crossover,
                    termination_criterion=StoppingByEvaluations(
                        max_evaluations=max_evaluations)),
                    algorithm_tag='SPEA2',
                    problem_tag=problem_tag,
                    run=run))
            jobs.append(
                Job(
                    algorithm=IBEA(
                        problem=problem,
                        population_evaluator=MultiprocessEvaluator(N_CPU),
                        kappa=1.,
                        population_size=100,
                        offspring_population_size=100,
                        mutation=mutation,
                        crossover=crossover,
                        termination_criterion=StoppingByEvaluations(
                            max_evaluations=max_evaluations)),
                    algorithm_tag='IBEA',
                    problem_tag=problem_tag,
                    run=run,
                ))

    return jobs
コード例 #16
0
Net = Network(folderName="Topologia2")

for executions in range(timesToRun):
    print("Interation number:", executions)

    problem = OTNProblem(Net, len(Net.LinkBundles))
    max_evaluations = 1000
    # stopCriterion = StoppingByEvaluationsCustom(max_evaluations, [200, 2.1])  # To topology 1, 200 is enough

    algorithm = NSGAII(problem=problem,
                       population_size=20,
                       offspring_population_size=20,
                       mutation=IntegerPolynomialMutation(
                           probability=0.05, distribution_index=20),
                       crossover=IntegerSBXCrossover(probability=0.3,
                                                     distribution_index=20),
                       termination_criterion=StoppingByEvaluationsCustom(
                           max_evaluations=max_evaluations,
                           reference_point=[5000, 2.1],
                           AlgorithmName='Reference')
                       # termination_criterion=stopCriterion
                       )

    progress_bar = ProgressBarObserver(max=max_evaluations)
    algorithm.observable.register(progress_bar)

    algorithm.run()
    solutions = algorithm.get_result()

    for solution in solutions:
        if not solution.objectives[1] >= 1.3:
コード例 #17
0
from jmetal.util.termination_criterion import StoppingByEvaluations
""" 
Distributed (synchronous) version of NSGA-II using Apache Spark.
"""

if __name__ == "__main__":
    problem = ZDT1Modified()

    max_evaluations = 100

    algorithm = NSGAII(
        problem=problem,
        population_size=10,
        offspring_population_size=10,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=20),
        population_evaluator=SparkEvaluator(),
        termination_criterion=StoppingByEvaluations(
            max_evaluations=max_evaluations),
    )

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, "FUN." + algorithm.label)
    print_variables_to_file(front, "VAR." + algorithm.label)

    print(f"Algorithm: {algorithm.get_name()}")
    print(f"Problem: {problem.get_name()}")
コード例 #18
0
#print(smrseeds)

#Experiments
#No seeds: MOEAs
noseedprocessruns = []
reference = []
#noseedfront = []
for i in range(run):
    problem = MADM()
    seedset = []
    max_evaluations = 100000
    #algorithm = SPEA2(
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=IntegerPolynomialMutation(probability=0.1),
        crossover=IntegerCrossover(probability=0.9),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
    )

    # algorithm.observable.register(observer=ProgressBarObserver(max=max_evaluations))
    # algorithm.observable.register(observer=VisualizerObserver())

    resultsets = algorithm.run()
    #print(len(resultsets))
    process = []
    for g in range(len(resultsets)):
        process.append(get_non_dominated_solutions(resultsets[g]))

    front = get_non_dominated_solutions(algorithm.get_result())  #process[-1]
    process.append(front)
コード例 #19
0
ファイル: nsgaii_ssp.py プロジェクト: pombredanne/jMetalPy
        5488, 1129, 1111, 7597, 5406, 2134, 7280, 6465, 4084, 8564, 2593, 9954,
        4731, 1347, 8984, 5057, 3429, 7635, 1323, 1146, 5192, 6547, 343, 7584,
        3765, 8660, 9318, 5098, 5185, 9253, 4495, 892, 5080, 5297, 9275, 7515,
        9729, 6200, 2138, 5480, 860, 8295, 8327, 9629, 4212, 3087, 5276, 9250,
        1835, 9241, 1790, 1947, 8146, 8328, 973, 1255, 9733, 4314, 6912, 8007,
        8911, 6802, 5102, 5451, 1026, 8029, 6628, 8121, 5509, 3603, 6094, 4447,
        683, 6996, 3304, 3130, 2314, 7788, 8689, 3253, 5920, 3660, 2489, 8153,
        2822, 6132, 7684, 3032, 9949, 59, 6669, 6334
    ]

    problem = SubsetSum(C, W)

    algorithm = NSGAII(problem=problem,
                       population_size=100,
                       offspring_population_size=100,
                       mutation=BitFlipMutation(probability=0.5),
                       crossover=SPXCrossover(probability=0.8),
                       selection=BinaryTournamentSelection(
                           comparator=RankingAndCrowdingDistanceComparator()),
                       termination_criterion=StoppingByEvaluations(max=25000))

    progress_bar = ProgressBarObserver(max=25000)
    algorithm.observable.register(observer=progress_bar)

    algorithm.run()
    front = algorithm.get_result()

    print('Algorithm (binary problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
コード例 #20
0
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import BitFlipMutation, SPXCrossover
from jmetal.problem.multiobjective.unconstrained import OneZeroMax
from jmetal.util.observer import ProgressBarObserver, VisualizerObserver
from jmetal.util.solutions import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    binary_string_length = 512
    problem = OneZeroMax(binary_string_length)

    max_evaluations = 50000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=BitFlipMutation(probability=1.0 / binary_string_length),
        crossover=SPXCrossover(probability=1.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver())

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(
        front, 'FUN.' + algorithm.get_name() + "-" + problem.get_name())
    print_variables_to_file(
コード例 #21
0
                                               k=self.number_of_variables)

        return new_solution

    def get_name(self):
        return 'MultiObjective TSP'


if __name__ == '__main__':
    problem = NSGA()
    max_evaluations = 20000
    algorithm = NSGAII(
        problem=problem,
        population_size=20,
        offspring_population_size=20,
        mutation=PermutationSwapMutation(probability=0.2),
        # crossover=PMXCrossover(probability=0.9),
        crossover=Order1Crossover(probability=0.9),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
    )
    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver(
        reference_front=problem.reference_front))

    algorithm.run()
    front = algorithm.get_result()

    # Plot front
    plot_front = Plot(plot_title='Pareto front approximation',
                      reference_front=problem.reference_front,
コード例 #22
0
    def train(self):
        problem = Ejemplo(X=self.Xtrain,
                          Y=self.Ytrain,
                          kernel=self.kernel,
                          gamma=self.gamma,
                          degree=self.degree,
                          C=self.C,
                          coef0=self.coef0)
        #problem.reference_front = read_solutions(filename='resources/reference_front/ZDT1.pf')

        max_evaluations = self.maxEvaluations
        algorithm = NSGAII(
            problem=problem,
            population_size=self.popsize,
            offspring_population_size=self.popsize,
            mutation=BitFlipMutation(probability=1.0 /
                                     np.shape(self.Xtrain)[0]),
            crossover=SPXCrossover(probability=1.0),
            termination_criterion=StoppingByEvaluations(max=max_evaluations))

        algorithm.observable.register(observer=ProgressBarObserver(
            max=max_evaluations))
        #algorithm.observable.register(observer=VisualizerObserver(reference_front=problem.reference_front))

        algorithm.run()
        front = algorithm.get_result()

        # Plot front
        plot_front = Plot(plot_title='Pareto front approximation',
                          reference_front=None,
                          axis_labels=problem.obj_labels)
        plot_front.plot(front,
                        label=algorithm.label,
                        filename=algorithm.get_name())

        # Plot interactive front
        plot_front = InteractivePlot(plot_title='Pareto front approximation',
                                     axis_labels=problem.obj_labels)
        plot_front.plot(front,
                        label=algorithm.label,
                        filename=algorithm.get_name())

        # Save results to file
        print_function_values_to_file(front, 'FUN.' + algorithm.label)
        print_variables_to_file(front, 'VAR.' + algorithm.label)
        print('Algorithm (continuous problem): ' + algorithm.get_name())

        # Get normalized matrix of results
        normed_matrix = normalize(
            list(map(lambda result: result.objectives, front)))

        # Get the sum of each objective results and select the best (min)
        scores = list(map(lambda item: sum(item), normed_matrix))
        solution = front[scores.index(min(scores))]

        self.instances = solution.variables[0]
        self.attributes = solution.variables[1]

        # Generate masks
        # Crop by characteristics and instances
        X = self.Xtrain[self.instances, :]
        X = X[:, self.attributes]
        Y = self.Ytrain[self.instances]

        self.model = SVC(gamma=self.gamma,
                         C=self.C,
                         degree=self.degree,
                         kernel=self.kernel)
        self.model.fit(X=X, y=Y)

        # write your code here
        return self.model
コード例 #23
0
    Pnmut: float = 0.2
    Tel: float = 0.5
    Pmut: float = 0.05
    generations: int = 50
    pop_size: int = 30
    Cr: float = 0.5
    max_evaluations: float = generations * pop_size
    problem: MulticastProblem = MulticastProblem(
        Graph=gr, root_node=root_node, destination_nodes=destination_nodes)
    algorithm = NSGAII(problem=problem,
                       population_size=pop_size,
                       offspring_population_size=int(pop_size * Cr),
                       mutation=MulticastMutation(probability=Pmut,
                                                  Pnmut=Pnmut,
                                                  G=gr),
                       crossover=MulticastCrossover(
                           probability=1.0,
                           root_node=root_node,
                           destination_nodes=destination_nodes,
                           graph=gr),
                       termination_criterion=StoppingByEvaluations(
                           max_evaluations=max_evaluations))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + algorithm.label)
    print_variables_to_file(front, 'VAR.' + algorithm.label)

    plot_front = Plot(title='Pareto front approximation',
コード例 #24
0
from jmetal.util.observer import ProgressBarObserver, VisualizerObserver
from jmetal.util.solutions import read_solutions, print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations
from jmetal.lab.visualization import Plot, InteractivePlot

if __name__ == '__main__':
    problem = ZDT1()
    problem.reference_front = read_solutions(
        filename='resources/reference_front/ZDT1.pf')

    max_evaluations = 25000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=20),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver(
        reference_front=problem.reference_front))

    algorithm.run()
    front = algorithm.get_result()

    # Plot front
    plot_front = Plot(plot_title='Pareto front approximation',
コード例 #25
0
    Goal_num = Configuration.goal_num


    """===============================实例化问题对象============================"""
    problem = TurnRightProblem(Goal_num, Configuration)

    """=================================算法参数设置============================"""
    max_evaluations = Configuration.maxIterations

    if Configuration.algorithm == "NSGA_II":
        algorithm = NSGAII(
            population_evaluator=MultiprocessEvaluator(Configuration.ProcessNum),
            # population_evaluator=SequentialEvaluator(),
            problem=problem,
            population_size = Configuration.population,
            offspring_population_size = Configuration.population,
            mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
            crossover=SBXCrossover(probability=1.0, distribution_index=20),
            termination_criterion = StoppingByEvaluations(max_evaluations=max_evaluations)
            # termination_criterion = StoppingByQualityIndicator(quality_indicator=FitnessValue, expected_value=1, degree=0.9)
            # selection = BinaryTournamentSelection()
        )
    elif Configuration.algorithm == "NSGA_III" or Configuration.algorithm == "NSGA_III_Adapt":
        algorithm = NSGAIII(
            population_evaluator=MultiprocessEvaluator(Configuration.ProcessNum),
            problem=problem,
            population_size = Configuration.population,
            reference_directions=UniformReferenceDirectionFactory(Configuration.goal_num, n_points= Configuration.population - 1),
            # offspring_population_size = Configuration.population,
            mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
            crossover=SBXCrossover(probability=1.0, distribution_index=20),
            termination_criterion = StoppingByEvaluations(max_evaluations=max_evaluations)
コード例 #26
0
from jmetal.util.comparator import DominanceComparator
from jmetal.util.observer import PrintObjectivesObserver
from jmetal.util.solutions_utils import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    binary_string_length = 512
    problem = OneMax(binary_string_length)

    max_evaluations = 20000

    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=1,
        mutation=BitFlipMutation(probability=1.0 / binary_string_length),
        crossover=SPXCrossover(probability=1.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        dominance_comparator=DominanceComparator()
    )

    algorithm.observable.register(observer=PrintObjectivesObserver(1000))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, 'FUN.'+ algorithm.get_name()+"-"+problem.get_name())
    print_variables_to_file(front, 'VAR.' + algorithm.get_name()+"-"+problem.get_name())

    print('Algorithm (continuous problem): ' + algorithm.get_name())
コード例 #27
0
if __name__ == '__main__':
    problem = ZDT2()
    problem.reference_front = read_solutions(
        filename='../../../resources/reference_front/{}.pf'.format(
            problem.get_name()))

    reference_point = [0.8, 0.5]

    max_evaluations = 25000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=20),
        selection=BinaryTournamentSelection(
            comparator=RankingAndCrowdingDistanceComparator()),
        dominance_comparator=GDominanceComparator(reference_point),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(
        observer=VisualizerObserver(reference_front=problem.reference_front,
                                    reference_point=(reference_point)))

    algorithm.run()
    front = algorithm.get_result()
コード例 #28
0
    print_variables_to_file,
)
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == "__main__":
    problem = MixedIntegerFloatProblem(10, 10, 100, -100, -1000, 1000)

    max_evaluations = 25000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=CompositeMutation([
            IntegerPolynomialMutation(0.01, 20),
            PolynomialMutation(0.01, 20.0)
        ]),
        crossover=CompositeCrossover([
            IntegerSBXCrossover(probability=1.0, distribution_index=20),
            SBXCrossover(probability=1.0, distribution_index=20),
        ]),
        termination_criterion=StoppingByEvaluations(
            max_evaluations=max_evaluations),
    )

    algorithm.run()
    front = get_non_dominated_solutions(algorithm.get_result())

    # Save results to file
    print_function_values_to_file(front, "FUN." + algorithm.label)
    print_variables_to_file(front, "VAR." + algorithm.label)
コード例 #29
0
from jmetal.operator import SBXCrossover, PolynomialMutation
from jmetal.problem.singleobjective.unconstrained import Rastrigin
from jmetal.util.observer import PrintObjectivesObserver
from jmetal.util.solutions import print_function_values_to_file, print_variables_to_file
from jmetal.util.solutions.comparator import DominanceComparator
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    problem = Rastrigin(10)

    max_evaluations = 50000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20.0),
        crossover=SBXCrossover(probability=0.9, distribution_index=20.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        dominance_comparator=DominanceComparator())

    algorithm.observable.register(observer=PrintObjectivesObserver(1000))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(
        front, 'FUN.' + algorithm.get_name() + "-" + problem.get_name())
    print_variables_to_file(
        front, 'VAR.' + algorithm.get_name() + "-" + problem.get_name())
コード例 #30
0
ファイル: nsgaii_binary.py プロジェクト: msteijaert/jMetalPy
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import BitFlipMutation, SPXCrossover
from jmetal.problem.multiobjective.unconstrained import OneZeroMax
from jmetal.util.solution import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    binary_string_length = 512
    problem = OneZeroMax(binary_string_length)

    max_evaluations = 50000
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=100,
        mutation=BitFlipMutation(probability=1.0 / binary_string_length),
        crossover=SPXCrossover(probability=1.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + algorithm.label)
    print_variables_to_file(front, 'VAR.' + algorithm.label)

    print(f'Algorithm: ${algorithm.get_name()}')
    print(f'Problem: ${problem.get_name()}')
    print(f'Computing time: ${algorithm.total_computing_time}')