Workaround for: Sum of binary Matrix as Index for Input Matrix

Hey people,

I am new here, any help is much appreciated!!

@variable( bilap, X[1:2,u=1:4,1:3], Bin) 


I want to use the sum of all 1s per each u in X as an Input (Index) for the matrix shown above.

@constraint( bilap , workers_allocated[u=1:4],w[u]=sum(X[i,u,j] for i in 1:2, j in 1:3)
@constraint( bilap , duration[i=1:4], duration[i]=Duration_per_task[i][w[u])

I know, it`s not possible like this, but I am struggeling with alternative workarrounds tbh.
First I introduced a binary variable:

@variable( bilap, D[1:3,1:4], Bin)

@constraint( bilap , Da[i=1:4],Duration[i]==sum(D[j,i]*Duration_per_task[i][j] for j in 1:3))

@constraint( bilap , Da2[i=1:4],sum(D[:,i])==1)

My problem is how to link the binary variable D to the sum of the 1s in X (necessary, cause there are several other constraints for X)

This Approach:

@constraint( bilap , Da3[i=1:4],sum(x[a,i,p] for a in 1:2, p in 1:3)==sum(D[j,i])*j for j in 1:3)

leads to following Error:

Unsupported constraint expression: we don't know how to parse constraints containing expressions of type :generator

Also I tried ConditionalJuMP to use @implies, but without any success.

Many thanks!!

You have a typo here. It needs to be ==sum(D[j,i] * j for j in 1:3)).

Putting everything together:

duration_per_task = [
    [10 6 4],
    [20 10_000 10_000],
    [1_000 8 4],
    [15 12 8],

model = Model()
@variable(model, X[1:2, 1:4, 1:3], Bin)
@variable(model, z[1:4, 1:3], Bin)
@constraint(model, [u=1:4], sum(z[u, :]) <= 1)
    [u = 1:4],
    sum(i * z[u, i] for i in 1:3) == sum(X[i, u, j] for i in 1:2, j in 1:3),
    sum(duration_per_task[u][j] * z[u, j] for j in 1:3),
# Do something with duration[u]...
1 Like

what a silly mistake…
I really appreciate your help and time!!!

1 Like

I really appreciate your help and time!!!

No worries :smile: