Closed hakank closed 3 years ago
This is a bit similar to #205 . Currently the indicator or reified variable has to be a binary variable.
In your example:
@constraint(model, val == x[k,l] => {bi[k] + bj[l] == 2} )
Needs to be written as:
@constraint(model, binary_variable := {val == x[k,l]})
@constraint(model, binary_variable => {bi[k] + bj[l] == 2} )
I'll have a look at supporting this.
Ah, of course! I should have realized that.
Adding a new variable bij[1:n,1:n]
seems to work. I have to test it further but it seems promising...
function matrix_element(model, x,i,j,val)
n,_ = size(x)
bi = @variable(model,[1:n], Bin)
bj = @variable(model,[1:n], Bin)
bij = @variable(model, [1:n,1:n], Bin) # Added
@constraint(model, sum(bi) == 1)
@constraint(model, sum(bj) == 1)
@constraint(model, sum(bij[:]) == 1) # Added
for k in 1:n, l in 1:n
@constraint(model,bi[k] := { k == i })
@constraint(model,bj[l] := { l == j })
@constraint(model,bij[k,l] := { bi[k] + bj[l] == 2 }) # Added
@constraint(model, bij[k,l] => { val == x[k,l] } )
end
return bi,bj,bij
end
The following model throws a strange/uninformative error when activating one of the two commented constraints in the
matrix_element
function. The error is "no method matching _build_indicator_constraint". See below for the full stack trace.The principle of the constraint is to fix the row (via the
bi
binary array) and the column (viabj
array) and selecting the row/column in the matrixx
.What I can see, this decomposition should work:
bi
andbj
reification arrays are correctii = 2
thenbi
is[0,1,0
jj = 3
thenbj
is[0,0,1]
However, when uncommenting one of the two "connection" constraints in
matrix_element
the model don't work, i.e.@constraint(model, val == x[k,l] => {bi[k] + bj[l] == 2} )
@constraint(model, (bi[k] + bj[l] == 2) => { val == x[k,l] } )
(I'm testing both to debug and they throw the same error. Also changing to reification instead give the same error.)
Is there an error in this model or is it some kind of bug in handling indicators?
As it stand, the program prints:
Here's the full stacktrace when the first of the two connection constraints is uncommented