-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order-maintaining copy_to #2236
Comments
I agree, when there is an NLP block then we simply disable constrained variables. |
we could add a keyword argument maintain_variable_order = always_maintain_variable_order || has_nlp |
We probably want to stop adding keyword arguments to |
The problem is if you want to set that as the caller of |
The approach then is to use a layer like here: MathOptInterface.jl/src/Utilities/copy.jl Lines 512 to 643 in dab02e5
|
This actually hints at a deeper problem: the order of MOI constraints in a copy is not the same between solvers. One places this crops up is writing files like MPS. Most copies end up grouping by constraint type and then construction order, but I do wonder if there should instead be a global order of constraints. i.e., all |
@blegat and I discussed this without much of a conclusion. Do we have a reproducible example of the current problem? Is it necessary to use a permutation matrix? Couldn't we just pass a (permuted) view of the vector to the function Here's the bit where we disable constrained variables: MathOptInterface.jl/src/Utilities/copy.jl Lines 488 to 500 in a049bfe
So maybe we do need a way for |
one solution would be a three-argument |
Keeping constraint order would require a big change to MOI. We're really just not set up to record or communicate that information. (It'd likely mean requiring implementations to use a non-decreasing UUID for Can you point to a concrete example where this is necessary? This line in Boscia is worrying: Can't you just work-around this with a permutation vector? Or ask your oracle to accept a julia> x = [0.1, 0.2, 0.3, 0.4]
4-element Vector{Float64}:
0.1
0.2
0.3
0.4
julia> p = [4, 2, 1, 3]
4-element Vector{Int64}:
4
2
1
3
julia> x[p]
4-element Vector{Float64}:
0.4
0.2
0.1
0.3
julia> view(x, p)
4-element view(::Vector{Float64}, [4, 2, 1, 3]) with eltype Float64:
0.4
0.2
0.1
0.3 |
If you want indices to be from 1 to n you can use a MatrixOfConstraints. See Zaphod.jl for an example of how to use it |
I'd propose we close this. I don't think we need to add more complexity to MOI. |
Maybe we could add all constraints required a shared non-decreasing UUID as one of the MOI 2.0 decisions. Added to #2180 |
Thoughts @matbesancon? |
I'll do that as a temporary solution, but the fact that the order-preserving implementation is right there in copy-to without being accessible is a bit frustrating |
It would be handy in some cases to have a second implementation of
copy_to
that adds variables (and constraints) in the order of increasing index instead of constrained and then free.That way one can get rid of the
index_map
. Concretely, I'm working on non-linear on top of MOI with a functionf(x)
that takes the vector of variables in order of variable index. When copying the model, this would be handy to keep the same order to avoid having to callf(permutation_matrix * x)
all the timeThe text was updated successfully, but these errors were encountered: