# MiniZinc: type error: identifier `friend' already defined groupphoto.ozn:8 #44

Closed
opened this Issue Aug 25, 2015 · 3 comments

Projects
None yet
3 participants

### brudgers commented Aug 25, 2015

 Command `\$ minizinc groupphoto.mzn data/groupphoto1.dzn`. Code: `````` include "alldifferent.mzn"; array[Person] of var 0..4: obj = [left(position[i]) + right(position[i]) + front(position[i]) + rear(position[i]) | i in Person]; output [show(obj), show(position)]; solve maximize sum(obj); int: n; array[Person, Person] of bool: friend; set of int: Person = 1..n; array[Person] of var Person: position; constraint alldifferent(position); int: m = n div 2; constraint assert(n mod 2 = 0, "n must be even"); function var 0..1: left(var Person: i) = if i > 1 /\ i != m + 1 then bool2int(friend[position[i], position[i-1]]) else 0 endif; function var 0..1: right(var Person: i) = if i < n /\ i != m then bool2int(friend[position[i], position[i+1]]) else 0 endif; function var 0..1: front(var Person: i) = if i > m then bool2int(friend[position[i], position[i-m]]) else 0 endif; function var 0..1: rear(var Person: i) = if i < m then bool2int(friend[position[i], position[i+m]]) else 0 endif; ``````
Member

### schutta commented Aug 25, 2015

 Using the command to flatten the model ``````\$ mzn2fzn -D "n = 2; friend = [| false, false | false, false |];" bug_44.mzn `````` results in the following ozn-file ``````output [show(obj),show(position)]; set of int: Person = 1..2; array [Person] of int: position; function var 0..1 : left(var Person: i) = if i > 1 /\ i!=m+1 then bool2int(friend[position[i],position[i-1]]) else 0 endif; array [Person,Person] of bool: friend = [|false,false|false,false|]; int: m = 1; array [Person] of int: obj; array [Person,Person] of bool: friend = [|false,false|false,false|]; int: m = 1; `````` in that the declaration of the parameters friend and m are duplicated. MiniZinc 2.0.{0,1} crashes with a segmentation fault and MiniZinc 2.0.2+ leads to that erroneous ozn file.
Member

### schutta commented Aug 25, 2015

 A work-around for the current version is to use the command mzn2fzn to flatten the model, which generates a FlatZinc file with extension "fzn" and the erroneous output (ozn file), and then to use your preferred FlatZinc solver to solve the flatten model. The solver output won't conform with the specified one in the MiniZinc model, but if you need the "well-formed" output then remove duplicates from the ozn file (by hand or script) and pipe the solver's output to solns2out, e.g., ``````\$ cat | solns2out ``````
Member

### guidotack commented Aug 25, 2015

 Thanks for the report. I've added a fix, it will be part of the next release.

### guidotack added a commit that referenced this issue Aug 25, 2015

``` Don't copy vardecl items to output model that are already there. Fixes … ```
`…#44.`
``` f922d7a ```

### guidotack added a commit that referenced this issue Sep 29, 2015

``` Don't copy vardecl items to output model that are already there. Fixes … ```
`…#44.`
``` a33af46 ```