JuMP constraints with conditions in Sum

I am trying to solve an optimization problem with JuMP. Is there any way to include “condition” in the “sum” part of @constraint macro?

The constraint is: \sum_{c \in C} \sum_{s \in S} \sum_{r \in S, s \ne r} (x_s^c + 2 * y_sr^c) = S

My code: @constraint(m, sum((x[s,c] + 2 * y[s,r,c]) for s=1:length(routes), r=1:length(routes), c=1:length(carrier)) == length(routes))

How can I include “s \ne r” condition in the @constraint macro?

Thanks!

JuMP sums use standard Julia generator syntax. So you can go:

julia> using JuMP

julia> m=Model()
Feasibility problem with:
 * 0 linear constraints
 * 0 variables
Solver is default solver

julia> @variable(m, x[1:3])
3-element Array{JuMP.Variable,1}:
 x[1]
 x[2]
 x[3]

julia> @constraint(m, sum(x[i] for i in 1:3 if i != 2) == 1)
x[1] + x[3] == 1
2 Likes

Thank you for the help.