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

HELP on computing HyperVolume #33

Closed leodsti closed 5 years ago

leodsti commented 5 years ago

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,

benhid commented 5 years ago

As for now, you can use the static method from Problem:

from jmetal.core.problem import Problem

front = Problem.read_front_from_file_as_solutions('file.pf')
hv = HyperVolume(reference_point=[1, 1])

value = hv.compute(front)

(Note that in future releases this method will be under the util module).

Or you can implement your own parser, e.g.:

def read_solutions(file_path: str):
    front = []

    with open(file_path) as file:
        for line in file:
            vector = [float(x) for x in line.split()]
            solution = FloatSolution(0, len(vector), 0, [], [])
            solution.objectives = vector

            front.append(solution)

    return front