Constraint declaration

Bildschirmfoto 2023-01-08 um 18.50.34

i want to build an MEXCLP using Julia/Jump in VS Code. Everything is working fine with the declaration except for this particular constraint.

I tried this declaration:
@constraint(model, c1, sum(x[j] for j in W[i]) >= sum(y[i,k] for k in 1:p) for i in V)

But I get an error. Is this declaration correct for the picture I added, which shows the constraint? Maybe I did something wrong with the declaration of p, W and V so it doesn’t work?


@constraint(model, c1[i in V], sum(x[j] for j in W[i]) >= sum(y[i,k] for k in 1:p))
1 Like

Thank you!

Could you help me with this constraint as well?
Bildschirmfoto 2023-01-08 um 21.10.15

I tried: @constraint(model, c2, sum(x[j] for j in W:p) <= p)

From your previous post, it looks like W is an array, which you indexed like W[i].

So it doesn’t mean anything, mathematically, to sum \sum\limits_{j \in W}^p x_j. Perhaps you just meant \sum\limits_{j \in W_p} x_j?

If so, the JuMP equivalent is:

@constraint(model, c2, sum(x[j] for j in W[p]) <= p).

It’s easier to help if you read Please read: make it easier to help you and can provide a reproducible example.

1 Like

Thank you so much for reply!

It was really helpful!

I have a new model and I would like to add the following constraint

Is my declaration correct?
@constraint(model, c10[u in setdiff(U, [1]), j !=j‘], sum(sum(V[j,j‘,u] for j in J) for j‘ in J) <=F)

The sets and parameters etc. have all been declared. I just want to know if I implemented the " u in set U / {1}" and "j !=j’ " correctly.

Thank you and have a nice day !

The condition j != j‘ should be separated with ;, not ,, see Containers · JuMP
Otherwise, you just create another dimension indexed by the Bool true or false so you will actually add the constraints when it is false.

1 Like

Thank you,
so I should always use a semicolon when separating conditions?

I have another example:

@constraint(model, c 7[c in J; u in setdiff(U, [1])], - sum( V[j,c,u] for j in J))

is this implementation correct?

Sorry I misread, it should be

constraint(model, c10[u in setdiff(U, [1]), sum(sum(V[j,j‘,u] for j in J) for j‘ in J if j !=j‘) <=F)

A , means “for all”, a ; means “if”. So in your second example, you need a comma.
In your first example, j was not a constraint index but an index of the for loop so it’s the classical Julia syntax

1 Like

Thanks for clarifying !

1 Like