Skip to content

[BUG] Duplication of NDS implementations + custom Dominator interface #784

@pablo-garciaalonso

Description

@pablo-garciaalonso

Checklist

  • I searched existing issues
  • I'm using the latest pymoo version

Bug Description

The update from 0.4.* to 0.5.* introduced changes in the project structure. Part of those were the centralization of all functions with Python/Cython implementation in the same folder. All the different algorithms to perform non-dominated sorting, which were previously in pymoo/util/nds/ are now defined in pymoo/functions/standard/ but the original implementations are still available. Only pymoo/util/nds/fast_non_dominated_sort.py contains code that is still called, but it's .

The only usage of fast_non_dominated_sort from pymoo/util/nds/fast_non_dominated_sort.py occurs in lines 32-33 of pymoo/util/nds/non_dominated_sorting.py:

# if a custom dominator is provided, use the custom dominator and run fast_non_dominated_sort  
if self.dominator is not None:  
    # Use the custom dominator directly  
    from pymoo.util.nds.fast_non_dominated_sort import fast_non_dominated_sort  
    fronts = fast_non_dominated_sort(F, dominator=self.dominator, **kwargs)  

In this case, if a dominator instance is passed to the NonDominatedSorting constructor (in theory any class implementing a calc_domination_matrix static method should work), this version is called. Elsewhere, if the standard/intended load_function approach is used the version in pymoo/functions/standard/non_dominated_sorting.py will be used.

On top of that, the Python implementations (both of them) of fast_non_dominated_sort include the following signature and code (the current one in pymoo/function has an extra parameter that does not matter here):

def fast_non_dominated_sort(F, dominator=Dominator(), **kwargs):
    if "dominator" in kwargs:
        M = Dominator.calc_domination_matrix(F)
    else:
        M = dominator.calc_domination_matrix(F)

With that signature the "if" branch is unreachable, any argument bound to the name dominator can't end up in kwargs, as a named argument with the same name is defined. Just calling
M = dominator.calc_domination_matrix(F)
already manages to fallback to the default Dominator if none is provided.

Minimal Code to Reproduce

N/A

Error Message

N/A

PyMoo & Python Version

pymoo 0.6.1.6, python 3.14.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions