Giter Club home page Giter Club logo

jmetalpy's Introduction

jMetalPy

CI PyPI Python version DOI PyPI License Code style: black

A paper introducing jMetalPy is available at: https://doi.org/10.1016/j.swevo.2019.100598

Table of Contents

Installation

You can install the latest version of jMetalPy with pip,

pip install jmetalpy  # or "jmetalpy[distributed]"
Notes on installing with pip

jMetalPy includes features for parallel and distributed computing based on pySpark and Dask.

These (extra) dependencies are not automatically installed when running pip, which only comprises the core functionality of the framework (enough for most users):

pip install jmetalpy

This is the equivalent of running:

pip install "jmetalpy[core]"

Other supported commands are listed next:

pip install "jmetalpy[dev]"  # Install requirements for development
pip install "jmetalpy[distributed]"  # Install requirements for parallel/distributed computing
pip install "jmetalpy[complete]"  # Install all requirements

Hello, world! 👋

Examples of configuring and running all the included algorithms are located in the documentation.

from jmetal.algorithm.multiobjective 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()

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=25000)
)

algorithm.run()

We can then proceed to explore the results:

from jmetal.util.solution import get_non_dominated_solutions, print_function_values_to_file, print_variables_to_file

front = get_non_dominated_solutions(algorithm.result())

# save to files
print_function_values_to_file(front, 'FUN.NSGAII.ZDT1')
print_variables_to_file(front, 'VAR.NSGAII.ZDT1')

Or visualize the Pareto front approximation produced by the algorithm:

from jmetal.lab.visualization import Plot

plot_front = Plot(title='Pareto front approximation', axis_labels=['x', 'y'])
plot_front.plot(front, label='NSGAII-ZDT1', filename='NSGAII-ZDT1', format='png')

Pareto front approximation

Features

The current release of jMetalPy (v1.7.0) contains the following components:

  • Algorithms: local search, genetic algorithm, evolution strategy, simulated annealing, random search, NSGA-II, NSGA-III, SMPSO, OMOPSO, MOEA/D, MOEA/D-DRA, MOEA/D-IEpsilon, GDE3, SPEA2, HYPE, IBEA. Preference articulation-based algorithms (G-NSGA-II, G-GDE3, G-SPEA2, SMPSO/RP); Dynamic versions of NSGA-II, SMPSO, and GDE3.
  • Parallel computing based on Apache Spark and Dask.
  • Benchmark problems: ZDT1-6, DTLZ1-2, FDA, LZ09, LIR-CMOP, RWA, unconstrained (Kursawe, Fonseca, Schaffer, Viennet2), constrained (Srinivas, Tanaka).
  • Encodings: real, binary, permutations.
  • Operators: selection (binary tournament, ranking and crowding distance, random, nary random, best solution), crossover (single-point, SBX), mutation (bit-blip, polynomial, uniform, random).
  • Quality indicators: hypervolume, additive epsilon, GD, IGD.
  • Pareto front approximation plotting in real-time, static or interactive.
  • Experiment class for performing studies either alone or alongside jMetal.
  • Pairwise and multiple hypothesis testing for statistical analysis, including several frequentist and Bayesian testing methods, critical distance plots and posterior diagrams.
Scatter plot 2D Scatter plot 3D
Parallel coordinates Interactive chord plot

Changelog

  • [Current development version] The project structure has been changed from flat to src
  • [v1.7.0] Add RWA benchmark, refactor classes BinarySolution and BinaryProblem.
  • [v1.6.0] Refactor class Problem, the single-objective genetic algorithm can solve constrained problems, performance improvements in NSGA-II, generation of Latex tables summarizing the results of the Wilcoxon rank sum test, added a notebook folder with examples.
  • [v1.5.7] Use of linters for catching errors and formatters to fix style, minor bug fixes.
  • [v1.5.6] Removed warnings when using Python 3.8.
  • [v1.5.5] Minor bug fixes.
  • [v1.5.4] Refactored quality indicators to accept numpy array as input parameter.
  • [v1.5.4] Added CompositeSolution class to support mixed combinatorial problems. #69

License

This project is licensed under the terms of the MIT - see the LICENSE file for details.

jmetalpy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jmetalpy's Issues

Constraint

Hi, I'm come back.
Now, I want to restructure my problem algorithm. I want to know if the moead_lz09.py in examples.multiobjective can run the constraint problem? Because i can run the Srinivas in jmetal.problem directly.
If yes, I can safely refactor the code with reference to the example of Srinivas.
If no, I will choose jMetal instead of jMetalPy.
Thank you.

Parallelisation with Dask does not work

Hi,

The readme for jMetalPy mentions that it can be parallelised with PySpark or Dask, but doesn't mention how to do so. Is there documentation anywhere for how to configure that?

Thanks

Pareto front tracking

Hello,

