Skip to content

Any efficient way for sparse matrix constraints? #205

@happyxu0619

Description

@happyxu0619

Is there efficient way for building constraints with sparse matrix A, lb <= Ax <= ub

Here is my code

for i in 1:cons_num
    expr_i = 0.0
    for j in 1:var_num
        for k in constraint_matrix.colptr[j]:(constraint_matrix.colptr[j+1]-1)
            if constraint_matrix.rowval[k] == i
                expr_i += constraint_matrix.nzval[k] * x[j]
            end
        end
    end
    constraint(c, expr_i; lcon=cons_lb[i], ucon=cons_ub[i])
end

While JuMP code is very simple and efficient.
@constraint(model, cons_lb .<= A * x .<= cons_ub)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions