libminizinc icon indicating copy to clipboard operation
libminizinc copied to clipboard

Attached model using mod on large bounds crashes in COIN-BC, works with Gecode

Open zayenz opened this issue 4 years ago • 1 comments

The model from this StackOverflow answer (attached at the end also) using a mod constraints and works fine using Gecode.

When running with COIN-BC it gives the following error

Running number_concatenation.mzn
MiniZinc: evaluation error: 
/Users/zayenz/projects/minizinc/models/number_concatenation.mzn:63:
  in binary '=' operator expression
  in binary 'mod' operator expression
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/std//builtins.mzn:325:
  in if-then-else expression
  in call 'mod_t'
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/std//builtins.mzn:2829:
  in let expression
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/std//builtins.mzn:2831:
  in call 'int_mod'
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/linear//redefinitions.mzn:176:
  in binary '=' operator expression
  in array access
  in call 'aux_int_division_modulo_fn'
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/linear//redefinitions.mzn:180:
  in let expression
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/linear//redefinitions.mzn:184:
  in let expression
/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/linear//redefinitions.mzn:185:
  in set literal
  in binary 'div' operator expression
  arithmetic operation on infinite value

Process finished with non-zero exit code 1
Finished in 129msec

I'm assuming that these happen because the integer variables involved have non-specific domains? No matter the actual reason, both failures could be improved to at least point the user in the right direction of what variable the problem is with.

include "globals.mzn";

%
% Problem data
%

% The set of allowed values
set of int: Values = {1, 10, 20, 40, 100, 200};

% The number of value to concatenate
int: n = 4;


%
% Derived data
%

% The available values as an index set
set of int: Index = 1..card(Values);
% The values as an array
array[Index] of int: values = [v | v in Values];
% The length of values in decimal notation
array[Index] of int: lengths = [ceil(log10(v+1)) | v in Values];
% A mapping table from values to the widths of the numbers
array[Index, 1..2] of int: value_to_widths = array2d(Index, 1..2, [
    [values[i], 10^lengths[i]][v_or_w] 
    | i in Index, v_or_w in 1..2]);
% The numbers as an index set
set of int: N = 1..4;


%
% Variables
%

% The numbers to choose
array[N] of var Values: numbers;
% The widths of the numbers
array[N] of var int: widths;
% The factors to use for concatenation
array[1..n] of var int: factors;
% The concatenation of the numbers
var int: concatenation;


%
% Constraints
%

% For each number, find the widths of it using the mapping table
constraint forall (i in N) (
    table([numbers[i], widths[i]], value_to_widths) 
);

% Find the factors to multiply numbers with for the concatenation
constraint factors[n] == 1;
constraint forall (i in 1..n-1) (factors[i] == widths[i+1] * factors[i+1]);

% Concatenate the numbers using the factors
constraint concatenation == sum(i in N) (numbers[i] * factors[i]);

% Problem constraint, the concatenation should be evenly divisible by 13
constraint concatenation mod 13 == 0;


%
% Solve and output
%

% Find solutions using standard search
% 636 failures to find all solutions using Gecode 6.1.1
%solve satisfy;

% Find solution by setting the least significant number first
% 121 failures to find all solutions using Gecode 6.1.1
solve :: int_search(reverse(numbers), input_order, indomain_min) satisfy;

% Find the smallest concatenation using the numbers
%solve minimize concatenation;

% Find the largest concatenation using the numbers
%solve maximize concatenation;

% Output both data and variables
output [
  "values=", show(values), "\n",
  "lengths=", show(lengths), "\n",
  "v_to_w={ "] ++ [show(value_to_widths[i, 1]) ++ "->" ++ show(value_to_widths[i, 2]) ++ " "|i in Index] ++ ["}\n",
  "numbers=", show(numbers), "\n",
  "widths=", show(widths), "\n",
  "factors=", show(factors), "\n",
  "concatenation=", show(concatenation), "\n",
];

zayenz avatar Aug 13 '20 05:08 zayenz

I've created a seperate issue for Chuffed in that repository (https://github.com/chuffed/chuffed/issues/72).

The CBC interface does live here, so this issue will track that part of the problem.

Dekker1 avatar Apr 16 '21 07:04 Dekker1