Clarabel.jl icon indicating copy to clipboard operation
Clarabel.jl copied to clipboard

collect method for cones

Open PaulSoderlind opened this issue 2 years ago • 3 comments

as discussed at https://discourse.julialang.org/t/ann-clarabel-jl-new-convex-optimization-solver/83915

To filter out the b[i]==Inf cases, I currently need to build the vector cones in a loop, so it has as many elements as length(b). Then, I can index into it with cones[.!isinf.(b)].

It would nice if I could create this vector by collect([NonnegativeConeT(2)]) or similarly to allow the indexing.

PaulSoderlind avatar Jul 16 '22 11:07 PaulSoderlind

I am happy to implement this, but maybe there is also some confusion here about defining cone constraints. Assuming that you are modelling all linear inequalities, you don't need to make a separate cone constraint for each element of b. If the vector $b \in \mathbb R^n$, then you can just make a single cone constraint cones = [ NonnegativeConeT(n) ], so that length(cones) == 1.

If you have the possibility of infinite elements in b, it's maybe easier therefore to just do something like cones = [ NonnegativeConeT(count(!isinf,b)) ]. You will also need to remove the corresponding rows of $A$.

Note that the solver will also accept something like :

n = count(!isinf,b)
cones  = fill(Clarabel.NonnegativeConeT(1), n)

which sounds like what your are doing. This will be a little slower to solve though, since there is more function call overhead incurred using $n$ cones of dimension $1$ rather than $1$ cone of dimension $n$.

We should probably consolidate repeated cones like this internally, but it doesn't happen at the moment using the native interface. The package will do that for you though if you call the solver through MathOptInterface (i.e. consolidation works when calling through JuMP and Convex.jl).

goulart-paul avatar Jul 18 '22 09:07 goulart-paul

all linear inequalities

My typical use case has also linear equalities, which I have handled with Clarabel.ZeroConeT(1). I guess I could reorder the restrictions to get the equalities first and then apply your idea. (Replacing an equality with two inequalities is not a good idea, or?)

PaulSoderlind avatar Jul 18 '22 12:07 PaulSoderlind

Yes, the above would also work with equalities, i.e. you can have [Clarabel.ZeroConeT(m), Clarabel.NonnegativeConeT(n)] or similar.

You can also have a mix or multiple instances of these cones in arbitrary order.

For equalities, it is preferable to use the ZeroConeT rather than a two sided set of inequalities, though I believe either way would work.

goulart-paul avatar Jul 18 '22 14:07 goulart-paul

We have implemented a feature that will automatically eliminate constraints with very large bounds, which I think means that that the issue described here is no longer relevant. This is now part of release v0.4.1.

I will close, but feel free to reopen if I have misunderstood.

goulart-paul avatar Mar 08 '23 21:03 goulart-paul