New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brudgers opened this Issue Aug 25, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@brudgers

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;
@schutta

This comment has been minimized.

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.

@schutta

This comment has been minimized.

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 <solver output file> | solns2out <corrected ozn file>
@guidotack

This comment has been minimized.

Member

guidotack commented Aug 25, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment