minizincgecode

MiniZinc: type error: invalid type for comprehension: `array[int] of var opt string'


I use MiniZinc 2.7.6 and Gecode 6.3.0 when I run the below block of code:

int: user_property_1 = 1; % user_property_1-parameter
int: user_property_2 = 2; % user_property_2-parameter
int: user_property_3 = 1; % user_property_3-parameter
int: user_property_4 = 2; % user_property_4-parameter
int: user_property_5 = 2; % user_property_5-parameter
int: user_property_6 = 1; % user_property_6-parameter
int: user_property_7 = 1; % user_property_7-parameter
array [1..3] of {0, 5, 10, 15, 20, 30}: product_property_1 = [5,10,15]; % product_property_1-parameter
array [1..3] of {0, 3, 9, 12, 15, 20}: product_property_2 = [3,3,3]; % product_property_2-parameter
array [1..3] of {0, 2, 24, 720}: product_property_3 = [0,0,0]; % product_property_3-parameter
array [1..3] of {0, 1}: product_property_4 = [0,0,0]; % product_property_4-parameter
array [1..3] of {0, 3, 9, 12, 15, 20}: product_property_5 = [0,0,0]; % product_property_5-parameter
array [1..3] of {0, 3, 9, 12, 15, 20}: product_property_6 = [0,0,0]; % product_property_6-parameter
array [1..3] of int: price = [61,77,91]; % price-parameter
array [1..3] of  {0, 1}: rides_limit = [0,0,0]; % rides_limit-parameter
array [1..3] of string: object_ids = ["5eb4028e8f061c3338dd41b7","5eb4028e8f061c3338dd41b8","5eb4028e8f061c3338dd41b9"]; % object_ids-parameter
var set of 1..3: occur; % occur-variable
constraint user_property_1==2 ->forall (i in occur) (product_property_4 [i]= 0); % C1-constraint
constraint user_property_4==3 ->forall (i in occur)(product_property_2 [i] != 0 ); % C2-constraint
constraint user_property_3==3 ->forall (i in occur)(product_property_4[i]!=0); % C3-constraint
constraint user_property_5==2 ->forall (i in occur)(product_property_3[i]!=0); % C4-constraint
constraint user_property_6==3 ->forall (i in occur)(product_property_5[i]!=0); % C5-constraint
constraint user_property_7==3 ->forall (i in occur)(product_property_6[i]!=0); % C6-constraint
constraint user_property_2==3 ->forall (i in occur)(product_property_1[i]!=0); % C7-constraint
solve satisfy;output["product_ids:" ++ join(",", [ "\(i)" | i in fix(occur)] ) ++"\nObject_ids:" ++show(i in occur) (object_ids[i])++"\nproduct_property_1:" ++show(i in occur) (product_property_1[i])++"\nproduct_property_2:" ++show(i in occur) (product_property_2[i])++"\nproduct_property_3:" ++show(i in occur) (product_property_3[i])++"\nproduct_property_4:" ++show(i in occur) (product_property_4[i])++"\nproduct_property_5:" ++show(i in occur) (product_property_5[i])++"\nproduct_property_6:" ++show(i in occur) (product_property_6[i])++"\nprice:" ++show(i in occur) (price[i])++"\nrides_limit:" ++show(i in occur) (rides_limit[i])++"\nnumber_products:"++ show(card(occur))++"\n" ]; % goal

I get the below error:

MiniZinc: type error: invalid type for comprehension: `array[int] of var opt string'

My understanding is that the issue is related to the

array [1..3] of string: object_ids = ["5eb4028e8f061c3338dd41b7","5eb4028e8f061c3338dd41b8","5eb4028e8f061c3338dd41b9"]; % object_ids-parameter

Based on this post I tried using enum data type but since my string array consists of numbers also, this did not work for my case. How could I fix it? The strange thing is that this used to work some time ago...is it related with the version of MiniZinc?


Solution

  • The error refers to your output statement.

    Change occur to fix(occur)

    .... "\nObject_ids:" ++show(i in fix(occur)) (object_ids[i]) ...
    

    Usage of fix was discussed in a related post.

    With help of a function, you could rewrite your output section into something like this:

    function string: show_prop(string: s, array[int] of int: p) =
      "\n" ++ s ++ ":[" ++ join(", ", ["\(p[i])" | i in fix(occur)] ) ++ "]";
    
    output["product_ids:" 
    ++ join(",", [ "\(i)" | i in fix(occur)] ) 
    ++"\nObject_ids:" ++ show(i in fix(occur)) (object_ids[i]) 
    ++ show_prop("product property 1", product_property_1)
    ++ show_prop("product property 2", product_property_2)
    ++ show_prop("product property 3", product_property_3)
    ++ show_prop("product property 4", product_property_4)
    ++ show_prop("product property 5", product_property_5)
    ++ show_prop("product property 6", product_property_6)
    ++ show_prop("price", price)
    ++ show_prop("rides_limit", rides_limit)
    ++"\nnumber_products:"++ show(card(fix(occur)))++"\n" ]; % goal