# Constraint declaration generates an error

**URL:** https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [May 16, 2021, 10:23am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239 "2021-05-16T10:23:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [May 16, 2021, 10:23am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/1 "2021-05-16T10:23:19Z")

</div>

Dear all,  
how to type the constraint below in order to avoid an error.  
for j in N1  
if j\>1 && j\<7  
@constraint(vrpm, sum(x[j,i,k] for i in N5, k in B if i!=j)  
-sum(x[i,j,k] for i in N4, k in B, if i!=j) == 0)  
end  
end  
If statement ( if j\>1 && j\<7) makes that error ( LoadError: MethodError: no method matching isless(::Int64, ::String))  
Thanks,  
Mamo

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [May 16, 2021, 11:25am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/2 "2021-05-16T11:25:25Z")

</div>

Please make it easier to help you by formatting your code and making it self-contained, e.g., here you don’t say what `N1` is; see [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).  
From what I see, `j` is a `String` so I guess `N1` contains some strings and then you try to compare it with `1` and `7`. Strings cannot be compared to numbers hence the error.

---

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [May 16, 2021, 11:32am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/3 "2021-05-16T11:32:36Z")

</div>

yes, thanks blegat. N1 is the set of strings, by if statement j counter should exclude first and last member of the set N1.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 16, 2021, 11:36am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/4 "2021-05-16T11:36:40Z")

</div>

Just do `for j in N1[2:6]` if you know that’s the range you’re after?

---

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [May 16, 2021, 11:48am UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/5 "2021-05-16T11:48:38Z")

</div>

Thanks nilshg, two additional questions:  
What is the command for printing the values of decision variables?  
If I want to print the entire model print(model) but what if I want to see only a specific constraint in the derived form? I need to name it?

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [May 16, 2021, 1:38pm UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/6 "2021-05-16T13:38:18Z")

</div>

> What is the command for printing the values of decision variables?

Use [`value`](https://jump.dev/JuMP.jl/stable/manual/solutions/#Primal-solution-values)

> If I want to print the entire model print(model) but what if I want to see only a specific constraint in the derived form? I need to name it?

Not necessarily, you can also do `con_ref = @constraint(...)` and use `con_ref` to reference the constraint even if it has no name.

---

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [May 16, 2021, 3:16pm UTC](https://discourse.julialang.org/t/constraint-declaration-generates-an-error/61239/7 "2021-05-16T15:16:34Z")

</div>

Thanks blegat!
