I have the following script that works for the case N=4.
using JuMP
import HiGHS
m = Model(HiGHS.Optimizer);
@variable(m, x[1:4,1:8], Bin)
@variable(m, y[1:4,1:6], Bin)
@constraints(m, begin
[j in 1:8], sum(x[r,j] for r in 1:4)==1
[i in 1:3], y[4,i]-->{x[4,i]+x[4,i+5]==2}
sum(y[4,j] for j in 1:3)==1
[i in 1:4], y[3,i]-->{x[3,i]+x[3,i+4]==2}
sum(y[3,j] for j in 1:4)==1
[i in 1:5], y[2,i]-->{x[2,i]+x[2,i+3]==2}
sum(y[2,j] for j in 1:5)==1
[i in 1:6], y[1,i]-->{x[1,i]+x[1,i+2]==2}
sum(y[1,j] for j in 1:6)==1
end)
optimize!(m)
julia> value.(x)
4×8 Matrix{Float64}:
0.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0
0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0
1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0
Can I get a compact form that allows me to do tests for higher values of N, without having to hand write all the constraints, case by case?
Is something like this, with the appropriate and correct syntax possible?
N=4
m = Model(HiGHS.Optimizer);
@variable(m, x[1:N,1:2N], Bin)
@variable(m, y[1:N,1:2(N-1)], Bin)
@constraints(m, begin
[j in 1:2N], sum(x[r,j] for r in 1:N)==1
for k in N-1:-1:1
[i in 1:k], y[k+1,i]-->{x[k1,i]+x[k+1,i+k+2]==2}
sum(y[k+1,j] for j in 1:k)==1
end
end)
optimize!(m)
value.(x)