Adding a SOS2 constraint for a variable which is defined over a DenseAxisArray?

Hello!

I wonder how to add a SOS2 constraint with JuMP for a variable which is defined over a DenseAxisArray or SparseAxisArray? For example:

using JuMP


mymod = Model();

#sets
node = ["n1", "n2", "n3"]

#declare variables
@variable(mymod, r[node], lower_bound = 0)

print(r)

#add sos2 constraint
@constraint(mymod, q_1, r in SOS2([1.0, 2.0, 3.0]) )

The error I get is:

ERROR: LoadError: At /home/user/data/julia/testsos.jl:15: @constraint(mymod, q_1, r[:] in SOS2([1.0, 2.0, 3.0])): unable to add the constraint because we don’t recognize 1-dimensional DenseAxisArray{VariableRef,1,…} with index sets:
Dimension 1, [“n1”, “n2”, “n3”]
And data, a 3-element Array{VariableRef,1}:
r[n1]
r[n2]
r[n3] as a valid JuMP function.

Turn it into a vector first:

@constraint(mymod, q_1,  [r[n] for n in node] in SOS2())

Although JuMP could add a new method for this to make it easier.

Edit: Support Containers in `VectorConstraints` · Issue #2563 · jump-dev/JuMP.jl · GitHub if anyone is interested, it’s a good first-issue to contribute to JuMP.

1 Like

Thanks! It seems to work.

1 Like