Skip to content

ScalarFunctionIterator has quadratic complexity #418

Closed
@mohamed82008

Description

@mohamed82008

The current ScalarFunctionIterator has a best case quadratic and worst case cubic (if the constraints are dense) complexity. If we do a Radix sort by the output_index then it becomes O(nk) where k is the average number of terms per constraint. For sparse constraints, this is linear complexity. This together with the use of StructsOfArrays.jl can enable returning a view from scalar_terms_at_index which reduces allocations. The catch here is if the user/solver expects the terms to be in a certain order and sorting will just confuse everyone. I haven't seen this assumption made anywhere so I am asking if you know otherwise.

https://github.com/JuliaOpt/MathOptInterface.jl/blob/247c4baf673eb8b1c29177e7f1652a0a78e1d570/src/Utilities/functions.jl#L103

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions