If condition in constraint set

#1

Is there a way to rewrite the following constraint set in one row?

for i in set_i
    for ii in set_i
        if parameter[ii] >= parameter[i]
            @constraint( model, x[i] - y[ii] <= 0 );
        end
    end
end

Something like this:

@constraint( model, constrname[i in set_i, ii in set_i],
                x[i] - y[ii] <= 0 if parameter[ii] >= parameter[i] );
0 Likes

#2

See the JuMP docs: http://www.juliaopt.org/JuMP.jl/latest/constraints/#SparseAxisArrays-1

Admittedly, it isn’t a big section. If you wanted to expand them, you can edit the docs using this link https://github.com/JuliaOpt/JuMP.jl/edit/master/docs/src/constraints.md

0 Likes