Is there any functionality in place to track the progress of the non-dominated solution set (i.e. plot number of improvements versus number of function evaluations) for any given algorithm? Specifically, I would like to evaluate the search progress / performance of the NSGA-II as applied to a water quality model optimization that I am running.

Thanks,
Josh

NSGAII

Hi,

I am new to this framework so not sure if there is a problem on my side, but whenever I'm trying to run any of the NSGAII examples I get the following errors:

C:\Users---\PycharmProjects\jMetal\venv\Scripts\python.exe C:/Users/---/PycharmProjects/jMetal/Main.py
C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\dask\config.py:161: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
data = yaml.load(f.read()) or {}
Traceback (most recent call last):
File "C:/Users/---/PycharmProjects/jMetal/Main.py", line 2, in
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\jmetal\algorithm\multiobjective\nsgaii.py", line 4, in
from distributed import as_completed, Client
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed_init_.py", line 5, in
from .actor import Actor, ActorFuture
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\actor.py", line 4, in
from .client import Future, default_client
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\client.py", line 49, in
from .batched import BatchedSend
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\batched.py", line 10, in
from .core import CommClosedError
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\core.py", line 20, in
from .comm import (
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\comm_init_.py", line 27, in
register_transports()
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\comm_init
.py", line 18, in register_transports
from . import inproc
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\comm\inproc.py", line 15, in
from ..protocol import nested_deserialize
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\protocol_init
.py", line 7, in
from .cuda import cuda_serialize, cuda_deserialize
File "C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\distributed\protocol\cuda.py", line 5, in
from dask.utils import typename
ImportError: cannot import name 'typename' from 'dask.utils' (C:\Users---\PycharmProjects\jMetal\venv\lib\site-packages\dask\utils.py)

My version of jmetalpy is 0.9.0 and this happens only when I'm running the NSGAII examples.

Thank you in advance for your help.

How to decrease execution time?

Hello everybody, I'm new in JMetalPy and in multi-objective optimization in general. In my problem I have to run different times the OMOPSO algorithm, and as many data I put in my problem the execution time increases. Is it possible to run it in parallel in order to reduce the execution time?

Permutation problem operators

Hello everyone!

I have found out that Operators for permutation Problems (TSP) impose assumption about different 'depth' of Configuration variables.

More concretely, CXCrossover and ScrambleMutation operate on configuration variables as it is a nested list (e.g. configuration.variables == [[1,2,3], [1,2,3], ... [1,2,3]]).

In other hand, PermutationSwapMutation, PMXCrossover work with configuration.variables as with 'flat lists' (or, just on top level of nested lists).

As the result, it is impossible to use CXCrossover and ScrambleMutation with TSP problem:
image

Is it a bug in implementation, or the intent of these Operators is different?

P.S. Thank you for your framework, I do really like the architecture and code style 👍

Default observable list is not emptied on Jupyter Notebooks

Optimization algorithms internally use a default observable implementation from the Store:

store = _Store()

Every time a new observer (e.g., termination criterion, progress bar) is registered to an algorithm, it is added to a private list of the observable class.

In Jupyter notebooks, the re-run of a cell of the code does not empty the internal list of observables from the default observable of the algorithm, dealing with new observers being added to the list every single time. This is due to Jupyter storing the session in memory.

As for now, it is necessary to manually empty the list on every new execution:

algorithm = NSGAII(...)
+algorithm.observable.observers = []

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

Only old versions up to 0.9.0 available on pip

While the latest jmetalpy version here is 1.5.0, the latest one that can be installed through pip is 0.9.0. I don't know how pip handles version updates - is there something you can do about it?

Order 1 Crossover Opeator

I did notice that the repo doesn't have Order 1 Crossover Operator defined.
It will be helpful if you include it.

Thanks!

Suggestion of 2 new observers

Good Morning!

I would like to suggest two other observers:

"WriteSolutionsToFileObserver"

To record solutions, allowing you to examine solutions evolution over generations.

This "observer" can have the same parameters as "WriteFrontToFileObserver" (output_directory, step, silent).

Another interesting observer can also be used for both tasks: "WriteFrontAndSolutionsToFileObserver", with the same parameters.

Thank you very much.

Greetings.

Savio

Configure number of runs in a experiment

Hello, I am using the module NSGAII-SMPSO for ZDT1.py for setup an experiment, and I could not find the parameter for setup the number of runs. In JMetal for Java there is an option to select the number or runs, and given that metaheuristics are non-deterministic, it is desirable to setup the number of runs of an experiment. I made a keyword search on the repository, and I could not found the words runs. Hence, I wonder if I am missing something, or number of runs feature is not available in JMetalPy?

Regards.

Step and Silent parameters suggestions for WriteFrontToFileObserver

Good Morning! Congratulations on working with the jMetalPy framework.

I would like to suggest two parameters for the "observer" "WriteFrontToFileObserver":

  1. step = int, to record the function values ​​only at each N evaluations (similar to the PlotFrontToFileObserver).

  2. silent = boolean, to write the values ​​in the background without printing Log to output

Thank you very much.

Regards.

Savio

Solution Matrix

Hello, I am trying to optimize over a function that contains a known array of matrices A, an unknown array of matrices B, and two penalty hyperparameters c and d . Is it possible to return a solution that is an array of optimal matrices along with the two optimal values for the hyperparameters?

Currently my objective function is coded using numpy array operations (no loops), but the returned solutions contain three values rather than an array of matrices and two individual values. I'm using NSGA-II and class FloatProblem.
Thank you in advance.

Problem when performing experiments with the same algorithm for tunning transformation operators

In metaheuristics, it is necessary to tunning the parameters of an algorithm, when tackling new problems. In particular, I'm working with NSGA-II, and I'd like to tune the probability of executing transformation operators (CX for example).

Take as a example the following code:

from jmetal.algorithm import NSGAII
from jmetal.component.comparator import RankingAndCrowdingDistanceComparator
from jmetal.operator import NullMutation, SBX, BinaryTournamentSelection
from jmetal.problem import ZDT1, ZDT2
from jmetal.component.quality_indicator import HyperVolume
from jmetal.util.laboratory import experiment, display

algorithm = [
    (NSGAII, {'population_size': 100, 'max_evaluations': 25000, 'mutation': NullMutation(), 'crossover': SBX(1.0, 20),
              'selection': BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())}),
    (NSGAII, {'population_size': 100, 'max_evaluations': 25000, 'mutation': NullMutation(), 'crossover': SBX(0.7, 20),
              'selection': BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())})

]
metric = [HyperVolume(reference_point=[1, 1])]
problem = [(ZDT1, {}), (ZDT2, {})]

