jMetal / jMetalPy

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

Failed to open TrueType font #56

Closed 1017073490 closed 4 years ago

1017073490 commented 4 years ago

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.

ajnebro commented 4 years ago

Hi. Certainly, the settings of the moead_dtlz2.py program contained a wrong parameter value.

The program assumes that the working directory is the root proyect directory, which contains the resources folder containing the reference Pareto fronts and the weight vectors for MOEA/D. However, the weight vector path (line 25) contained the "../.." string, which is wrong.

We have just fixed the issue.

benhid commented 4 years ago

On the other hand, your traceback shows what seems to be an issue with matplotlib — the package we are using to plot results:

File "C:\Users\张兴\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\backends\backend_ps.py", line 1122, in print_figure_implfh, fonttype, glyph_ids)
RuntimeError: Failed to open TrueType font"

Check out this question on Stackoverflow.

1017073490 commented 4 years ago

I changed the the weight vector path (line 25). However, it shows that “Failed to initialize weights”. By the way, I think the former code seems has no error.

1017073490 commented 4 years ago

It seems that the issue is related to matplotlib

1017073490 commented 4 years ago

I want to write my own multi-objective function that mimics lz09, how do I mimic and modify it? Do I just need to change my own expression for lz09? If you have time, could you give me some detailed answer?

benhid commented 4 years ago

You can define a new problem or create a new class that inherits from LZ09.

The latter approach allows you to override methods from the parent class LZ09 if necessary (some lines have been omitted for the sake of simplicity):

class LZ09(FloatProblem):

    def __init__(self,
                 number_of_variables: int,
                 number_of_objectives: int,
                 number_of_constraints: int,
                 ptype: int,
                 dtype: int,
                 ltype: int):
        super(LZ09, self).__init__()
        ...

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

    def objective(self, x_variables: list) -> list:
        ...

class NewLZ09(LZ09):

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

        for i in range(self.number_of_objectives):
            solution.objectives[i] = y[i]

        return solution

    def objective(self, x_variables: list) -> list:
        # you can implement your own functions here
        # to mimic LZ09 behaviour
        ...

This is how the LZ09_F8 problem looks like (note that this class inherits from LZ09 and thus all methods are re-used):

class LZ09_F8(LZ09):

    def __init__(self):
        super(LZ09_F8, self).__init__(number_of_variables=10, number_of_objectives=2, number_of_constraints=0,
                                      dtype=4, ltype=21, ptype=21)

    def get_name(self):
        return 'LZ09_F8'

P.S. This issue is unrelated to main topic. If you find any other problem, feel free to open a new issue.