Wikunia / ConstraintSolver.jl

ConstraintSolver in Julia: Blog posts ->
https://opensourc.es/blog/constraint-solver-1
MIT License
136 stars 14 forks source link

Better dispatch strategy #60

Closed Wikunia closed 4 years ago

Wikunia commented 4 years ago

As mentioned by @matbesancon it isn't a good idea to have the type Function in constraints like:

mutable struct LinearConstraint{T <: Real} <: Constraint
    idx                 :: Int
    fct                 :: Function
...

because of dynamic dispatching this will be slower. The idea is to have a similar structure to MOI instead such that new constraints provide two functions: prune_constraint(com, v::MOI.VectorOfVariables, set) for example or prune_constraint(com, func:MOI.ScalarAffineFunction, set). As well as a still_feasible(com,func,set, value, index) function in contrast to the current functions:

function all_different(com::CS.CoM, constraint::BasicConstraint; logs = true)
function all_different(com::CoM, constraint::Constraint, value::Int, index::Int)