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

Highs_getRowsByRange is slow

Open jd-lara opened this issue 1 year ago • 6 comments

Recently I noticed that the numerical checks in PowerSimulations.jl since it takes a long time to run with HiGHS w.r.t to Gurobi or Xpress.

This is the loop we use is something like this

function get_constraint_numerical_bounds(model::OperationModel)
    if !is_built(model)
        error("Model not built, can't calculate constraint numerical bounds")
    end
    bounds = ConstraintBounds()
    for (const_key, constraint_array) in get_constraints(get_optimization_container(model))
        # TODO: handle this at compile and not at run time
        if isa(constraint_array, SparseAxisArray)
            for idx in eachindex(constraint_array)
                constraint_array[idx] == 0.0 && continue
                con_obj = JuMP.constraint_object(constraint_array[idx])
                update_coefficient_bounds(bounds, con_obj, (const_key, idx))
                update_rhs_bounds(bounds, con_obj, (const_key, idx))
            end
        else
            for idx in Iterators.product(constraint_array.axes...)
                !isassigned(constraint_array, idx...) && continue
                con_obj = JuMP.constraint_object(constraint_array[idx...])
                update_coefficient_bounds(bounds, con_obj, (const_key, idx))
                update_rhs_bounds(bounds, con_obj, (const_key, idx))
            end
        end
    end
    return bounds
end

jd-lara avatar Mar 18 '24 23:03 jd-lara

To clarify, what type of constraints is this iterating over?

odow avatar Mar 19 '24 00:03 odow

To clarify, what type of constraints is this iterating over?

All supported ones in direct mode. Nothing esoteric

jd-lara avatar Mar 19 '24 15:03 jd-lara

I think we decided that this was because it queries the constraint matrix: https://github.com/jump-dev/HiGHS.jl/blob/1d192e20410b2e71c7cf1eaab48d3e533f3f8902/src/MOI_wrapper.jl#L1662-L1708 One option would be to use a cache instead of direct_model, so something like model = Model(HiGHS.Optimizer; add_bridges = false).

I don't think there's an easy way to speed this up in HiGHS.jl.

odow avatar Apr 18 '24 03:04 odow