results = experiment(algorithm, metric, problem)
display(results)

Then I get the error below. The error in the debugger is exactly in the function def _sort_by_dimension(self, nodes, i): from the quality_indicator module.

I attached the snapshot of the variable decorated, one line before. For me it seems valid, but I do not understand why the exception?

snapshot

Connected to pydev debugger (build 182.3911.33)
2018-08-31 12:38:19,292 [MainThread  ] [DEBUG]  Problem is not instantiated by default
2018-08-31 12:38:19,292 [MainThread  ] [DEBUG]  Algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII is not instantiated by default
2018-08-31 12:38:19,293 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT1 object at 0x7fbcc1b676d8>, algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII
2018-08-31 12:39:52,314 [MainThread  ] [DEBUG]  Algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII is not instantiated by default
2018-08-31 12:39:52,317 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT1 object at 0x7fbcc1b676d8>, algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII
2018-08-31 12:41:20,350 [MainThread  ] [DEBUG]  Waiting
2018-08-31 12:41:20,351 [MainThread  ] [DEBUG]  Problem is not instantiated by default
2018-08-31 12:41:20,351 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT2 object at 0x7fbce01e46d8>, algorithm <NSGAII(Thread-6, initial)>
2018-08-31 12:42:45,406 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT2 object at 0x7fbce01e46d8>, algorithm <NSGAII(Thread-8, initial)>
2018-08-31 12:44:12,156 [MainThread  ] [DEBUG]  Waiting
Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/moar82/jMetalPy/examples/experiment/NSGAII-SMPSO for ZDT1.py", line 19, in <module>
    results = experiment(algorithm, metric, problem)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/util/laboratory.py", line 55, in experiment
    result[algorithm.get_name()].setdefault('metric', dict()).update({metric.get_name(): metric.compute(front)})
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 75, in compute
    self._pre_process(relevant_points)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 165, in _pre_process
    self._sort_by_dimension(nodes, i)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 174, in _sort_by_dimension
    decorated.sort()
TypeError: '<' not supported between instances of 'Node' and 'Node'

Process finished with exit code 1

Thanks for the support!

get_non_domiated_solutions() seems not return expected pf solutions with 3 objectives

Hello,
thanks for the great tool of jmetalpy and i use it in my optimization problems and it works quite well.
the only issue I observed is that when I run it for 3 objectives optimization,
the function get_non_domiated_solutions() seems didn't return the required PF result.
it always return 1 PF point no matter how many points the original solutions has.
to find out if this is my usage issue or potentially code risk, I try to look into the jmetalpy code and find that in:
file util/archive.py:

     def add(self, solution: S) -> bool:
        is_dominated = False
        is_contained = False

        if len(self.solution_list) == 0:
            self.solution_list.append(solution)
            return True
        else:
            number_of_deleted_solutions = 0

            # New copy of list and enumerate
            for index, current_solution in enumerate(list(self.solution_list)):
                is_dominated_flag = self.comparator.compare(solution, current_solution)
                if is_dominated_flag == -1:
                    del self.solution_list[index - number_of_deleted_solutions]
                    number_of_deleted_solutions += 1
                elif is_dominated_flag == 1:
                    is_dominated = True
                    break
                elif is_dominated_flag == 0:
                    if solution.objectives == current_solution.objectives:
                        is_contained = True
                        break

        if not is_dominated and not is_contained:
            self.solution_list.append(solution)
            return True

        return False

