### Install jMetalPy from source Source: https://github.com/jmetal/jmetalpy/blob/main/docs/source/getting-started.rst Steps to clone the repository from GitHub and install the package using setup.py. ```console git clone https://github.com/jMetal/jMetalPy.git python setup.py install ``` -------------------------------- ### Dynamic NSGA-II Example Usage Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/eas/nsgaii_dynamic.html An example demonstrating how to instantiate and run the Dynamic NSGA-II algorithm. ```APIDOC ## Example Usage of Dynamic NSGA-II ### Description This example shows how to configure and execute the Dynamic NSGA-II algorithm with specific problem, operators, and observers. ### Code ```python from jmetal.algorithm.multiobjective.nsgaii import DynamicNSGAII from jmetal.operator.crossover import SBXCrossover from jmetal.operator.mutation import PolynomialMutation from jmetal.problem.multiobjective.fda import FDA2 from jmetal.util.observable import TimeCounter from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver from jmetal.util.termination_criterion import StoppingByEvaluations # Problem definition problem = FDA2() # Time counter for dynamic problems time_counter = TimeCounter(delay=1) time_counter.observable.register(problem) time_counter.start() # Algorithm configuration max_evaluations = 25000 algorithm = DynamicNSGAII( 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) ) # Observers for visualization and logging algorithm.observable.register(observer=PlotFrontToFileObserver('front_plot')) algorithm.observable.register(observer=WriteFrontToFileObserver('front_files')) # Run the algorithm algorithm.run() ``` ``` -------------------------------- ### Dynamic SMPSO Example Usage Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/psos/smpso_dynamic.ipynb.txt An example demonstrating how to instantiate and run the DynamicSMPSO algorithm with specific problem, operators, observers, and termination criteria. ```APIDOC ## Dynamic SMPSO Example ### Description This example shows how to configure and execute the DynamicSMPSO algorithm for solving a multi-objective optimization problem. It utilizes `FDA2` as the problem, `PolynomialMutation` for mutation, `CrowdingDistanceArchive` for leader selection, and includes observers for plotting and writing fronts to files, with termination based on a maximum number of evaluations. ### Method Python script using jmetalpy library. ### Endpoint N/A (Local execution) ### Parameters - **problem**: The optimization problem to solve (e.g., `FDA2`). - **swarm_size**: The size of the particle swarm. - **mutation**: The mutation operator to use (e.g., `PolynomialMutation`). - **leaders**: The archive used to store leaders (e.g., `CrowdingDistanceArchive`). - **termination_criterion**: The criterion to stop the algorithm (e.g., `StoppingByEvaluations`). ### Request Example ```python from jmetal.algorithm.multiobjective.smpso import DynamicSMPSO from jmetal.operator.mutation import PolynomialMutation from jmetal.problem.multiobjective.fda import FDA2 from jmetal.util.archive import CrowdingDistanceArchive from jmetal.util.observable import TimeCounter from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver from jmetal.util.termination_criterion import StoppingByEvaluations problem = FDA2() time_counter = TimeCounter(delay=15) time_counter.observable.register(problem) time_counter.start() max_evaluations = 25000 algorithm = DynamicSMPSO( problem=problem, swarm_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.observable.register(observer=PlotFrontToFileObserver('front_plot')) algorithm.observable.register(observer=WriteFrontToFileObserver('front_files')) algorithm.run() ``` ### Response - **front**: The final front of non-dominated solutions. ### Response Example (The output is typically a set of files generated by the observers, e.g., front files and plot files, and the final front of solutions.) ``` -------------------------------- ### SMPSO/RP Algorithm Example Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/psos/smpso_preference.html This example demonstrates how to use the SMPSO/RP algorithm with ZDT4 problem, including setting up reference points, archives, and termination criteria. ```APIDOC ## SMPSO/RP Algorithm Example ### Description This example shows how to instantiate and run the SMPSO/RP algorithm for a multi-objective optimization problem. ### Method Instantiation and execution of the SMPSO/RP algorithm. ### Endpoint N/A (This is a code example, not an API endpoint) ### Parameters N/A ### Request Example ```python from jmetal.algorithm.multiobjective.smpso import SMPSORP from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT4 from jmetal.util.archive import CrowdingDistanceArchiveWithReferencePoint from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT4() swarm_size = 100 reference_point = [[0.1, 0.8], [0.6, 0.1]] archives_with_reference_points = [] for point in reference_point: archives_with_reference_points.append( CrowdingDistanceArchiveWithReferencePoint(int(swarm_size / len(reference_point)), point) ) max_evaluations = 50000 algorithm = SMPSORP( problem=problem, swarm_size=swarm_size, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), reference_points=reference_point, leaders=archives_with_reference_points, termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.run() solutions = algorithm.get_result() # Visualization (optional) from jmetal.lab.visualization.plotting import Plot from jmetal.util.solution import get_non_dominated_solutions front = get_non_dominated_solutions(solutions) plot_front = Plot(plot_title='Pareto front approximation', axis_labels=['x', 'y'], reference_point=reference_point) plot_front.plot(front, label='SMPSORP-ZDT4') ``` ### Response N/A (This is a code execution example) ### Response Example N/A ``` -------------------------------- ### Dynamic SMPSO Example Usage Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/psos/smpso_dynamic.html A Python code example demonstrating how to instantiate and run the DynamicSMPSO algorithm with a dynamic problem. ```APIDOC ## Example: Dynamic SMPSO ### Description This example shows how to set up and execute the DynamicSMPSO algorithm for a dynamic multi-objective optimization problem (FDA2). ### Code ```python from jmetal.algorithm.multiobjective.smpso import DynamicSMPSO from jmetal.operator.mutation import PolynomialMutation from jmetal.problem.multiobjective.fda import FDA2 from jmetal.util.archive import CrowdingDistanceArchive from jmetal.util.observable import TimeCounter from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver from jmetal.util.termination_criterion import StoppingByEvaluations # Problem definition problem = FDA2() # Observers and counters time_counter = TimeCounter(delay=15) time_counter.observable.register(problem) time_counter.start() # Algorithm configuration max_evaluations = 25000 algorithm = DynamicSMPSO( problem=problem, swarm_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations(max=max_evaluations) ) # Register observers for visualization and output algorithm.observable.register(observer=PlotFrontToFileObserver('front_plot')) algorithm.observable.register(observer=WriteFrontToFileObserver('front_files')) # Run the algorithm algorithm.run() ``` ``` -------------------------------- ### NSGA-II Algorithm Usage Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/eas/nsgaii.html Example of how to instantiate and run the NSGA-II algorithm for multi-objective optimization. ```APIDOC ## NSGA-II Algorithm Usage ### Description This example demonstrates how to initialize and execute the NSGA-II algorithm with a specific problem, population settings, mutation, crossover, and termination criterion. ### Method Instantiation and execution of the `NSGAII` class. ### Endpoint N/A (This is a code example, not an API endpoint) ### Parameters * `problem` (Problem) - The optimization problem to solve. * `population_size` (int) - The number of individuals in the population. * `offspring_population_size` (int) - The number of offspring to generate. * `mutation` (Mutation) - The mutation operator. * `crossover` (Crossover) - The crossover operator. * `termination_criterion` (TerminationCriterion) - The criterion to stop the algorithm. ### Request Example ```python from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.operator.crossover import SBXCrossover from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT1 from jmetal.util.termination_criterion import StoppingByEvaluations 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=max_evaluations) ) algorithm.run() solutions = algorithm.get_result() ``` ### Response * `solutions` (list) - A list of solutions representing the Pareto front approximation. ``` -------------------------------- ### Install jMetalPy with pip Source: https://github.com/jmetal/jmetalpy/blob/main/README.md Installs the jMetalPy library using pip. Additional dependencies for distributed computing can be installed with 'jmetalpy[distributed]'. ```console pip install jmetalpy pip install "jmetalpy[distributed]" pip install "jmetalpy[dev]" pip install "jmetalpy[complete]" ``` -------------------------------- ### Install jMetalPy via pip Source: https://github.com/jmetal/jmetalpy/blob/main/docs/source/getting-started.rst Commands to install the jMetalPy library using pip. Includes options for core components, documentation, distributed computing, and complete installations. ```console pip install jmetalpy pip install "jmetalpy[core]" pip install "jmetalpy[docs]" pip install "jmetalpy[distributed]" pip install "jmetalpy[complete]" ``` -------------------------------- ### SMPSO/RP Algorithm Example Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/psos/smpso_preference.ipynb.txt This snippet demonstrates how to set up and run the SMPSO/RP algorithm with a specified problem, mutation operator, reference points, and termination criterion. ```APIDOC ## SMPSO/RP Algorithm Example ### Description This code snippet shows how to initialize and execute the SMPSO/RP (Strength Multi-Objective Particle Swarm Optimization with Reference Points) algorithm. It involves defining the problem, setting up the swarm size, defining reference points for the archive, and configuring the termination criterion. ### Method N/A (This is a Python script demonstrating algorithm execution) ### Endpoint N/A ### Parameters - **problem**: The optimization problem to solve (e.g., ZDT4). - **swarm_size**: The number of particles in the swarm. - **mutation**: The mutation operator to be used (e.g., PolynomialMutation). - **reference_points**: A list of reference points used for the archive. - **leaders**: A list of archives, each associated with a reference point. - **termination_criterion**: The condition to stop the algorithm's execution (e.g., StoppingByEvaluations). ### Request Example ```python from jmetal.algorithm.multiobjective.smpso import SMPSORP from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT4 from jmetal.util.archive import CrowdingDistanceArchiveWithReferencePoint from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT4() swarm_size = 100 reference_point = [[0.1, 0.8],[0.6, 0.1]] archives_with_reference_points = [] for point in reference_point: archives_with_reference_points.append( CrowdingDistanceArchiveWithReferencePoint(int(swarm_size / len(reference_point)), point) ) max_evaluations = 50000 algorithm = SMPSORP( problem=problem, swarm_size=swarm_size, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), reference_points=reference_point, leaders=archives_with_reference_points, termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.run() solutions = algorithm.get_result() ``` ### Response #### Success Response (200) - **solutions** (list): A list of solutions representing the Pareto front approximation. #### Response Example ```json { "solutions": [ { "objectives": [0.1, 0.2], "variables": [0.5, 0.6] }, { "objectives": [0.3, 0.4], "variables": [0.7, 0.8] } ] } ``` ``` -------------------------------- ### Initialize SMPSO Algorithm Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/psos/smpso.html Demonstrates the instantiation of the SMPSO algorithm class. It requires a problem definition, swarm size, mutation operator, and optional archive and comparator configurations. ```python from jmetal.algorithm.multiobjective.smpso import SMPSO from jmetal.operator import PolynomialMutation from jmetal.util.archive import CrowdingDistanceArchive algorithm = SMPSO( problem=problem, swarm_size=100, mutation=PolynomialMutation(probability=1.0/problem.number_of_variables), leaders=CrowdingDistanceArchive(100) ) ``` -------------------------------- ### Initialize and Run SMPSORP Algorithm Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/psos/smpso_preference.html This snippet demonstrates how to configure the SMPSORP algorithm using the ZDT4 problem, define reference points, and execute the optimization process with a specified termination criterion. ```python from jmetal.algorithm.multiobjective.smpso import SMPSORP from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT4 from jmetal.util.archive import CrowdingDistanceArchiveWithReferencePoint from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT4() swarm_size = 100 reference_point = [[0.1, 0.8],[0.6, 0.1]] archives_with_reference_points = [] for point in reference_point: archives_with_reference_points.append( CrowdingDistanceArchiveWithReferencePoint(int(swarm_size / len(reference_point)), point) ) max_evaluations = 50000 algorithm = SMPSORP( problem=problem, swarm_size=swarm_size, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), reference_points=reference_point, leaders=archives_with_reference_points, termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.run() solutions = algorithm.get_result() ``` -------------------------------- ### Interactive Plotting Example Source: https://github.com/jmetal/jmetalpy/blob/main/docs/tutorials/visualization.html Example of how to create and plot an interactive Pareto front using the InteractivePlot class. ```APIDOC ## Example Usage ### Description This example demonstrates how to instantiate the `InteractivePlot` class and use its `plot` method to visualize a Pareto front. ### Code ```python from jmetal.lab.visualization.interactive import InteractivePlot # Assuming 'front' is a list of solutions obtained from an algorithm # and 'NSGAII-ZDT1' is the label for this front. plot_front = InteractivePlot(title='Pareto front approximation') plot_front.plot(front, label='NSGAII-ZDT1', filename='NSGAII-ZDT1-interactive') ``` ### Parameters Used in Example - **front**: A list of solutions. - **label**: 'NSGAII-ZDT1' - The name given to this Pareto front. - **filename**: 'NSGAII-ZDT1-interactive' - The name of the output file for the interactive plot. ``` -------------------------------- ### Install jMetalPy via CLI Source: https://github.com/jmetal/jmetalpy/blob/main/docs/getting-started.html Commands to install the jMetalPy library using pip or by building from the source code repository. ```bash pip install jmetalpy git clone https://github.com/jMetal/jMetalPy.git python setup.py install ``` -------------------------------- ### Initialize LZ09 Problem Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/problem/multiobjective/lz09.html Instantiates the LZ09 benchmark problem with specific configuration parameters. ```APIDOC ## POST /jmetal/problem/multiobjective/lz09 ### Description Initializes a new instance of the LZ09 multi-objective optimization problem. ### Method POST ### Endpoint /jmetal/problem/multiobjective/lz09 ### Parameters #### Request Body - **number_of_variables** (int) - Required - The number of decision variables in the problem. - **ptype** (int) - Required - The type of Pareto set shape. - **dtype** (int) - Required - The distance function type. - **ltype** (int) - Required - The linkage function type. ### Request Example { "number_of_variables": 10, "ptype": 21, "dtype": 1, "ltype": 1 } ### Response #### Success Response (200) - **status** (string) - Success message indicating the problem is initialized. #### Response Example { "status": "LZ09 problem initialized" } ``` -------------------------------- ### Install jMetalPy via Command Line Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/getting-started.rst.txt Commands to install the jMetalPy library and its various dependency sets using pip or by cloning the source repository. ```console pip install jmetalpy pip install "jmetalpy[core]" pip install "jmetalpy[docs]" pip install "jmetalpy[distributed]" pip install "jmetalpy[complete]" git clone https://github.com/jMetal/jMetalPy.git python setup.py install ``` -------------------------------- ### Initialize and Execute Local Search Algorithm Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/singleobjective/local.search.html Demonstrates the lifecycle methods for a LocalSearch algorithm instance. This includes initializing the process, performing iterative steps, and checking for completion. ```python algorithm = LocalSearch(problem=problem) algorithm.init_progress() while not algorithm.stopping_condition_is_met(): algorithm.step() algorithm.update_progress() result = algorithm.result() ``` -------------------------------- ### Configure and Run Dynamic NSGA-II Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/eas/nsgaii_dynamic.ipynb.txt This snippet demonstrates the setup of the Dynamic NSGA-II algorithm, including the registration of a time-based observer for dynamic problem changes and the configuration of output observers for tracking the Pareto front. ```python from jmetal.algorithm.multiobjective.nsgaii import DynamicNSGAII from jmetal.operator.crossover import SBXCrossover from jmetal.operator.mutation import PolynomialMutation from jmetal.problem.multiobjective.fda import FDA2 from jmetal.util.observable import TimeCounter from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver from jmetal.util.termination_criterion import StoppingByEvaluations problem = FDA2() time_counter = TimeCounter(delay=1) time_counter.observable.register(problem) time_counter.start() max_evaluations = 25000 algorithm = DynamicNSGAII( 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=PlotFrontToFileObserver('front_plot')) algorithm.observable.register(observer=WriteFrontToFileObserver('front_files')) algorithm.run() ``` -------------------------------- ### Running Experiments Source: https://github.com/jmetal/jmetalpy/blob/main/docs/source/tutorials/experiment.rst This snippet demonstrates how to configure and run an experimental study. It defines jobs for different algorithms (NSGA-II, GDE3, SMPSO) and problems (ZDT1, ZDT2, ZDT3), sets up termination criteria, and then initiates the experiment run. ```APIDOC ## Running Experiments ### Description This section outlines the process of setting up and executing an experimental study using jMetalPy. It involves defining various jobs, each consisting of an algorithm, a problem, and specific run parameters. The experiment is then initiated and executed. ### Method Python Script ### Endpoint N/A (Local Execution) ### Parameters N/A ### Request Example ```python from jmetal.algorithm.multiobjective.gde3 import GDE3 from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.algorithm.multiobjective.smpso import SMPSO from jmetal.core.quality_indicator import * from jmetal.lab.experiment import Experiment, Job, generate_summary_from_experiment from jmetal.operator import PolynomialMutation, SBXCrossover from jmetal.problem import ZDT1, ZDT2, ZDT3 from jmetal.util.archive import CrowdingDistanceArchive from jmetal.util.termination_criterion import StoppingByEvaluations 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=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=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=max_evaluations) ), algorithm_tag='SMPSO', problem_tag=problem_tag, run=run, ) ) return jobs if __name__ == '__main__': # Configure the experiments jobs = configure_experiment(problems={'ZDT1': ZDT1(), 'ZDT2': ZDT2(), 'ZDT3': ZDT3()}, n_run=31) # Run the study output_directory = 'data' experiment = Experiment(output_dir=output_directory, jobs=jobs) experiment.run() ``` ### Response N/A (This is a script execution) ### Response Example N/A ``` -------------------------------- ### GDE3 Algorithm Usage Example Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/multiobjective/eas/gde3.html This example demonstrates how to use the GDE3 algorithm to solve the ZDT1 multi-objective optimization problem and visualize the resulting Pareto front approximation. ```APIDOC ## GDE3 Algorithm Usage Example ### Description This example demonstrates how to instantiate and run the GDE3 algorithm for a multi-objective optimization problem (ZDT1) and then visualize the obtained Pareto front approximation. ### Method ```python from jmetal.algorithm.multiobjective.gde3 import GDE3 from jmetal.problem import ZDT1 from jmetal.util.termination_criterion import StoppingByEvaluations # Problem definition problem = ZDT1() # Algorithm configuration max_evaluations = 25000 algorithm = GDE3( problem=problem, population_size=100, cr=0.5, # Crossover probability f=0.5, # Mutation factor termination_criterion=StoppingByEvaluations(max_evaluations) ) # Run the algorithm algorithm.run() solutions = algorithm.get_result() # Visualization from jmetal.lab.visualization.plotting import Plot from jmetal.util.solution import get_non_dominated_solutions front = get_non_dominated_solutions(solutions) plot_front = Plot(plot_title='Pareto front approximation', axis_labels=['x', 'y']) plot_front.plot(front, label='GDE3-ZDT1') ``` ### Parameters - `problem` (Problem): The optimization problem to solve. - `population_size` (int): The number of individuals in the population. - `cr` (float): The crossover probability. - `f` (float): The mutation factor. - `termination_criterion` (TerminationCriterion): The criterion to stop the algorithm. - `k` (float, optional): Parameter for the algorithm. Defaults to 0.5. - `population_generator` (Generator, optional): Generator for the initial population. Defaults to RandomGenerator. - `population_evaluator` (Evaluator, optional): Evaluator for the population. Defaults to SequentialEvaluator. - `dominance_comparator` (Comparator, optional): Comparator for dominance ranking. Defaults to DominanceComparator. ### Response Example ```json { "solutions": [ { "objectives": [0.1, 0.9], "variables": [0.2, 0.8] }, { "objectives": [0.3, 0.7], "variables": [0.4, 0.6] } ] } ``` ``` -------------------------------- ### SMPSORP Algorithm Initialization in Python Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/multiobjective/smpso.html Initializes the SMPSORP algorithm, setting up problem parameters, swarm configuration, mutation strategies, reference points, and termination criteria. It also manages swarm generation and evaluation, and starts a background thread for reference point updates. ```python class SMPSORP(SMPSO): def __init__( self, problem: FloatProblem, swarm_size: int, mutation: Mutation, reference_points: List[List[float]], leaders: List[ArchiveWithReferencePoint], termination_criterion: TerminationCriterion, swarm_generator: Generator = store.default_generator, swarm_evaluator: Evaluator = store.default_evaluator, ): """This class implements the SMPSORP algorithm. :param problem: The problem to solve. :param swarm_size: :param mutation: :param leaders: List of bounded archives. :param swarm_evaluator: An evaluator object to evaluate the solutions in the population. """ super(SMPSORP, self).__init__( problem=problem, swarm_size=swarm_size, mutation=mutation, leaders=None, swarm_generator=swarm_generator, swarm_evaluator=swarm_evaluator, termination_criterion=termination_criterion, ) self.leaders = leaders self.reference_points = reference_points self.lock = threading.Lock() thread = threading.Thread(target=_change_reference_point, args=(self,)) thread.start() ``` -------------------------------- ### GET /algorithm/spea2/name Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/multiobjective/spea2.html Returns the identifier name of the algorithm. ```APIDOC ## GET /algorithm/spea2/name ### Description Returns the string name of the algorithm implementation. ### Method GET ### Endpoint /algorithm/spea2/name ### Response #### Success Response (200) - **name** (string) - The name of the algorithm, which is 'SPEA2'. #### Response Example { "name": "SPEA2" } ``` -------------------------------- ### Integration with Algorithms Source: https://github.com/jmetal/jmetalpy/blob/main/docs/source/advanced-topics/distance-based-archive.rst Conceptual example of integrating DistanceBasedArchive with optimization algorithms. ```APIDOC ## Integration with Algorithms ### Description This section provides a conceptual overview of how `DistanceBasedArchive` can be integrated with optimization algorithms that support archives. Note that actual integration might require modifications to the specific algorithm implementation. ### Method N/A (Conceptual) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.util.archive import DistanceBasedArchive from jmetal.problem import ZDT1 # Create algorithm with custom archive problem = ZDT1() archive = DistanceBasedArchive(maximum_size=100) # Note: This is conceptual - actual integration depends on algorithm design # Some algorithms may need modification to accept custom archives # Example: algorithm = NSGAII(problem=problem, population_size=100, archive=archive) print("Conceptual integration example: NSGAII with DistanceBasedArchive") ``` ### Response N/A (Conceptual Code) ``` -------------------------------- ### Preference Point-based NSGA-II Algorithm Setup and Execution (Python) Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/eas/nsgaii_preference.ipynb.txt This snippet sets up and runs the NSGA-II algorithm using a specified reference point for preference. It configures the problem, operators, and termination criterion. The algorithm is then executed, and the resulting solutions are retrieved. Dependencies include jmetalpy's algorithm, operator, problem, and utility modules. ```Python from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.operator.crossover import SBXCrossover from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT2 from jmetal.util.comparator import GDominanceComparator from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT2() max_evaluations = 25000 reference_point = [0.2, 0.5] 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), dominance_comparator=GDominanceComparator(reference_point), termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.run() solutions = algorithm.get_result() ``` -------------------------------- ### GET /api/algorithm/multiobjective/moead Source: https://github.com/jmetal/jmetalpy/blob/main/docs/genindex.html Retrieves the MOEAD multi-objective algorithm class definition. ```APIDOC ## GET /api/algorithm/multiobjective/moead ### Description Provides access to the MOEAD (Multi-Objective Evolutionary Algorithm based on Decomposition) implementation. ### Method GET ### Endpoint /api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD ### Parameters None ### Response #### Success Response (200) - **class** (object) - The MOEAD algorithm class definition. ``` -------------------------------- ### jmetal.algorithm.multiobjective.ibea.IBEA.create_initial_solutions Source: https://github.com/jmetal/jmetalpy/blob/main/docs/genindex.html Creates the initial population of solutions for the IBEA algorithm. ```APIDOC ## create_initial_solutions() ### Description Generates the initial population of solutions for the IBEA (Indicator-Based Evolutionary Algorithm) algorithm. ### Method (Method details not provided in the source text) ### Endpoint (Endpoint details not provided in the source text) ### Parameters (No parameters specified) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### GET /api/algorithm/multiobjective/mocell Source: https://github.com/jmetal/jmetalpy/blob/main/docs/genindex.html Retrieves the MOCell multi-objective algorithm class definition. ```APIDOC ## GET /api/algorithm/multiobjective/mocell ### Description Provides access to the MOCell multi-objective evolutionary algorithm implementation. ### Method GET ### Endpoint /api/algorithm/multiobjective/eas/mocell.html#jmetal.algorithm.multiobjective.mocell.MOCell ### Parameters None ### Response #### Success Response (200) - **class** (object) - The MOCell algorithm class definition. ``` -------------------------------- ### GET /problems/unconstrained/onezeromax Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/problem/multiobjective.html Retrieves the configuration and evaluation methods for the OneZeroMax problem. ```APIDOC ## GET /problems/unconstrained/onezeromax ### Description Provides access to the OneZeroMax problem definition, used for benchmarking optimization algorithms. ### Method GET ### Endpoint /problems/unconstrained/onezeromax ### Response #### Success Response (200) - **name** (string) - The name of the problem (OneZeroMax). - **number_of_objectives** (integer) - The number of objectives. #### Response Example { "name": "OneZeroMax", "number_of_objectives": 2 } ``` -------------------------------- ### EvolutionStrategy: Create Initial Solutions (Python) Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/singleobjective/evolution_strategy.html Generates the initial population of solutions for the evolutionary algorithm using the configured population generator. ```python def create_initial_solutions(self) -> List[S]: return [self.population_generator.new(self.problem) for _ in range(self.population_size)] ``` -------------------------------- ### GET /evolution_strategy/stopping_condition Source: https://github.com/jmetal/jmetalpy/blob/main/docs/api/algorithm/singleobjective/evolution.strategy.html Checks if the algorithm's stopping condition has been met. ```APIDOC ## GET /evolution_strategy/stopping_condition ### Description The stopping condition is met or not. ### Method GET ### Endpoint /evolution_strategy/stopping_condition ### Response #### Success Response (200) - **is_met** (bool) - Boolean indicating if the algorithm should stop. #### Response Example { "is_met": false } ``` -------------------------------- ### OMOPSO Algorithm Implementation in Python Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/multiobjective/omopso.html This snippet provides the core implementation of the OMOPSO algorithm. It includes the constructor for setting up the algorithm's parameters, such as problem definition, swarm size, mutation operators, leader archives, epsilon values, and termination criteria. It also defines methods for creating initial solutions and evaluating them. ```python import random from copy import copy from typing import List, Optional, TypeVar import numpy from jmetal.config import store from jmetal.core.algorithm import ParticleSwarmOptimization from jmetal.core.problem import FloatProblem from jmetal.core.solution import FloatSolution from jmetal.operator.mutation import NonUniformMutation from jmetal.operator.mutation import UniformMutation from jmetal.util.archive import BoundedArchive, NonDominatedSolutionsArchive from jmetal.util.comparator import DominanceComparator, EpsilonDominanceComparator from jmetal.util.evaluator import Evaluator from jmetal.util.generator import Generator from jmetal.util.termination_criterion import TerminationCriterion R = TypeVar("R") class OMOPSO(ParticleSwarmOptimization): def __init__( self, problem: FloatProblem, swarm_size: int, uniform_mutation: UniformMutation, non_uniform_mutation: NonUniformMutation, leaders: Optional[BoundedArchive], epsilon: float, termination_criterion: TerminationCriterion, swarm_generator: Generator = store.default_generator, swarm_evaluator: Evaluator = store.default_evaluator, ): super(OMOPSO, self).__init__(problem=problem, swarm_size=swarm_size) self.swarm_generator = swarm_generator self.swarm_evaluator = swarm_evaluator self.termination_criterion = termination_criterion self.observable.register(termination_criterion) self.uniform_mutation = uniform_mutation self.non_uniform_mutation = non_uniform_mutation self.leaders = leaders self.epsilon = epsilon self.epsilon_archive = NonDominatedSolutionsArchive(EpsilonDominanceComparator(epsilon)) self.c1_min = 1.5 self.c1_max = 2.0 self.c2_min = 1.5 self.c2_max = 2.0 self.r1_min = 0.0 self.r1_max = 1.0 self.r2_min = 0.0 self.r2_max = 1.0 self.weight_min = 0.1 self.weight_max = 0.5 self.change_velocity1 = -1 self.change_velocity2 = -1 self.dominance_comparator = DominanceComparator() self.speed = numpy.zeros((self.swarm_size, self.problem.number_of_variables()), dtype=float) def create_initial_solutions(self) -> List[FloatSolution]: return [self.swarm_generator.new(self.problem) for _ in range(self.swarm_size)] def evaluate(self, solution_list: List[FloatSolution]): return self.swarm_evaluator.evaluate(solution_list, self.problem) def stopping_condition_is_met(self) -> bool: return self.termination_criterion.is_met ``` -------------------------------- ### GET /problem/singleobjective/knapsack/name Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/problem/singleobjective/knapsack.html Retrieves the identifier name for the Knapsack problem instance. ```APIDOC ## GET /problem/singleobjective/knapsack/name ### Description Returns the string identifier for the Knapsack problem class. ### Method GET ### Endpoint /jmetal/problem/singleobjective/knapsack/name ### Parameters None ### Request Example N/A ### Response #### Success Response (200) - **name** (string) - The name of the problem, which is 'Knapsack'. #### Response Example { "name": "Knapsack" } ``` -------------------------------- ### Running Experiments with jMetalPy Source: https://context7.com/jmetal/jmetalpy/llms.txt This snippet demonstrates how to set up and run multi-objective optimization experiments using the Experiment class. It covers defining jobs for different algorithm-problem combinations, configuring algorithms like NSGAII and SMPSO, running the experiment with parallel execution, and generating a summary with quality indicators such as HyperVolume and InvertedGenerationalDistance. Dependencies include various algorithms, problems, and quality indicators from jMetalPy, as well as numpy. ```python from jmetal.lab.experiment import Experiment, Job, generate_summary_from_experiment from jmetal.algorithm.multiobjective import NSGAII, SMPSO from jmetal.problem.multiobjective.zdt import ZDT1, ZDT2 from jmetal.core.quality_indicator import HyperVolume, InvertedGenerationalDistance from jmetal.operator.mutation import PolynomialMutation from jmetal.operator.crossover import SBXCrossover from jmetal.util.termination_criterion import StoppingByEvaluations from jmetal.util.archive import CrowdingDistanceArchive import numpy as np # Create jobs for different algorithm/problem combinations jobs = [] n_runs = 30 for run in range(n_runs): for problem_class in [ZDT1, ZDT2]: problem = problem_class() # NSGA-II configuration nsgaii = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(1.0/problem.number_of_variables(), 20), crossover=SBXCrossover(1.0, 20), termination_criterion=StoppingByEvaluations(25000) ) jobs.append(Job(nsgaii, "NSGAII", problem.name(), run)) # SMPSO configuration smpso = SMPSO( problem=problem, swarm_size=100, mutation=PolynomialMutation(1.0/problem.number_of_variables(), 20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations(25000) ) jobs.append(Job(smpso, "SMPSO", problem.name(), run)) # Run experiment with parallel execution experiment = Experiment( output_dir="experiment_results", jobs=jobs, m_workers=4 # Number of parallel workers ) experiment.run() # Generate summary with quality indicators reference_front = np.loadtxt("ZDT1.pf") indicators = [ HyperVolume(reference_point=[1.1, 1.1]), InvertedGenerationalDistance(reference_front=reference_front) ] generate_summary_from_experiment( input_dir="experiment_results", quality_indicators=indicators, reference_fronts="reference_fronts/" ) # Creates QualityIndicatorSummary.csv with all results ``` -------------------------------- ### GET /problem/fda5/info Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/problem/multiobjective/fda.html Retrieves metadata and configuration for the FDA5 problem instance. ```APIDOC ## GET /problem/fda5/info ### Description Returns the configuration details for the FDA5 problem, including the number of variables, objectives, and bounds. ### Method GET ### Endpoint /problem/fda5/info ### Response #### Success Response (200) - **name** (string) - The name of the problem (FDA5). - **number_of_variables** (int) - Default is 12. - **number_of_objectives** (int) - Always 3. #### Response Example { "name": "FDA5", "number_of_variables": 12, "number_of_objectives": 3 } ``` -------------------------------- ### Initialize JMetalPy Solution Classes Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/eas/hype.ipynb.txt Shows the constructor implementation for the base Solution class and the FloatSolution subclass, which handle variable, objective, and constraint initialization. ```python class Solution: def __init__(self, number_of_variables, number_of_objectives, number_of_constraints=0): self.variables = [[] for _ in range(number_of_variables)] self.objectives = [0.0 for _ in range(number_of_objectives)] self.constraints = [0.0 for _ in range(number_of_constraints)] self.attributes = {} class FloatSolution(Solution): def __init__(self, lower_bound, upper_bound, number_of_objectives, number_of_constraints=0): super(FloatSolution, self).__init__(len(lower_bound), number_of_objectives, number_of_constraints) self.lower_bound = lower_bound self.upper_bound = upper_bound ``` -------------------------------- ### GET /problem/fda5/evaluate Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/problem/multiobjective/fda.html Evaluates a given solution against the FDA5 objective functions. ```APIDOC ## POST /problem/fda5/evaluate ### Description Calculates the objective values for a provided FloatSolution based on the FDA5 dynamic problem definition. ### Method POST ### Endpoint /problem/fda5/evaluate ### Parameters #### Request Body - **solution** (FloatSolution) - Required - The solution object containing decision variables to evaluate. ### Request Example { "solution": { "variables": [0.5, 0.2, 0.8, 0.1, 0.3, 0.4, 0.6, 0.7, 0.9, 0.1, 0.2, 0.5] } } ### Response #### Success Response (200) - **solution** (FloatSolution) - The solution object updated with calculated objectives. #### Response Example { "objectives": [0.45, 0.12, 0.88] } ``` -------------------------------- ### POST /algorithm/smpsorp/run Source: https://github.com/jmetal/jmetalpy/blob/main/docs/source/api/algorithm/multiobjective/psos/smpso_preference.ipynb Initializes and executes the SMPSORP (Speed-constrained Multi-Objective Particle Swarm Optimization with Reference Points) algorithm for a given problem. ```APIDOC ## POST /algorithm/smpsorp/run ### Description Configures and runs the SMPSORP algorithm with specific reference points and termination criteria. ### Method POST ### Endpoint /algorithm/smpsorp/run ### Parameters #### Request Body - **problem** (object) - Required - The optimization problem instance (e.g., ZDT4). - **swarm_size** (integer) - Required - Number of particles in the swarm. - **reference_points** (array) - Required - List of reference points for the archives. - **max_evaluations** (integer) - Required - Termination criterion based on total evaluations. ### Request Example { "problem": "ZDT4", "swarm_size": 100, "reference_points": [[0.1, 0.8], [0.6, 0.1]], "max_evaluations": 50000 } ### Response #### Success Response (200) - **solutions** (array) - The set of non-dominated solutions found by the algorithm. #### Response Example { "status": "success", "solutions": [{"objectives": [0.12, 0.78]}, {"objectives": [0.55, 0.15]}] } ``` -------------------------------- ### Implement Crossover Operators Source: https://context7.com/jmetal/jmetalpy/llms.txt Provides examples of using various crossover operators including SBX, BLX-alpha, PMX, and Differential Evolution. These operators are essential for combining parent solutions to generate offspring in evolutionary algorithms. ```python sbx = SBXCrossover(probability=0.9, distribution_index=20.0) offspring = sbx.execute([parent1, parent2]) blx = BLXAlphaCrossover(probability=0.9, alpha=0.5) offspring = blx.execute([parent1, parent2]) pmx = PMXCrossover(probability=0.9) offspring = pmx.execute([perm1, perm2]) de_crossover = DifferentialEvolutionCrossover(CR=0.5, F=0.5, K=0.5) offspring = de_crossover.execute([parent1, parent2, parent1]) ``` -------------------------------- ### Get OMOPSO Algorithm Name Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/multiobjective/omopso.html Returns the name of the OMOPSO algorithm. ```python def get_name(self) -> str: return "OMOPSO" ``` -------------------------------- ### GET /algorithm/mocell/result Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_modules/jmetal/algorithm/multiobjective/mocell.html Retrieves the final solution list from the MOCell archive. ```APIDOC ## GET /algorithm/mocell/result ### Description Returns the list of non-dominated solutions stored in the algorithm's archive. ### Method GET ### Endpoint /algorithm/mocell/result ### Response #### Success Response (200) - **solutions** (List[S]) - The list of solutions found by the algorithm. #### Response Example { "solutions": ["sol1", "sol2"] } ``` -------------------------------- ### Configure and Run IBEA Algorithm Source: https://github.com/jmetal/jmetalpy/blob/main/docs/_sources/api/algorithm/multiobjective/eas/ibea.ipynb.txt This snippet demonstrates how to initialize the IBEA algorithm with specific operators (SBXCrossover and PolynomialMutation) for the ZDT1 problem and execute it until a defined number of evaluations is reached. ```python from jmetal.algorithm.multiobjective.ibea import IBEA from jmetal.operator.crossover import SBXCrossover from jmetal.operator.mutation import PolynomialMutation from jmetal.problem import ZDT1 from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT1() max_evaluations = 25000 algorithm = IBEA( problem=problem, kappa=1., 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) ) algorithm.run() front = algorithm.get_result() ```