Unfortunately it ends up having O(n^3) complexity, as benchmark notes,
but that is only because connected() is itself O(n^2).
There may perhaps be a better formulation for all that,
but i'm not seeing it currently.
The results are already much better than i had hoped.
(There may be a standard set of inefficiencies in minizinc itself,
not sure how much i want to look into that given how it's developed and tested...)
It would have been rather useful to me when i was trying to write a model, and i couldn't quite come up with anything good on a spot, and thus after much pain ended up with: https://github.com/LebedevRI/minizinc-graph-reachability-matrix-predicate.mzn
Unfortunately it ends up having
O(n^3)
complexity, as benchmark notes, but that is only becauseconnected()
is itselfO(n^2)
. There may perhaps be a better formulation for all that, but i'm not seeing it currently. The results are already much better than i had hoped.(There may be a standard set of inefficiencies in minizinc itself, not sure how much i want to look into that given how it's developed and tested...)