I am afriad that when del some member in the original list when looping it, it may deleted the unexpeced member there.
I think when during the looping of enumerate(), it will always get updated the list and then we are iterate the unexpected members

I did some simple test and find the issue:

num_deleted = 0
a = [10,11,12, 13, 14]
for i,v in enumerate(a):
    print("")
    print('i =', i, ', v = ', v)
    print('a = ',  a)

    if v % 2 == 0:
        print("condition is true, v {} deleted".format(str(a[i- num_deleted ])))
        del a[i - num_deleted]
    num_deleted += 1

print('finally, a = ', a)

what I want is to get the final a = [11, 13], but actually I got is [13, 14]

simulated annealing with dask

I am trying to run a single objective problem with simulated annealing. any way to speed up using dask? Thank you!

constraint programming

hi and tnx for great project. can u explain if our model have multiple constraint and objective function how we can implement it and use Jmetalpy?

SyntaxError: invalid syntax

Hi.
I get that output when I try to import the package: from jmetal.algorithm import NSGAII

Traceback (most recent call last):
File "Jmetal.py", line 1, in
from jmetal.algorithm import NSGAII
File "/usr/lib/python2.7/site-packages/jmetalpy-0.5.1-py2.7.egg/jmetal/init.py", line 3, in
from jmetal import algorithm
File "/usr/lib/python2.7/site-packages/jmetalpy-0.5.1-py2.7.egg/jmetal/algorithm/init.py", line 1, in
from .multiobjective.nsgaii import NSGAII
File "/usr/lib/python2.7/site-packages/jmetalpy-0.5.1-py2.7.egg/jmetal/algorithm/multiobjective/nsgaii.py", line 24
problem: Problem[S],
^
SyntaxError: invalid syntax

New Problem sets

How do I extend the problem class. I need the WFG problem sets and the MaF as well?
Is there any plans to incorporate these problem sets in the jMetalPy?

How to use Integer and Float variables in one problem?

How can I mix variables of different types or how can I set which varibles are discrete and which are contiguous like
[0, 1, 0, 2, 1.2, 0.2, 3.6, 1.5] the first four columns are discrete values and the last four columns are continuous values?

Why we should use chord diagram?

I understand that the pareto front can be visualised as function of the objective function(s) on the different axes, but why the chord diagram is a good visualization for the pareto front? My question is serious, could you provide an example of chord's diagram utility? As suggestion, could be also the spider plot a good instrument for solutions visualization?

size of examined solutions

Hi

If the leaders group holds all swarm particles (as done by initialize_global_best() and update_global_best()), then why the attached line select only 2 random solutions from the leaders (i.e., the whole swarm) to determine the global best solution?

Regards

particles = Random.sample(self.leaders.solution_list, 2)

implementación de problema genérico

Hola estimados, ayer leí el paper y me interesó bastante su proyecto. He estado buscando en la documentación pero no he encontrado algún ejemplo para algún modelo de optimización genérico, como el problema de la mochila o un problema de transporte. ¿Tienen algún ejemplo de como resolver algún problema de optimización genérico a través de las metaheurísticas del framework? Aun no logro encontrar la sintaxis para cargar mi problema de optimización en alguna de las metaheurísticas del framework. Saludos

[Question] How to start NSGA2 algorithm?

Hello!

I want to study optimizing algorithms, but i don't have background about optimizing algorithms. Can you give guide for me about what should i do first?

Thank you in advance.

Failed to open TrueType font

Dear authors:
First thanks for the source code.
I run the "moead_dtlz2.py" in the jMetalPy.examples.multiobjective and I encounter some problems. It shows"Traceback (most recent call last):
File "E:/pycham/jMetalPy/examples/multiobjective/moead_dtlz2.py", line 37, in
plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name())
File "E:\pycham\jMetalPy\jmetal\lab\visualization\plotting.py", line 73, in plot
self.three_dim(front, label, filename, format)
File "E:\pycham\jMetalPy\jmetal\lab\visualization\plotting.py", line 155, in three_dim
plt.savefig(filename + '.' + format, format=format, dpi=1000)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\pyplot.py", line 689, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\figure.py", line 2094, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure
**kwargs)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backends\backend_ps.py", line 921, in print_eps
return self._print_ps(outfile, 'eps', *args, **kwargs)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backends\backend_ps.py", line 950, in _print_ps
**kwargs)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backends\backend_ps.py", line 1180, in _print_figure
print_figure_impl(fh)
File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backends\backend_ps.py", line 1122, in print_figure_impl
fh, fonttype, glyph_ids)
RuntimeError: Failed to open TrueType font"
But when annotated "plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name())" and it can run the probably right result as well as write the result to the file.
Is there something wrong with the code?
Be patient and wait for your reply
Yours sincerely.

Handling of Constraints - Max/Mix Value Instead

Hi,

Thank you for always being so prompt with responses in the past. I have a quick question about using constraints.

I can see in the examples that you can set a constraint to a specific number - for example:
solution.constraints[0] = 1.0 - (x1 * x1 + x2 * x2) / 225.0

However, in my problem I have a maximum value (0.15) that my x1 can be as a constraint:
solution.constraints[0] = x1 <= 0.15

I was not sure how to implement that and if it is possible. From what I read from the documentation for JMetalPy you are using the implementation proposed in 'A fast and elitist multiobjective genetic algorithm' for the handling constraints which supports such a scenario.

Could you please give me some guidance on how to achieve using a max value as a constraint if possible? Thanks in advance for your input.

Kind regards,
Mila

Problem when using class RandomSearch

Hi, I am trying to run an experiment using NSGAII and randomSearch. However my script breaks when it reaches the class RandomSearch with the folloiwng error.

2018-08-30 03:22:29,075 [MainThread  ] [INFO ]  Running experiment: problem <miniaturization.Miniaturization object at 0x7f95bf2c7518>, algorithm <module 'jmetal.algorithm.multiobjective.randomSearch' from '/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/algorithm/multiobjective/randomSearch.py'>
Traceback (most recent call last):
  File "NSGAII-RS for MINIOT.py", line 17, in <module>                         
    results = experiment(algorithm, metric, problem)                           
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/util/laboratory.py", line 41, in experiment                                     
    pool.submit(algorithm_list[a_index][0].run())                              
AttributeError: module 'jmetal.algorithm.multiobjective.randomSearch' has no attribute 'run'

This the code of my experiment:

from jmetal.algorithm import NSGAII
from jmetal.algorithm.multiobjective import randomSearch
from jmetal.component.comparator import RankingAndCrowdingDistanceComparator
from jmetal.operator import  SP, BitFlip, BinaryTournamentSelection
from miniaturization import Miniaturization
from jmetal.component.quality_indicator import HyperVolume
from jmetal.util.laboratory import experiment, display

algorithm = [
    (    (randomSearch, {'max_evaluations': 250}))
]
metric = [HyperVolume(reference_point=[1, 1, 1, 1])]
problem = [(Miniaturization, {})]

results = experiment(algorithm, metric, problem)
display(results)

Do you have any idea why this happening? NSGAII is working well.

Problem after install

Hello,
Thank you for your work !
I installed version 0.9 (python3.7.2) (with pip and git) all ok.
I tried to run an example code from documentation and at execution I have an exception on jmetal.component : ModuleNotFoundError: No module named 'jmetal.component'

Actually, there is no subfolder component in the jmetal folder...
Is it an error in the doc or in the installation scripts?
Thanks for all !

Derivative free models

Our models are based on surrogate
models to approximate the computationally expensive objective functions. Hence, derivative information, which is generally unavailable for black-box simulation ob-
jective functions, is not available. I was wondering if your optimization algorithms can handle derivative free models.

HELP on computing HyperVolume

Hi,

I struggle trying to compute the hypervole of a pareto front in a file.
My situation is that I have a file in 2 dimention containg a Pareto Front and I would like to compute the Hypervolume.

I don't understand how to load the pareto front in a Solution Object.

Could you please help me out.

Thank you in advance,
Regards,

RandomSearch

Hello,

I have implemented a multiobjective problem using RandomSearch the following way:

problem = CustomProblem.Problem()
    time_counter = TimeCounter(delay=1)
    time_counter.observable.register(problem)
    time_counter.start()
    max_seconds = 100

    algorithm = RandomSearch(
        problem=problem,
        termination_criterion=StoppingByTime(max_seconds),
    )
    algorithm.observable.register(observer=ProgressBarObserver(max=max_seconds))
    algorithm.run()

The version of the package I'm using is 1.5.1.

The code compiles just fine. However, after 100 seconds the process is still running and the ProgressBarObserver is not printed either. I tried implementing StoppingByEvaluations and same happened. I also tried using one of the included in the package problems ZDT1 with both termination criterions and same happened.

I have successfully implemented a few other multi-objective algorithms including NSGA-II, OMOPSO, SMPSO using the same custom problem and everything has run smoothly so far.

I could not find an example of an implementation of RandomSearch in the example folder so apologies if I have just done that incorrectly. I would appreciate some input on why the process does not terminate and results are not generated.

Thanks in advance,
Mila

can's use Streaming plots

Hello, I am trying to use Streaming plots, but it does not work. I got this output. The operating system is Ubuntu 18.04.IDE is Pycharm

`/usr/bin/python3.7 /home/hu/Desktop/jMetalPy-master/examples/multiobjective/moead_DTLZ2.py
Error importing optional module IPython.core.display
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plotly/optional_imports.py", line 25, in get_module
return import_module(name)
File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 953, in _find_and_load_unlocked
File "", line 219, in _call_with_frames_removed
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 953, in _find_and_load_unlocked
File "", line 219, in _call_with_frames_removed
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/dist-packages/IPython/init.py", line 54, in
from .core.application import Application
File "/usr/local/lib/python3.7/dist-packages/IPython/core/application.py", line 25, in
from IPython.core import release, crashhandler
File "/usr/local/lib/python3.7/dist-packages/IPython/core/crashhandler.py", line 27, in
from IPython.core import ultratb
File "/usr/local/lib/python3.7/dist-packages/IPython/core/ultratb.py", line 119, in
from IPython.utils import path as util_path
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/path.py", line 17, in
from IPython.utils.process import system
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/process.py", line 19, in
from ._process_posix import system, getoutput, arg_split, check_pid
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/_process_posix.py", line 23, in
import pexpect
File "/usr/lib/python3/dist-packages/pexpect/init.py", line 75, in
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
Error importing optional module IPython
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plotly/optional_imports.py", line 25, in get_module
return import_module(name)
File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/dist-packages/IPython/init.py", line 54, in
from .core.application import Application
File "/usr/local/lib/python3.7/dist-packages/IPython/core/application.py", line 25, in
from IPython.core import release, crashhandler
File "/usr/local/lib/python3.7/dist-packages/IPython/core/crashhandler.py", line 27, in
from IPython.core import ultratb
File "/usr/local/lib/python3.7/dist-packages/IPython/core/ultratb.py", line 119, in
from IPython.utils import path as util_path
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/path.py", line 17, in
from IPython.utils.process import system
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/process.py", line 19, in
from ._process_posix import system, getoutput, arg_split, check_pid
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/_process_posix.py", line 23, in
import pexpect
File "/usr/lib/python3/dist-packages/pexpect/init.py", line 75, in
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
Error importing optional module IPython.display
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plotly/optional_imports.py", line 25, in get_module
return import_module(name)
File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 953, in _find_and_load_unlocked
File "", line 219, in _call_with_frames_removed
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/dist-packages/IPython/init.py", line 54, in
from .core.application import Application
File "/usr/local/lib/python3.7/dist-packages/IPython/core/application.py", line 25, in
from IPython.core import release, crashhandler
File "/usr/local/lib/python3.7/dist-packages/IPython/core/crashhandler.py", line 27, in
from IPython.core import ultratb
File "/usr/local/lib/python3.7/dist-packages/IPython/core/ultratb.py", line 119, in
from IPython.utils import path as util_path
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/path.py", line 17, in
from IPython.utils.process import system
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/process.py", line 19, in
from ._process_posix import system, getoutput, arg_split, check_pid
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/_process_posix.py", line 23, in
import pexpect
File "/usr/lib/python3/dist-packages/pexpect/init.py", line 75, in
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
Progress: 100%|##########| 50000/50000 [00:10<00:00, 4570.83it/s]
Algorithm (continuous problem): MOEAD
Problem: DTLZ1
Computing time: 10.940814733505249
Process finished with exit code 0'

Why execution time increases?

Hi everybody, I'm working on OMOPSO algorithm and something strange happens: at the initial time there are a lot of it/s but when the execution time increases there is a decreases of the it/s. I'm working on a very power cpu with 32 core and I've set the multiprocessevaluator but it takes too long to finish. Is it the right behaviour? How cold I increase the execution speed?

Reference front file was not found at resources/reference_front/ZDT1.pf

Hi.
I just installed jMetalPy using pip install in the anaconda prompt, however for some reason the resources are not being installed properly.

Anyone else having this issue?

Thanks in advance.

Edit: I mean, I can install it manually, but I do not know where I should copy the resource folder if I want to use it on Anaconda's Spyder.

Optional dependencies

First of all congrats with this initiative, so far this seems a great optimization package!

I noticed that Pyspark and Dask are mandatory dependencies of this project. However, since a user is likely to only use one of those, or none at all, it makes the package as a whole unnecessarily heavy. This can be a burden when distributing this package as part of a larger application.

It might be better to make the various parallelization frameworks optional dependencies. This can be done with the 'extras_require' arg in setup.py (https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies). It would probably also entail moving some import statements around.

Values and variables are not saved to files

Thank you for adding some new examples, and I can run the moead_iepsilon_srinivas successfully. I'm going to write my own target function based on this demo. But another moead_iepsilon_lircmop2 still have one problem that there are no results in the files of FUN and VAR.
With best wishes!

Permutation Problem

Hello,
Could you provide an example for permutation problems?
Moreover, could you update the package in the pip? There are no some parts to create a permutation problem (new solution/crossover/mutation).

Thanks

Suggestion for saving front history in experiment

Hello,

I congratulate everyone involved in this interesting project.

I would like to make a suggestion.

We were trying to save the history of the approximation front so that we could generate graphs of the convergence of the metrics (like Hypervolume, for example).

We verify that there is an Observer to record the front of each generation. We then try to create a JobHist class, copying the Jobs class from lib "https://github.com/jMetal/jMetalPy/blob/master/jmetal/lab/experiment.py", as follows:

class JobHist:

    def __init__(self, algorithm: Algorithm, algorithm_tag: str, problem_tag: str, run: int):
        self.algorithm = algorithm
        self.algorithm_tag = algorithm_tag
        self.problem_tag = problem_tag
        self.run_tag = run

    def execute(self, output_path: str = ''):

        if output_path:
            save_front_history = WriteFrontToFileObserver(output_directory=output_path+'/HIST.{}'.format(self.run_tag))
            self.algorithm.observable.register(save_front_history)

        self.algorithm.run()

        if output_path:
            file_name = os.path.join(output_path, 'FUN.{}.tsv'.format(self.run_tag))
            print_function_values_to_file(self.algorithm.get_result(), filename=file_name)

            file_name = os.path.join(output_path, 'VAR.{}.tsv'.format(self.run_tag))
            print_variables_to_file(self.algorithm.get_result(), filename=file_name)

            file_name = os.path.join(output_path, 'TIME.{}'.format(self.run_tag))
            with open(file_name, 'w+') as of:
                of.write(str(self.algorithm.total_computing_time))

To make it easier to maintain, the Job class could have a parameter to store or not the history of each generation, or just the history for each interval of N=10 (or 20, 30, etc) generations, among other options.

However, we note that the function "generate_summary_from_experiment" expects the folders to be in a specific structure, in which it considers the last folder found as the name of the problem, and the penultimate folder found as the name of the algorithm.

When trying to use this JobHist class that we created, the function "generate_summary_from_experiment" considered that the folder "HIST.0" would be the name of a problem, and that ZDT1 would be the name of the algorithm. And it gave an error because it did not find the PF reference file for the "problem" "HIST.0".

As the algorithm and problem folders are generated as first and second folders after the name of the "output_dir" of the experiment, we saw that it would be enough to change the function "generate_summary_from_experiment" in: [-2:] to [1:3]

    for dirname, _, filenames in os.walk(input_dir):
        for filename in filenames:
            try:
                # Linux filesystem
                #algorithm, problem = dirname.split('/')[-2:]
                algorithm, problem = dirname.split('/')[1:3]
            except ValueError:
                # Windows filesystem
                #algorithm, problem = dirname.split('\\')[-2:]
                algorithm, problem = dirname.split('\\')[1:3]

            if 'HIST.' not in dirname: # <------------ needed
                if 'TIME' in filename:
                    run_tag = [s for s in filename.split('.') if s.isdigit()].pop()

                    with open(os.path.join(dirname, filename), 'r') as content_file:
                        content = content_file.read()

                    with open('QualityIndicatorSummary.csv', 'a+') as of:
                        of.write(','.join([algorithm, problem, run_tag, 'Time', str(content)]))
                        of.write('\n')

                if 'FUN' in filename:

So we can keep a folder "HIST.{RUN}" inside each folder "algorithm / problem" of an experiment.

    * <base_dir>/
      * algorithm_a/
        * problem_a/
          * HIST.0/ (history of RUN 0)
            * FUN.0 (first generation non-dominated front of execution 0)
            * FUN.1 (second generation non-dominated front of execution 0)
            * ...
          * FUN.0.tsv (final non-dominated front of execution 0)
          * HIST.1/ (history of RUN 1)
            * FUN.0 (first generation non-dominated front of execution 1)
            * FUN.1 (second generation non-dominated front of execution 1)
            * ...
          * FUN.1.tsv (final non-dominated front of execution 1)
          * VAR.0.tsv
          * VAR.1.tsv
          * ...

Another need would be after that we can generate the summary of indicators or metrics by RUN, so that we can generate graphs with the convergence of these indicators, presenting the median and the 1st and 3rd quartiles.

With this history of the approximation front of each RUN, we will also be able to generate animations to verify their evolution over the generations.

It is a suggestion.

Thank you very much.

Regards.

Do you still have plans to develop python version?

I recently learned about Jmetal and I only familiar with the python language, but I found that python version lack of many algorithms and problems (in fact, only nsga2 algorithm and smpso algorithm joined). Do you have plans to update the python version with the java version, or hope that we develop these algorithms and problems by ourself ?

Does number of variables need to be the same as number of constraints in the NSGAII?

Hi,

I am trying to run a multi-objective optimization on my problem which looks like this:

class LoadOptCWT3(FloatProblem):

def __init__(self):
    super(LoadOptCWT3, self).__init__()
    self.number_of_variables = 23
    self.number_of_objectives = 2
    self.number_of_constraints = 2

    self.obj_directions = [self.MINIMIZE, self.MINIMIZE]
    self.obj_labels = ['f(x)', 'f(y)']

    self.lower_bound = [0.0,0.0]
    self.upped_bound = [1.0,1.0]

    FloatSolution.lower_bound = self.lower_bound
    FloatSolution.upper_bound = self.upper_bound

def evaluate(self, solution: FloatSolution) -> FloatSolution:
    x = solution.variables

    solution.objectives[0] = -((-0.002 * x[0]) + (-0.001*x[1])
                              + (0.002*x[2]) + (0.0*x[3])
                              + (0.002*x[4]) + (0.0*x[5])
                              + (-0.177*x[6]) + (0.561*x[7])
                              + (-0.002*x[8]) + (0.002*x[9])
                              + (0.001*x[10]) + (0.0*x[11])
                              + (-0.001*x[12]) + (0.003*x[13])
                              + (0.005*x[14]) + (0.0*x[15])
                              + (0.001*x[16]) + (0.001*x[17])
                              + (0.0*x[18]) + (0.003*x[19]) 
                              + (-0.001*x[20]) + (0.0*x[21])
                              + (0.01*x[22]) + 0.145)


    solution.objectives[1] = -((0.01 * x[0]) + (-0.007*x[1])
                              + (-0.003*x[2]) + (0.0*x[3])
                              + (0.0*x[4]) + (-0.001*x[5])
                              + (-3.984*x[6]) + (5.937*x[7])
                              + (0.006*x[8]) + (0.0*x[9])
                              + (0.0*x[10]) + (0.012*x[11])
                              + (0.0*x[12]) + (-0.07*x[13])
                              + (0.102*x[14]) + (0.001*x[15])
                              + (0.0*x[16]) + (0.0*x[17])
                              + (0.0*x[18]) + (0.0*x[19]) 
                              + (-0.001*x[20]) + (0.0*x[21])
                              + (0.608*x[22]) + 0.716)

    self.__evaluate_constraints(solution)

    return solution


def __evaluate_constraints(self, solution: FloatSolution) -> None:
    constraints = [0.0 for _ in range(self.number_of_constraints)]

    x = solution.variables
    constraints[0] = -((-0.002 * x[0]) + (-0.001*x[1])
                      + (0.002*x[2]) + (0.0*x[3])
                      + (0.002*x[4]) + (0.0*x[5])
                      + (-0.177*x[6]) + (0.561*x[7])
                      + (-0.002*x[8]) + (0.002*x[9])
                      + (0.001*x[10]) + (0.0*x[11])
                      + (-0.001*x[12]) + (0.003*x[13])
                      + (0.005*x[14]) + (0.0*x[15])
                      + (0.001*x[16]) + (0.001*x[17])
                      + (0.0*x[18]) + (0.003*x[19]) 
                      + (-0.001*x[20]) + (0.0*x[21])
                      + (0.01*x[22]) + 0.145)
    constraints[1] = -((0.01 * x[0]) + (-0.007*x[1])
                      + (-0.003*x[2]) + (0.0*x[3])
                      + (0.0*x[4]) + (-0.001*x[5])
                      + (-3.984*x[6]) + (5.937*x[7])
                      + (0.006*x[8]) + (0.0*x[9])
                      + (0.0*x[10]) + (0.012*x[11])
                      + (0.0*x[12]) + (-0.07*x[13])
                      + (0.102*x[14]) + (0.001*x[15])
                      + (0.0*x[16]) + (0.0*x[17])
                      + (0.0*x[18]) + (0.0*x[19]) 
                      + (-0.001*x[20]) + (0.0*x[21])
                      + (0.608*x[22]) + 0.716)

    solution.constraints = constraints

def get_name(self):
    return 'LoadOptCWT3'

When i run NSGAII on this problem, I get an error: IndexError: list index out of range

This makes me think that NSGAII only works if number of variables is same as number of constraints (in my case they are not same, variables are 23 and constraints are 2).

Is this true? If so, what is the way to do multi objective optimization in this scenario using jMetalPy?

Appreciate your help.

Advice on Dynamic Number of Variables

Hi,

I am working on a model where each time a problem is created the number of variables in the solution is different and the solutions in the VAR file should have different length.

Previously, I implemented it where I set the number_of_variables = 1, however that only applied the mutation and crossover from the NSGAII on the first variable of my solution which makes perfect sense.

I am currently implementing a Dynamic NSGAII where during the update() in the problem I update the number of variables and the problem_modified. I am still struggling to implement the stopping condition - I have added the TimeCounter in the main, but not sure if I need to add a time element anywhere in the problem.

Also, please let me know if there is a better way of implementing this.

Thank you in advance for your help.

Kind regards,
Mila

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.