# card of optionals causes segfault on mzn2fzn translation level #135

Closed
opened this Issue Jan 26, 2017 · 0 comments

Projects
None yet
1 participant

### pafnucy commented Jan 26, 2017 • edited

 Code below produces segfault, it happens on mzn2fzn translation level. Use of card({expression}) leads to segfault, where for example length([expression]) works. ``````array[1..r] of GROUP: g1; array[1..r] of GROUP: g2; int : k; array[GROUP] of int: count; int: r; set of int: g12set = {i | i in 1..k where exists([j=i | j in g1++g2])}; set of int : GROUP = 1..k; int : T = sum(i in GROUP)(count[i]); set of int : TIME = 1..T; set of int : PERSON = 1..T; set of GROUP : F_GROUPS = {g | g in GROUP where g in {z | z in g1 ++ g2}}; set of GROUP : P_GROUPS = {g | g in GROUP where not (g in {z | z in g1 ++ g2})}; array[PERSON] of GROUP : assignment = [g | g in GROUP, k in 1..count[g]]; function int: lastoccur(array[int] of int: v, int: s) = max([ i | i in index_set(v) where v[i] = s]); function int: firstoccur(array[int] of int: v, int: s) = min([ i | i in index_set(v) where v[i] = s]); array[GROUP] of PERSON : last_assign = [lastoccur(assignment, g) | g in GROUP]; array[GROUP] of PERSON : first_assign = [firstoccur(assignment, g) | g in GROUP]; array[GROUP, GROUP] of bool : group_relation= array2d(GROUP, GROUP, [exists([g1[i] == row /\ g2[i] == col \/ g1[i] == col /\ g2[i] == row | i in 1..r]) | row, col in GROUP]); array[TIME] of var PERSON : order; array[PERSON] of var TIME : posn; include "globals.mzn"; constraint inverse(order, posn); constraint forall(g in {g | g in GROUP where count[g] > 2} intersect P_GROUPS)(posn[first_assign[g]] >= posn[last_assign[g] - 2]); array[GROUP] of var 0..1 : indicator; constraint forall(g in GROUP)(indicator[g] = 1 <-> g in g12set /\ card({posn[first_assign[g]] > posn[first_assign[gg]] /\ posn[first_assign[g]] > posn[last_assign[gg]] | gg in F_GROUPS where group_relation[g, gg]}) > 0); % no segfault version % constraint forall(g in GROUP)(indicator[g] = 1 <-> g in g12set /\ % length([posn[first_assign[g]] > posn[first_assign[gg]] /\ posn[first_assign[g]] > posn[last_assign[gg]] | gg in F_GROUPS where group_relation[g, gg]]) > 0); var int : obj = sum(g in GROUP)(3*bool2int(indicator[g] = 1)); solve maximize obj; g1 = []; g2 = []; k = 4; count = [3,2,2,3]; r = 0; `````` edit: fixed hidden 1st line of code (code directly behind triple backtick wasn't visible)

### guidotack added a commit that referenced this issue Jan 29, 2017

``` Coerce comprehension expression to var int in case of sets. Currently… ```
`… this at least triggers an error message rather than crashing, but it will work as soon as var set comprehensions are supported. Fixes #135.`
``` 20aa6b4 ```