# ERROR: syntax: function argument names not unique around

**URL:** <https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization\
**Created:** [January 25, 2021, 11:59pm UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944 "2021-01-25T23:59:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GraceMabele](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gracemabele/32/21360_2.png) [@GraceMabele](https://discourse.julialang.org/u/GraceMabele)\
**Post date:** [January 25, 2021, 11:59pm UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/1 "2021-01-25T23:59:42Z")

</div>

I am currently building a milp model previously done in GAMS and I’m converting it into JuMP (Julia).

I am particularly having trouble with constraints and the objective function that has more than one summation with conditions. It is returning the following error

syntax: function argument names not unique around C:\Users\glmab.julia\packages\JuMP\qhoVb\src\macros.jl:91

Stacktrace:  
[1] top-level scope at In[194]:7  
[2] include\_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

```julia
@constraints example2_netprofit begin
    mat1a[s in s, n in n, s = 1, n > 1],
       ST[s,n] == ST[s,n-1] + sum(sum(rho[i,s]*bs[i,np,n-1] for np in 1:length(np) if np <= n-1) for i in 1:length(Ips1)) + sum(sum(rho[i,s]*bs[i,n,np] for np in 1:length(np) if n <= np) for i in 1:length(Ics1))
    
    mat2a[s in s, n in n, s = 2, n > 1],
       ST[s,n] == ST[s,n-1] + sum(sum(rho[i,s]*bs[i,np,n-1] for np in 1:length(np) if np <= n-1) for i in 1:length(Ips2)) + sum(sum(rho[i,s]*bs[i,n,np] for np in 1:length(np) if n <= np) for i in 1:length(Ics2))
   
    mat3a[s in s, n in n, s = 3, n > 1],
       ST[s,n] == ST[s,n-1] + sum(sum(rho[i,s]*bs[i,np,n-1] for np in 1:length(np) if np <= n-1) for i in 1:length(Ips3)) + sum(sum(rho[i,s]*bs[i,n,np] for np in 1:length(np) if n <= np) for i in 1:length(Ics3))

    mat4a[s in s, n in n, s = 4, n > 1],
       ST[s,n] == ST[s,n-1] + sum(sum(rho[i,s]*bs[i,np,n-1] for np in 1:length(np) if np <= n-1) for i in 1:length(Ips4)) + sum(sum(rho[i,s]*bs[i,n,np] for np in 1:length(np) if n <= np) for i in 1:length(Ics4))

end

```

However, I have other constraints that do not have summation in it but are returning the exact same error.

```julia
@constraints example2_netprofit begin
    bv1[i in i, n in n],
      Ts[i,n] <= H
    bv2[i in i, n in n],
      Tf[i,n] <= H
    bv3[i in i, n in n, np in np, n <= np <= n],
      bs[i,n,np] <= bmax[i]
    bv4[s in s],
      ST0[s] <= STin[s]
    bv5[s in Sfis, s in Sp],
      ST0[s] == 0
    bv6[i in i, n in n, np in np, np < n],
      w[i,n,np] == 0
    bv7[i in i, n in n, np in np, np < n],
      bs[i,n,np] == 0
end

```

Here are the predefined sets and parameters used for the above to run correctly

```julia
#Sets
# i 'tasks' /t1*t5/
# j 'units' /j1*j5/
# n 'events' /n0*n3/
# s 'states' /s1*s4/

i = ["t1","t2","t3","t4","t5"];
j = ["j1","j2","j3","j4","j5"];
n = range(1,N, step = 1);
s = ["s1","s2","s3","s4"]

#SubSets

#Ij1(i) 'tasks which can be performed in unit 1' /task1/
#Ij2(i) 'tasks which can be performed in unit 2' /task2/
#Ij3(i) 'tasks which can be performed in unit 3' /task3/
#Ij4(i) 'tasks which can be performed in unit 4' /task4/
#Ij5(i) 'tasks which can be performed in unit 5' /task5/

Ij1 = i[1];
Ij2 = i[2];
Ij3 = i[3];
Ij4 = i[4];
Ij5 = i[5];

#Is1(i)'tasks which process state 1 and either produce or consume' /task1,task2/
#Is2(i)'tasks which process state 2 and either produce or consume' /task1,task2,task3/
#Is3(i)'tasks which process state 3 and either produce or consume' /task3,task4,task5/
#Is4(i)'tasks which process state 4 and either produce or consume' /task4,task5/

Is1 = i[1:2];
Is2 = i[1:3];
Is3 = i[3:5];
Is4 = i[4:5];

#Ips1(i) 'tasks which produce state 2' //
#Ips2(i) 'tasks which produce state 2' /task1,task2/
#Ips3(i) 'tasks which produce state 3' /task3/
#Ips4(i) 'tasks which produce state 4' /task4,task5/

Ips1 = [];
Ips2 = i[1:2];
Ips3 = i[3];
Ips4 = i[4:5];

#Ics1(i) 'tasks which consume state 1' /task1,task2/
#Ics2(i) 'tasks which consume state 2' /task3/
#Ics3(i) 'tasks which consume state 3' /task4,task5/
#Ics4(i) 'tasks which consume state 4' //

Ics1 = i[1:2];
Ics2 = i[3];
Ics3 = i[4:5];
Ics4 = [];

Sr =s[1]
Sfis = s[2:3]
Sp = s[4]

#alias(i,ip)
#alias(j,jp)
#alias(n,np,npp)

ip = i;
jp = j;
np = n;
npp = n;

```

```julia
#PARAMETERS
#bmin = [0,0,0,0,0]

bmin = OrderedDict(
   "t1" => 0,
   "t2" => 0,
   "t3" => 0,
   "t4" => 0,
   "t5" => 0   
)

#bmax = [100,150,200,150,150]
bmax = OrderedDict(
   "t1" => 100,
   "t2" => 150,
   "t3" => 200,
   "t4" => 150,
   "t5" => 150 
)

#STin = [10000, 0, 0, 0]
STin = OrderedDict(
     "s1" => 10000,
     "s2" => 0,
     "s3" => 0,
     "s4" => 0)

#STmax = [+inf, 200, 250, +inf]
STmax = OrderedDict(
     "s1" => Inf,
     "s2" => 200,
     "s3" => 250,
     "s4" => 0
)

#alpha = [1.333, 1.333, 1.000, 0.667, 0.667]
alpha = OrderedDict(
"t1" => 1.333,
"t2" => 1.333,
"t3" => 1.000,
"t4" => 0.667,
"t5" => 0.667
)

#beta = [0.01333, 0.01333, 0.00500, 0.00445, 0.00445]
beta = OrderedDict(
"t1" => 0.01333,
"t2" => 0.01333,
"t3" => 0.00500,
"t4" => 0.00445,
"t5" => 0.00445       
)

price = OrderedDict(
"s1" => 0,
"s2" => 0,
"s3" => 0,
"s4" => 5
)

demand = OrderedDict(
"s1" => 0,
"s2" => 0,
"s3" => 0,
"s4" => 0
)

#rho_table = wsv"""
#i s1 s2 s3 s4
#t1 -1 +1 0 0
#t2 -1 +1 0 0
#t3 0 -1 +1 0
#t4 0 0 -1 +1
#t5 0 0 -1 +1
#"""

rho_table = DataFrame([(i = "t1", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
                   (i = "t2", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
                   (i = "t3", s1 = 0, s2 = -1, s3 = +1, s4 = 0 ),
                   (i = "t4", s1 = 0, s2 = 0, s3 = -1, s4 = +1 ),
                   (i = "t5", s1 = 0, s2 = 0, s3 = -1, s4 = +1 )]);

rho = OrderedDict( (r[:i],states) => r[Symbol(states)] for r in eachrow(rho_table), states in s);

```

The commented out sections are in GAMS format. Please only take note. The other packages used include datastructures and dataframes

---

<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:** [January 26, 2021, 12:06am UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/2 "2021-01-26T00:06:54Z")

</div>

Hi @GraceMabele,

The syntax you’re looking for is something like

```nohighlight
mat1a[s in s, n in n; (s == 1) && (n > 1)],

```

You need to have the sets first, then a `;`, and then a single expression that evaluates to `true` or `false`.

I’ll see if we can improve the error message, because it is very unhelpful! (Edit: [https://github.com/jump-dev/JuMP.jl/issues/2318](https://github.com/jump-dev/JuMP.jl/issues/2318))

p.s. thanks for posting on the community forum. We try to keep the Github issues for bugs.

---

<div class="post-metadata">

**Author:** ![GraceMabele](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gracemabele/32/21360_2.png) [@GraceMabele](https://discourse.julialang.org/u/GraceMabele)\
**Post date:** [January 26, 2021, 5:20am UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/3 "2021-01-26T05:20:19Z")

</div>

Hi @odow

Thank you so much it worked for that set of constraints however not for the following below. It is giving me the exact same error. What’s different

```julia
@constraints example2_netprofit begin
    bv1[i in i, n in n],
      Ts[i,n] <= H
    
    bv2[i in i, n in n],
      Tf[i,n] <= H
    
    bv3[i in i, n in n, np in np; (n <= np <= n+d)],
      bs[i,n,np] <= bmax[i]
    
    bv4[s in s],
      ST0[s] <= STin[s]
    
    bv5[s in Sfis, s in Sp],
      ST0[s] == 0
    
    bv6[i in i, n in n, np in np; (np < n)],
      w[i,n,np] == 0
    
    bv7[i in i, n in n, np in np; (np < n)],
      bs[i,n,np] == 0
end

```

I even attempted to have a `;` for each but to no avail and separated the condition in bv3

---

<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:** [January 26, 2021, 6:45am UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/4 "2021-01-26T06:45:32Z")

</div>

~~Oops! I totally missed this point: you can’t have the name of the set be the same of the index. So no `i in i`. It needs to be something like:~~

~~ 

```nohighlight
s_set = ["s1", "s2", "s3", "s3"]
n_set = 1:N
mat1a[s in s_set, n in n_set; (s == 1) && (n > 1)],

```

 ~~

~~Because if you think about something like `ST0[s]`, do you mean `s` the set or `s`, an element in the set?~~

Surprisingly, this is not the issue. Can you post the full error? It would help if you could simplify your code to include only the smallest number of variables and constraints that are causing the error.

---

<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:** [January 26, 2021, 6:55am UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/5 "2021-01-26T06:55:55Z")

</div>

> [@GraceMabele](#):
>
> `bv5[s in Sfis, s in Sp],`

It looks like this might be the problem. You have two indices with the same name.

---

<div class="post-metadata">

**Author:** ![GraceMabele](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gracemabele/32/21360_2.png) [@GraceMabele](https://discourse.julialang.org/u/GraceMabele)\
**Post date:** [January 26, 2021, 9:46am UTC](https://discourse.julialang.org/t/error-syntax-function-argument-names-not-unique-around/53944/6 "2021-01-26T09:46:29Z")

</div>

You are correct regarding it being that constraint and bv4 above it. Thank you very much, you have been of great assistance highly appreciated. I tried to rectify as follows below but it is giving me a bounds error now.

```julia
   bv5[s in Sfis && Sp],
     ST0[s] == 0
  bv4[s in s],
      ST0[s] <= STin[s]

```
