# How to write a constraint Julia-jump

**URL:** <https://discourse.julialang.org/t/how-to-write-a-constraint-julia-jump/82513>\
**Category:** Optimization (Mathematical)\
**Created:** [June 9, 2022, 4:26pm UTC](https://discourse.julialang.org/t/how-to-write-a-constraint-julia-jump/82513 "2022-06-09T16:26:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [June 10, 2022, 12:10am UTC](https://discourse.julialang.org/t/how-to-write-a-constraint-julia-jump/82513/2 "2022-06-10T00:10:27Z")

</div>

Hi there,

It seems like you might want to start with some JuMP tutorials:

- [Getting started with JuMP · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/getting_started_with_JuMP/)

You should also read

- [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

It has some suggestions on writing a good question. It’s easier to help if you provide some reproducible code.

Broadly speaking though, you have two options:

Write a for-loop:

```julia
for i in I, j in J, k in K
    if j != k && i <= j
        @constraint(model, x[i,j] + x[i,k] <= 1)
    end
end

```

Use the container syntax ([Constraints · JuMP](https://jump.dev/JuMP.jl/stable/manual/constraints/#SparseAxisArrays)):

```julia
@constraint(model, [i=I, j=J, k=K; j != k && i <= j], x[i,j] + x[i,k] <= 1)

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-write-a-constraint-julia-jump/82513)._
