SciML / Optimization.jl

Mathematical Optimization in Julia. Local, global, gradient-based and derivative-free. Linear, Quadratic, Convex, Mixed-Integer, and Nonlinear Optimization in one simple, fast, and differentiable interface.
https://docs.sciml.ai/Optimization/stable/
MIT License
719 stars 80 forks source link

More advanced MOI Constraints #641

Open AlCap23 opened 10 months ago

AlCap23 commented 10 months ago

Is your feature request related to a problem? Please describe.

Mathoptinterface offers automatic and well tested "advanced" constraints, e.g. SOS constraints. It would be nice to offer those within Optimzation.jl.

As a motivating example consider the sparse regression problem (😅), which can either be modeled with integer variables $z_i \in \lbrace 0, 1\rbrace$ using a big-M formulationin the constraints

$$ M^l_i z_i \leq \xi_i \leq M^u_i z_i $$

or with the special ordered set 1 type constraint

$$ \lbrace \xi_i , 1 - z_i \rbrace \in \text{SOS-1} $$

which mathoptinterface expands internally.

Describe the solution you’d like

I think the nicest solution would be something along

@variables begin 
   x::Float64 [description="Parameter with value"] 
   c::Int [bounds = (0,1), description = "Integer decision"]
end

constraint = [
   SOS1(x, 1-c)
]

which indicates the right constraints.

Given that these constraints add variables and might become complicated, a transformation step could be added in the expression simplifcation routine of OptimizationMOI. This way only "dummy" constraints must be added and registered.

# Something along the lines of 
...
if ex.args[1] == SOS1 
    MOI.add_constraint(..., ....)
end
...

Describe alternatives you’ve considered

Instead of relying on MOI we could add functions returning the internal representation of the constraint. This would be more universal, but might end buggy and adds to the maintenance stack.