# The "sum" in constraint

**URL:** <https://discourse.julialang.org/t/the-sum-in-constraint/58434>\
**Category:** Optimization (Mathematical)\
**Created:** [April 2, 2021, 9:41am UTC](https://discourse.julialang.org/t/the-sum-in-constraint/58434 "2021-04-02T09:41:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hxxx123](https://avatars.discourse-cdn.com/v4/letter/h/ac8455/32.png) [@hxxx123](https://discourse.julialang.org/u/hxxx123)\
**Post date:** [April 2, 2021, 9:41am UTC](https://discourse.julialang.org/t/the-sum-in-constraint/58434/1 "2021-04-02T09:41:10Z")

</div>

I’m trying to add one constraint :sum of “t[i,j]_x[i,j]\<=10".  
T is one "11_11” metrix and x[1:11,1:11] are binary variables.Seems to be error. ![12](https://global.discourse-cdn.com/julialang/original/3X/9/d/9de44b83f5eda2b9e0e6f5592ea708e121d3fdc5.jpeg)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [April 2, 2021, 11:39am UTC](https://discourse.julialang.org/t/the-sum-in-constraint/58434/2 "2021-04-02T11:39:15Z")

</div>

Hello and welcome to the community. Please see the post

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

to learn how to ask a question so that it’s easy to help you.

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [April 2, 2021, 1:50pm UTC](https://discourse.julialang.org/t/the-sum-in-constraint/58434/3 "2021-04-02T13:50:37Z")

</div>

Please post an MWE and clarify what your problem is. The constraint is correct. At least this code works on my machine:

```julia
using JuMP, CPLEX
S = 1:11
A = rand(11,11)
model = JuMP.direct_model( CPLEX.Optimizer() )
@variable(model, x[i in S, j in S], Bin)
@objective(model, Max, sum(A[i,j] * x[i,j] for i in S, j in S ) )
@constraint(model, con, sum(A[i,j] * x[i,j] for i in S, j in S ) <= 1)
optimize!(model)

```
