jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
497 stars 150 forks source link

How can we save all solutions (both dominated and non-dominated)? (All function evaluations) #131

Closed mishras9 closed 2 years ago

mishras9 commented 2 years ago

How can I save all dominated and non-dominated solutions ?

For population= 100, number of generations= 10, I want to save all dominated and non-dominated solutions i.e., 100 pareto solutions and 900 non-pareto solutions from a total of 1000 functional evaluations. @ajnebro

from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import SBXCrossover, PolynomialMutation
from jmetal.util.termination_criterion import StoppingByEvaluations
from jmetal.util.observer import ProgressBarObserver
from jmetal.algorithm.multiobjective.smpso import SMPSO
from jmetal.operator import PolynomialMutation
from jmetal.util.archive import CrowdingDistanceArchive
from jmetal.algorithm.multiobjective.spea2 import SPEA2
from jmetal.lab.experiment import Experiment, Job, generate_summary_from_experiment
from jmetal.core.observer import Observer
from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver
import time

problem = MyProblem()

MFES= 1000

import time

start_time1 = time.process_time()
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=100,
                     offspring_population_size=100,
                     mutation=PolynomialMutation(probability=0.01, distribution_index=20),
                     crossover=SBXCrossover(probability=0.9, distribution_index=15),
                     termination_criterion=StoppingByEvaluations(max_evaluations=MFES)),
                    algorithm_tag='NSGAII',
                    problem_tag='My_Problem',
                    run=run,
                )
            )
    return jobs

if __name__ == '__main__':
    # Configure the experiments
    jobs = configure_experiment(problems={'My_Problem': MyProblem()}, n_run=5)
    # Run the study
    output_directory = 'P100G10'
    experiment = Experiment(output_dir=output_directory, jobs=jobs)
    experiment.run()
print("--- %s seconds ---" % (time.process_time() - start_time1))

@TimJay @Juanjdurillo @ajnebro @Canicio @cbarba