Add tabled models for 3 models
This commit is contained in:
parent
a0f4e4094e
commit
040a73a483
186
black-hole/table/0.mzn
Normal file
186
black-hole/table/0.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
31, 30, 8,
|
||||
45, 50, 19,
|
||||
37, 12, 47,
|
||||
24, 9, 18,
|
||||
16, 40, 20,
|
||||
38, 36, 49,
|
||||
11, 33, 51,
|
||||
39, 10, 14,
|
||||
3, 27, 46,
|
||||
29, 2, 35,
|
||||
4, 32, 17,
|
||||
15, 13, 5,
|
||||
23, 34, 28,
|
||||
48, 21, 52,
|
||||
22, 6, 42,
|
||||
44, 41, 26,
|
||||
25, 43, 7
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/1.mzn
Normal file
186
black-hole/table/1.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
20, 39, 6,
|
||||
34, 31, 32,
|
||||
15, 33, 38,
|
||||
40, 4, 43,
|
||||
16, 37, 7,
|
||||
2, 18, 19,
|
||||
8, 41, 47,
|
||||
35, 25, 51,
|
||||
28, 5, 21,
|
||||
45, 24, 23,
|
||||
9, 3, 46,
|
||||
27, 52, 26,
|
||||
14, 30, 44,
|
||||
36, 12, 49,
|
||||
10, 29, 42,
|
||||
48, 50, 13,
|
||||
17, 11, 22
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/10.mzn
Normal file
186
black-hole/table/10.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
6, 22, 20,
|
||||
33, 18, 31,
|
||||
44, 4, 2,
|
||||
51, 38, 23,
|
||||
41, 14, 5,
|
||||
34, 52, 39,
|
||||
46, 19, 49,
|
||||
10, 25, 15,
|
||||
45, 43, 32,
|
||||
26, 21, 11,
|
||||
27, 47, 37,
|
||||
28, 17, 50,
|
||||
7, 3, 24,
|
||||
30, 42, 16,
|
||||
40, 35, 29,
|
||||
36, 8, 48,
|
||||
13, 12, 9
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/11.mzn
Normal file
186
black-hole/table/11.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
10, 40, 12,
|
||||
21, 3, 9,
|
||||
47, 31, 20,
|
||||
19, 45, 6,
|
||||
7, 4, 35,
|
||||
26, 30, 28,
|
||||
25, 18, 32,
|
||||
34, 46, 49,
|
||||
15, 22, 42,
|
||||
13, 41, 2,
|
||||
11, 5, 44,
|
||||
8, 43, 39,
|
||||
36, 29, 17,
|
||||
38, 33, 52,
|
||||
24, 23, 37,
|
||||
14, 51, 48,
|
||||
27, 50, 16
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/12.mzn
Normal file
186
black-hole/table/12.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
13, 28, 25,
|
||||
21, 5, 43,
|
||||
4, 9, 30,
|
||||
40, 33, 51,
|
||||
48, 52, 10,
|
||||
37, 27, 12,
|
||||
41, 6, 3,
|
||||
42, 16, 35,
|
||||
38, 18, 14,
|
||||
45, 17, 49,
|
||||
29, 24, 36,
|
||||
31, 50, 39,
|
||||
32, 8, 7,
|
||||
46, 47, 20,
|
||||
23, 34, 2,
|
||||
15, 19, 26,
|
||||
44, 22, 11
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/13.mzn
Normal file
186
black-hole/table/13.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
43, 29, 24,
|
||||
12, 18, 37,
|
||||
28, 10, 42,
|
||||
48, 33, 9,
|
||||
15, 4, 44,
|
||||
21, 22, 17,
|
||||
25, 38, 5,
|
||||
45, 23, 13,
|
||||
51, 19, 7,
|
||||
16, 49, 6,
|
||||
50, 47, 31,
|
||||
3, 40, 32,
|
||||
2, 39, 30,
|
||||
34, 11, 14,
|
||||
35, 20, 46,
|
||||
27, 52, 8,
|
||||
26, 36, 41
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/14.mzn
Normal file
186
black-hole/table/14.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
26, 17, 22,
|
||||
19, 41, 46,
|
||||
5, 12, 13,
|
||||
31, 42, 3,
|
||||
49, 30, 36,
|
||||
38, 48, 52,
|
||||
20, 34, 2,
|
||||
9, 28, 24,
|
||||
44, 11, 33,
|
||||
50, 43, 16,
|
||||
45, 4, 47,
|
||||
29, 37, 51,
|
||||
32, 8, 21,
|
||||
35, 39, 14,
|
||||
15, 7, 10,
|
||||
27, 6, 18,
|
||||
23, 40, 25
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/15.mzn
Normal file
186
black-hole/table/15.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
28, 30, 11,
|
||||
2, 48, 20,
|
||||
29, 44, 9,
|
||||
45, 47, 40,
|
||||
24, 10, 19,
|
||||
14, 15, 51,
|
||||
5, 43, 46,
|
||||
8, 18, 32,
|
||||
37, 22, 36,
|
||||
31, 50, 49,
|
||||
7, 12, 52,
|
||||
27, 4, 39,
|
||||
33, 23, 38,
|
||||
25, 41, 35,
|
||||
42, 17, 3,
|
||||
34, 13, 26,
|
||||
21, 6, 16
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/16.mzn
Normal file
186
black-hole/table/16.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
20, 26, 2,
|
||||
10, 6, 45,
|
||||
14, 15, 21,
|
||||
27, 51, 41,
|
||||
19, 48, 8,
|
||||
44, 52, 33,
|
||||
39, 47, 7,
|
||||
17, 46, 37,
|
||||
13, 11, 40,
|
||||
32, 29, 9,
|
||||
3, 12, 42,
|
||||
28, 35, 50,
|
||||
34, 30, 24,
|
||||
43, 22, 16,
|
||||
5, 49, 31,
|
||||
25, 4, 36,
|
||||
18, 38, 23
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/17.mzn
Normal file
186
black-hole/table/17.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
46, 29, 48,
|
||||
50, 31, 26,
|
||||
25, 38, 13,
|
||||
42, 4, 52,
|
||||
40, 19, 45,
|
||||
23, 44, 47,
|
||||
16, 7, 21,
|
||||
6, 30, 3,
|
||||
34, 24, 41,
|
||||
22, 5, 39,
|
||||
12, 8, 17,
|
||||
20, 43, 18,
|
||||
11, 36, 27,
|
||||
49, 51, 33,
|
||||
14, 10, 37,
|
||||
32, 28, 2,
|
||||
35, 15, 9
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/18.mzn
Normal file
186
black-hole/table/18.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
48, 27, 46,
|
||||
49, 18, 40,
|
||||
33, 26, 32,
|
||||
36, 14, 6,
|
||||
44, 31, 42,
|
||||
5, 43, 15,
|
||||
38, 10, 29,
|
||||
21, 20, 22,
|
||||
25, 34, 19,
|
||||
52, 13, 37,
|
||||
28, 39, 12,
|
||||
23, 30, 2,
|
||||
47, 7, 3,
|
||||
8, 9, 16,
|
||||
51, 50, 41,
|
||||
24, 45, 35,
|
||||
11, 4, 17
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/19.mzn
Normal file
186
black-hole/table/19.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
49, 25, 9,
|
||||
37, 6, 19,
|
||||
21, 50, 44,
|
||||
40, 35, 52,
|
||||
10, 11, 41,
|
||||
7, 4, 13,
|
||||
15, 36, 2,
|
||||
32, 18, 31,
|
||||
30, 26, 39,
|
||||
14, 24, 8,
|
||||
48, 12, 46,
|
||||
29, 28, 34,
|
||||
43, 27, 16,
|
||||
42, 38, 33,
|
||||
23, 51, 22,
|
||||
17, 3, 5,
|
||||
20, 47, 45
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/2.mzn
Normal file
186
black-hole/table/2.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
38, 25, 14,
|
||||
8, 11, 13,
|
||||
18, 52, 19,
|
||||
30, 46, 16,
|
||||
9, 41, 29,
|
||||
22, 35, 27,
|
||||
21, 15, 10,
|
||||
50, 48, 7,
|
||||
37, 51, 49,
|
||||
23, 47, 43,
|
||||
40, 3, 6,
|
||||
28, 42, 20,
|
||||
34, 12, 2,
|
||||
36, 33, 45,
|
||||
32, 39, 4,
|
||||
26, 31, 5,
|
||||
24, 17, 44
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/20.mzn
Normal file
186
black-hole/table/20.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
13, 22, 5,
|
||||
15, 37, 6,
|
||||
14, 38, 49,
|
||||
50, 23, 51,
|
||||
27, 48, 10,
|
||||
9, 8, 16,
|
||||
26, 44, 43,
|
||||
35, 34, 30,
|
||||
11, 20, 40,
|
||||
17, 31, 47,
|
||||
29, 41, 28,
|
||||
4, 18, 39,
|
||||
12, 42, 25,
|
||||
2, 52, 33,
|
||||
36, 19, 32,
|
||||
24, 7, 45,
|
||||
21, 3, 46
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/3.mzn
Normal file
186
black-hole/table/3.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
25, 47, 51,
|
||||
23, 24, 41,
|
||||
52, 10, 7,
|
||||
36, 49, 35,
|
||||
16, 21, 4,
|
||||
12, 45, 9,
|
||||
50, 28, 3,
|
||||
20, 46, 43,
|
||||
44, 22, 32,
|
||||
34, 6, 31,
|
||||
40, 27, 33,
|
||||
15, 38, 14,
|
||||
37, 39, 42,
|
||||
26, 19, 5,
|
||||
29, 2, 18,
|
||||
13, 48, 11,
|
||||
8, 17, 30
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/4.mzn
Normal file
186
black-hole/table/4.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
39, 46, 5,
|
||||
37, 38, 32,
|
||||
49, 31, 48,
|
||||
11, 6, 22,
|
||||
2, 43, 13,
|
||||
17, 26, 16,
|
||||
4, 29, 8,
|
||||
24, 20, 34,
|
||||
42, 27, 52,
|
||||
19, 35, 15,
|
||||
41, 36, 40,
|
||||
44, 7, 9,
|
||||
33, 45, 51,
|
||||
10, 23, 47,
|
||||
3, 14, 21,
|
||||
25, 30, 18,
|
||||
50, 28, 12
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/5.mzn
Normal file
186
black-hole/table/5.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
42, 38, 4,
|
||||
45, 41, 21,
|
||||
28, 15, 43,
|
||||
30, 26, 25,
|
||||
51, 7, 39,
|
||||
22, 47, 8,
|
||||
16, 46, 12,
|
||||
29, 40, 18,
|
||||
19, 5, 33,
|
||||
13, 35, 20,
|
||||
17, 36, 23,
|
||||
34, 6, 27,
|
||||
14, 24, 11,
|
||||
52, 9, 49,
|
||||
10, 2, 3,
|
||||
44, 48, 31,
|
||||
37, 50, 32
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/6.mzn
Normal file
186
black-hole/table/6.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
40, 42, 24,
|
||||
31, 39, 37,
|
||||
48, 22, 36,
|
||||
19, 29, 44,
|
||||
51, 7, 45,
|
||||
49, 38, 14,
|
||||
25, 27, 16,
|
||||
15, 12, 52,
|
||||
20, 46, 8,
|
||||
32, 18, 2,
|
||||
30, 21, 13,
|
||||
5, 9, 33,
|
||||
11, 3, 17,
|
||||
4, 50, 47,
|
||||
10, 6, 23,
|
||||
34, 35, 28,
|
||||
43, 26, 41
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/7.mzn
Normal file
186
black-hole/table/7.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
37, 36, 18,
|
||||
50, 30, 25,
|
||||
47, 21, 52,
|
||||
9, 34, 28,
|
||||
20, 19, 2,
|
||||
14, 29, 6,
|
||||
5, 13, 51,
|
||||
23, 38, 45,
|
||||
16, 27, 24,
|
||||
46, 32, 44,
|
||||
40, 17, 12,
|
||||
33, 4, 42,
|
||||
43, 10, 3,
|
||||
26, 31, 35,
|
||||
15, 48, 11,
|
||||
8, 49, 7,
|
||||
39, 22, 41
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/8.mzn
Normal file
186
black-hole/table/8.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
43, 50, 35,
|
||||
6, 34, 38,
|
||||
7, 11, 40,
|
||||
51, 36, 3,
|
||||
42, 41, 31,
|
||||
33, 18, 24,
|
||||
49, 28, 2,
|
||||
29, 13, 8,
|
||||
30, 22, 37,
|
||||
25, 9, 26,
|
||||
14, 39, 19,
|
||||
27, 44, 4,
|
||||
17, 23, 47,
|
||||
46, 52, 48,
|
||||
10, 45, 15,
|
||||
5, 16, 21,
|
||||
20, 32, 12
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
186
black-hole/table/9.mzn
Normal file
186
black-hole/table/9.mzn
Normal file
@ -0,0 +1,186 @@
|
||||
%------------------------------------------------------------------------%
|
||||
% Solving the Black Hole Patience game
|
||||
%------------------------------------------------------------------------%
|
||||
%
|
||||
% The model of the problem is taken from "Search in the Patience Game
|
||||
% 'Black Hole'", by Ian P. Gent, Chris Jefferson, Tom Kelsey, Inês
|
||||
% Lynce, Ian Miguel, Peter Nightingale, Barbara M. Smith, and
|
||||
% S. Armagan Tarim. It only implements the basic model. The instances
|
||||
% are generated by the black hole patience model in the Gecode
|
||||
% distribution.
|
||||
%
|
||||
% This model uses the following global constraints
|
||||
% - inverse
|
||||
% - table
|
||||
%
|
||||
% Main authors:
|
||||
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.org>
|
||||
%
|
||||
% Copyright:
|
||||
% Mikael Zayenz Lagerkvist, 2009
|
||||
%
|
||||
% Permission is hereby granted, free of charge, to any person obtaining
|
||||
% a copy of this software and associated documentation files (the
|
||||
% "Software"), to deal in the Software without restriction, including
|
||||
% without limitation the rights to use, copy, modify, merge, publish,
|
||||
% distribute, sublicense, and/or sell copies of the Software, and to
|
||||
% permit persons to whom the Software is furnished to do so, subject to
|
||||
% the following conditions:
|
||||
%
|
||||
% The above copyright notice and this permission notice shall be
|
||||
% included in all copies or substantial portions of the Software.
|
||||
%
|
||||
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
%
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
include "table.mzn";
|
||||
include "inverse.mzn";
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Parameters
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Piles
|
||||
array[1..17, 1..3] of int: layout;
|
||||
|
||||
% Data
|
||||
%layout = array2d(1..17,1..3, [
|
||||
%31, 30, 8,
|
||||
%45, 50, 19,
|
||||
%37, 12, 47,
|
||||
%24, 9, 18,
|
||||
%16, 40, 20,
|
||||
%38, 36, 49,
|
||||
%11, 33, 51,
|
||||
%39, 10, 14,
|
||||
%3, 27, 46,
|
||||
%29, 2, 35,
|
||||
%4, 32, 17,
|
||||
%15, 13, 5,
|
||||
%23, 34, 28,
|
||||
%48, 21, 52,
|
||||
%22, 6, 42,
|
||||
%44, 41, 26,
|
||||
%25, 43, 7
|
||||
%]);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Variables
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Card at position
|
||||
array[1..52] of var 1..52: x;
|
||||
% Position of card
|
||||
array[1..52] of var 1..52: y;
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
% Ace of Spades is first card
|
||||
constraint x[1] == 1;
|
||||
|
||||
% Consecutive cards match
|
||||
constraint forall(i in 1..51) ( adjacent(x[i], x[i+1]) );
|
||||
|
||||
% Link x and y
|
||||
constraint inverse(x, y) :: domain;
|
||||
|
||||
|
||||
% A card must be played before the one under it.
|
||||
constraint
|
||||
forall(i in 1..17, j in 1..2) (
|
||||
y[layout[i,j]] < y[layout[i,j+1]]
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------%
|
||||
% Search
|
||||
%------------------------------------------------------------------------%
|
||||
|
||||
solve :: int_search(x,
|
||||
input_order,
|
||||
indomain_min,
|
||||
complete)
|
||||
satisfy;
|
||||
|
||||
|
||||
output [ "black-hole: ", show(x), "\n" ];
|
||||
%% ---------- DATA ----------
|
||||
layout = array2d(1..17,1..3, [
|
||||
31, 15, 22,
|
||||
43, 35, 20,
|
||||
24, 9, 48,
|
||||
32, 25, 12,
|
||||
8, 52, 27,
|
||||
26, 44, 38,
|
||||
29, 41, 36,
|
||||
28, 23, 10,
|
||||
50, 7, 2,
|
||||
30, 40, 39,
|
||||
4, 13, 33,
|
||||
42, 45, 16,
|
||||
21, 17, 46,
|
||||
5, 18, 14,
|
||||
34, 11, 37,
|
||||
51, 3, 19,
|
||||
6, 49, 47
|
||||
]);
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate adjacent(var 1..52: a, var 1..52: b) =
|
||||
table_int([a, b], array2d(1..416, index_set([a, b]), [2, 1, 13, 1, 15, 1,
|
||||
26, 1, 28, 1, 39, 1, 41, 1, 52, 1, 1, 2, 3, 2, 14, 2, 16, 2, 27, 2, 29, 2,
|
||||
40, 2, 42, 2, 2, 3, 4, 3, 15, 3, 17, 3, 28, 3, 30, 3, 41, 3, 43, 3, 3, 4,
|
||||
5, 4, 16, 4, 18, 4, 29, 4, 31, 4, 42, 4, 44, 4, 4, 5, 6, 5, 17, 5, 19, 5,
|
||||
30, 5, 32, 5, 43, 5, 45, 5, 5, 6, 7, 6, 18, 6, 20, 6, 31, 6, 33, 6, 44, 6,
|
||||
46, 6, 6, 7, 8, 7, 19, 7, 21, 7, 32, 7, 34, 7, 45, 7, 47, 7, 7, 8, 9, 8,
|
||||
20, 8, 22, 8, 33, 8, 35, 8, 46, 8, 48, 8, 8, 9, 10, 9, 21, 9, 23, 9, 34, 9,
|
||||
36, 9, 47, 9, 49, 9, 9, 10, 11, 10, 22, 10, 24, 10, 35, 10, 37, 10, 48, 10,
|
||||
50, 10, 10, 11, 12, 11, 23, 11, 25, 11, 36, 11, 38, 11, 49, 11, 51, 11, 11,
|
||||
12, 13, 12, 24, 12, 26, 12, 37, 12, 39, 12, 50, 12, 52, 12, 1, 13, 12, 13,
|
||||
14, 13, 25, 13, 27, 13, 38, 13, 40, 13, 51, 13, 2, 14, 13, 14, 15, 14, 26,
|
||||
14, 28, 14, 39, 14, 41, 14, 52, 14, 1, 15, 3, 15, 14, 15, 16, 15, 27, 15,
|
||||
29, 15, 40, 15, 42, 15, 2, 16, 4, 16, 15, 16, 17, 16, 28, 16, 30, 16, 41,
|
||||
16, 43, 16, 3, 17, 5, 17, 16, 17, 18, 17, 29, 17, 31, 17, 42, 17, 44, 17,
|
||||
4, 18, 6, 18, 17, 18, 19, 18, 30, 18, 32, 18, 43, 18, 45, 18, 5, 19, 7, 19,
|
||||
18, 19, 20, 19, 31, 19, 33, 19, 44, 19, 46, 19, 6, 20, 8, 20, 19, 20, 21,
|
||||
20, 32, 20, 34, 20, 45, 20, 47, 20, 7, 21, 9, 21, 20, 21, 22, 21, 33, 21,
|
||||
35, 21, 46, 21, 48, 21, 8, 22, 10, 22, 21, 22, 23, 22, 34, 22, 36, 22, 47,
|
||||
22, 49, 22, 9, 23, 11, 23, 22, 23, 24, 23, 35, 23, 37, 23, 48, 23, 50, 23,
|
||||
10, 24, 12, 24, 23, 24, 25, 24, 36, 24, 38, 24, 49, 24, 51, 24, 11, 25, 13,
|
||||
25, 24, 25, 26, 25, 37, 25, 39, 25, 50, 25, 52, 25, 1, 26, 12, 26, 14, 26,
|
||||
25, 26, 27, 26, 38, 26, 40, 26, 51, 26, 2, 27, 13, 27, 15, 27, 26, 27, 28,
|
||||
27, 39, 27, 41, 27, 52, 27, 1, 28, 3, 28, 14, 28, 16, 28, 27, 28, 29, 28,
|
||||
40, 28, 42, 28, 2, 29, 4, 29, 15, 29, 17, 29, 28, 29, 30, 29, 41, 29, 43,
|
||||
29, 3, 30, 5, 30, 16, 30, 18, 30, 29, 30, 31, 30, 42, 30, 44, 30, 4, 31, 6,
|
||||
31, 17, 31, 19, 31, 30, 31, 32, 31, 43, 31, 45, 31, 5, 32, 7, 32, 18, 32,
|
||||
20, 32, 31, 32, 33, 32, 44, 32, 46, 32, 6, 33, 8, 33, 19, 33, 21, 33, 32,
|
||||
33, 34, 33, 45, 33, 47, 33, 7, 34, 9, 34, 20, 34, 22, 34, 33, 34, 35, 34,
|
||||
46, 34, 48, 34, 8, 35, 10, 35, 21, 35, 23, 35, 34, 35, 36, 35, 47, 35, 49,
|
||||
35, 9, 36, 11, 36, 22, 36, 24, 36, 35, 36, 37, 36, 48, 36, 50, 36, 10, 37,
|
||||
12, 37, 23, 37, 25, 37, 36, 37, 38, 37, 49, 37, 51, 37, 11, 38, 13, 38, 24,
|
||||
38, 26, 38, 37, 38, 39, 38, 50, 38, 52, 38, 1, 39, 12, 39, 14, 39, 25, 39,
|
||||
27, 39, 38, 39, 40, 39, 51, 39, 2, 40, 13, 40, 15, 40, 26, 40, 28, 40, 39,
|
||||
40, 41, 40, 52, 40, 1, 41, 3, 41, 14, 41, 16, 41, 27, 41, 29, 41, 40, 41,
|
||||
42, 41, 2, 42, 4, 42, 15, 42, 17, 42, 28, 42, 30, 42, 41, 42, 43, 42, 3,
|
||||
43, 5, 43, 16, 43, 18, 43, 29, 43, 31, 43, 42, 43, 44, 43, 4, 44, 6, 44,
|
||||
17, 44, 19, 44, 30, 44, 32, 44, 43, 44, 45, 44, 5, 45, 7, 45, 18, 45, 20,
|
||||
45, 31, 45, 33, 45, 44, 45, 46, 45, 6, 46, 8, 46, 19, 46, 21, 46, 32, 46,
|
||||
34, 46, 45, 46, 47, 46, 7, 47, 9, 47, 20, 47, 22, 47, 33, 47, 35, 47, 46,
|
||||
47, 48, 47, 8, 48, 10, 48, 21, 48, 23, 48, 34, 48, 36, 48, 47, 48, 49, 48,
|
||||
9, 49, 11, 49, 22, 49, 24, 49, 35, 49, 37, 49, 48, 49, 50, 49, 10, 50, 12,
|
||||
50, 23, 50, 25, 50, 36, 50, 38, 50, 49, 50, 51, 50, 11, 51, 13, 51, 24, 51,
|
||||
26, 51, 37, 51, 39, 51, 50, 51, 52, 51, 1, 52, 12, 52, 14, 52, 25, 52, 27,
|
||||
52, 38, 52, 40, 52, 51, 52]));
|
||||
|
179
block-party/table/1176.mzn
Normal file
179
block-party/table/1176.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 52, 29, 10, 60, 23, 24, 7, 31, 48, 47, 1, 26, 37, 22, 61, 5, 58, 27, 25, 28, 2, 40, 21, 14 |
|
||||
45, 22, 36, 9, 51, 53, 44, 5, 30, 49, 46, 57, 43, 23, 60, 29, 18, 34, 27, 14, 61, 59, 41, 1 |
|
||||
53, 13, 5, 20, 63, 24, 60, 59, 31, 51, 56, 49, 22, 12, 28, 47, 40, 52, 27, 39, 26, 43, 54, 57 |
|
||||
13, 41, 39, 8, 33, 35, 46, 55, 0, 24, 62, 61, 54, 34, 20, 50, 51, 6, 63, 52, 1, 18, 21, 11 |
|
||||
37, 18, 33, 9, 30, 56, 50, 8, 4, 42, 23, 13, 43, 45, 21, 0, 12, 41, 20, 63, 28, 38, 36, 7 |
|
||||
49, 34, 0, 56, 47, 57, 26, 54, 35, 32, 3, 29, 10, 39, 19, 58, 59, 9, 2, 17, 36, 8, 15, 16 |
|
||||
58, 19, 53, 3, 62, 12, 55, 32, 42, 48, 6, 15, 16, 50, 30, 35, 33, 17, 4, 25, 11, 2, 38, 44 |
|
||||
14, 48, 42, 3, 55, 25, 4, 11, 38, 37, 44, 19, 46, 31, 16, 15, 32, 7, 6, 45, 17, 10, 40, 62 |]
|
||||
;
|
||||
% cubes: [4, 3, 7, 6, 2, 5, 1, 8]
|
||||
% symbols: [46, 22, 2, 58, 18, 23, 28, 25, 1, 27, 53, 49, 41, 36, 29, 14, 61, 31, 32, 57, 46, 12, 22, 15]
|
||||
% rotations: [9, 15, 4, 13, 20, 22, 18, 11]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 21, 58, 1, 1, 26, 7, 2, 1,
|
||||
52, 24, 5, 1, 2, 26, 7, 1, 40, 31, 10, 1, 60, 27, 14, 1, 58, 1, 21, 1, 28,
|
||||
29, 22, 1, 47, 61, 23, 1, 5, 52, 24, 1, 37, 48, 25, 1, 7, 2, 26, 1, 14, 60,
|
||||
27, 1, 29, 22, 28, 1, 22, 28, 29, 1, 10, 40, 31, 1, 48, 25, 37, 1, 31, 10,
|
||||
40, 1, 61, 23, 47, 1, 25, 37, 48, 1, 24, 5, 52, 1, 1, 21, 58, 1, 27, 14,
|
||||
60, 1, 23, 47, 61, 2, 9, 34, 1, 2, 36, 59, 5, 2, 34, 1, 9, 2, 22, 23, 14,
|
||||
2, 46, 41, 18, 2, 23, 14, 22, 2, 14, 22, 23, 2, 43, 30, 27, 2, 45, 53, 29,
|
||||
2, 27, 43, 30, 2, 1, 9, 34, 2, 59, 5, 36, 2, 18, 46, 41, 2, 30, 27, 43, 2,
|
||||
61, 57, 44, 2, 53, 29, 45, 2, 41, 18, 46, 2, 60, 51, 49, 2, 49, 60, 51, 2,
|
||||
29, 45, 53, 2, 44, 61, 57, 2, 5, 36, 59, 2, 51, 49, 60, 2, 57, 44, 61, 3,
|
||||
43, 59, 5, 3, 39, 13, 12, 3, 12, 39, 13, 3, 52, 57, 20, 3, 31, 27, 22, 3,
|
||||
47, 53, 24, 3, 49, 60, 26, 3, 22, 31, 27, 3, 63, 51, 28, 3, 27, 22, 31, 3,
|
||||
13, 12, 39, 3, 56, 54, 40, 3, 59, 5, 43, 3, 53, 24, 47, 3, 60, 26, 49, 3,
|
||||
28, 63, 51, 3, 57, 20, 52, 3, 24, 47, 53, 3, 40, 56, 54, 3, 54, 40, 56, 3,
|
||||
20, 52, 57, 3, 5, 43, 59, 3, 26, 49, 60, 3, 51, 28, 63, 4, 63, 54, 0, 4,
|
||||
61, 46, 1, 4, 11, 8, 6, 4, 6, 11, 8, 4, 8, 6, 11, 4, 35, 50, 13, 4, 55, 39,
|
||||
18, 4, 33, 24, 20, 4, 51, 62, 21, 4, 20, 33, 24, 4, 24, 20, 33, 4, 52, 41,
|
||||
34, 4, 50, 13, 35, 4, 18, 55, 39, 4, 34, 52, 41, 4, 1, 61, 46, 4, 13, 35,
|
||||
50, 4, 62, 21, 51, 4, 41, 34, 52, 4, 0, 63, 54, 4, 39, 18, 55, 4, 46, 1,
|
||||
61, 4, 21, 51, 62, 4, 54, 0, 63, 5, 37, 56, 0, 5, 20, 43, 4, 5, 9, 41, 7,
|
||||
5, 33, 38, 8, 5, 41, 7, 9, 5, 23, 36, 12, 5, 50, 28, 13, 5, 45, 63, 18, 5,
|
||||
43, 4, 20, 5, 30, 42, 21, 5, 36, 12, 23, 5, 13, 50, 28, 5, 42, 21, 30, 5,
|
||||
38, 8, 33, 5, 12, 23, 36, 5, 56, 0, 37, 5, 8, 33, 38, 5, 7, 9, 41, 5, 21,
|
||||
30, 42, 5, 4, 20, 43, 5, 63, 18, 45, 5, 28, 13, 50, 5, 0, 37, 56, 5, 18,
|
||||
45, 63, 6, 8, 54, 0, 6, 10, 35, 2, 6, 15, 59, 3, 6, 54, 0, 8, 6, 16, 56, 9,
|
||||
6, 35, 2, 10, 6, 59, 3, 15, 6, 56, 9, 16, 6, 34, 39, 17, 6, 47, 32, 19, 6,
|
||||
36, 29, 26, 6, 26, 36, 29, 6, 19, 47, 32, 6, 39, 17, 34, 6, 2, 10, 35, 6,
|
||||
29, 26, 36, 6, 17, 34, 39, 6, 32, 19, 47, 6, 57, 58, 49, 6, 0, 8, 54, 6, 9,
|
||||
16, 56, 6, 58, 49, 57, 6, 49, 57, 58, 6, 3, 15, 59, 7, 32, 53, 2, 7, 17,
|
||||
44, 3, 7, 16, 42, 4, 7, 38, 33, 6, 7, 15, 55, 11, 7, 35, 58, 12, 7, 55, 11,
|
||||
15, 7, 42, 4, 16, 7, 44, 3, 17, 7, 50, 25, 19, 7, 19, 50, 25, 7, 62, 48,
|
||||
30, 7, 53, 2, 32, 7, 6, 38, 33, 7, 58, 12, 35, 7, 33, 6, 38, 7, 4, 16, 42,
|
||||
7, 3, 17, 44, 7, 30, 62, 48, 7, 25, 19, 50, 7, 2, 32, 53, 7, 11, 15, 55, 7,
|
||||
12, 35, 58, 7, 48, 30, 62, 8, 7, 62, 3, 8, 17, 19, 4, 8, 46, 38, 6, 8, 62,
|
||||
3, 7, 8, 11, 42, 10, 8, 42, 10, 11, 8, 25, 15, 14, 8, 14, 25, 15, 8, 55,
|
||||
37, 16, 8, 19, 4, 17, 8, 4, 17, 19, 8, 15, 14, 25, 8, 45, 48, 31, 8, 44,
|
||||
40, 32, 8, 16, 55, 37, 8, 6, 46, 38, 8, 32, 44, 40, 8, 10, 11, 42, 8, 40,
|
||||
32, 44, 8, 48, 31, 45, 8, 38, 6, 46, 8, 31, 45, 48, 8, 37, 16, 55, 8, 3, 7,
|
||||
62]));
|
||||
|
179
block-party/table/1266.mzn
Normal file
179
block-party/table/1266.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 14, 2, 29, 16, 33, 3, 63, 47, 6, 26, 19, 34, 31, 44, 23, 9, 38, 49, 27, 7, 32, 37, 52, 17 |
|
||||
14, 47, 57, 53, 59, 37, 48, 41, 27, 12, 7, 52, 20, 44, 17, 21, 13, 43, 1, 10, 6, 23, 39, 9 |
|
||||
2, 27, 18, 10, 35, 53, 7, 33, 58, 57, 50, 30, 36, 31, 14, 4, 44, 12, 63, 49, 23, 52, 15, 19 |
|
||||
25, 34, 3, 40, 2, 33, 16, 43, 18, 31, 45, 21, 48, 10, 53, 24, 28, 59, 41, 4, 13, 57, 35, 63 |
|
||||
38, 18, 36, 26, 41, 60, 43, 22, 48, 28, 42, 46, 9, 20, 50, 56, 3, 37, 24, 17, 39, 8, 62, 45 |
|
||||
46, 0, 1, 16, 15, 25, 4, 19, 30, 34, 36, 13, 61, 51, 60, 40, 8, 26, 39, 11, 54, 5, 55, 62 |
|
||||
46, 29, 6, 30, 25, 59, 62, 35, 60, 28, 38, 11, 32, 5, 56, 42, 0, 54, 51, 22, 55, 1, 61, 58 |
|
||||
42, 32, 54, 21, 11, 49, 24, 15, 29, 58, 8, 51, 0, 55, 22, 50, 5, 45, 40, 12, 47, 61, 20, 56 |]
|
||||
;
|
||||
% cubes: [8, 3, 2, 7, 1, 6, 5, 4]
|
||||
% symbols: [49, 33, 17, 1, 31, 16, 26, 21, 50, 52, 12, 35, 27, 26, 37, 13, 42, 18, 59, 6, 6, 62, 45, 16]
|
||||
% rotations: [11, 12, 14, 4, 15, 7, 7, 21]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 44, 7, 2, 1, 9, 14, 3, 1,
|
||||
27, 31, 6, 1, 2, 44, 7, 1, 14, 3, 9, 1, 3, 9, 14, 1, 49, 17, 16, 1, 16, 49,
|
||||
17, 1, 52, 38, 19, 1, 33, 26, 23, 1, 23, 33, 26, 1, 31, 6, 27, 1, 37, 47,
|
||||
29, 1, 6, 27, 31, 1, 34, 63, 32, 1, 26, 23, 33, 1, 63, 32, 34, 1, 47, 29,
|
||||
37, 1, 19, 52, 38, 1, 7, 2, 44, 1, 29, 37, 47, 1, 17, 16, 49, 1, 38, 19,
|
||||
52, 1, 32, 34, 63, 2, 20, 27, 1, 2, 52, 48, 6, 2, 39, 13, 7, 2, 53, 43, 9,
|
||||
2, 47, 44, 10, 2, 17, 59, 12, 2, 7, 39, 13, 2, 37, 21, 14, 2, 59, 12, 17,
|
||||
2, 27, 1, 20, 2, 14, 37, 21, 2, 41, 57, 23, 2, 1, 20, 27, 2, 21, 14, 37, 2,
|
||||
13, 7, 39, 2, 57, 23, 41, 2, 9, 53, 43, 2, 10, 47, 44, 2, 44, 10, 47, 2, 6,
|
||||
52, 48, 2, 48, 6, 52, 2, 43, 9, 53, 2, 23, 41, 57, 2, 12, 17, 59, 3, 53, 4,
|
||||
2, 3, 2, 53, 4, 3, 23, 30, 7, 3, 12, 19, 10, 3, 19, 10, 12, 3, 35, 57, 14,
|
||||
3, 44, 50, 15, 3, 52, 33, 18, 3, 10, 12, 19, 3, 30, 7, 23, 3, 31, 49, 27,
|
||||
3, 7, 23, 30, 3, 49, 27, 31, 3, 18, 52, 33, 3, 57, 14, 35, 3, 58, 63, 36,
|
||||
3, 50, 15, 44, 3, 27, 31, 49, 3, 15, 44, 50, 3, 33, 18, 52, 3, 4, 2, 53, 3,
|
||||
14, 35, 57, 3, 63, 36, 58, 3, 36, 58, 63, 4, 31, 53, 2, 4, 57, 43, 3, 4,
|
||||
34, 10, 4, 4, 4, 34, 10, 4, 21, 16, 13, 4, 13, 21, 16, 4, 41, 48, 18, 4,
|
||||
16, 13, 21, 4, 25, 33, 24, 4, 33, 24, 25, 4, 45, 35, 28, 4, 53, 2, 31, 4,
|
||||
24, 25, 33, 4, 10, 4, 34, 4, 28, 45, 35, 4, 59, 63, 40, 4, 48, 18, 41, 4,
|
||||
3, 57, 43, 4, 35, 28, 45, 4, 18, 41, 48, 4, 2, 31, 53, 4, 43, 3, 57, 4, 63,
|
||||
40, 59, 4, 40, 59, 63, 5, 42, 62, 3, 5, 22, 36, 8, 5, 48, 24, 9, 5, 18, 20,
|
||||
17, 5, 20, 17, 18, 5, 17, 18, 20, 5, 36, 8, 22, 5, 9, 48, 24, 5, 37, 45,
|
||||
26, 5, 50, 41, 28, 5, 8, 22, 36, 5, 45, 26, 37, 5, 60, 56, 38, 5, 46, 43,
|
||||
39, 5, 28, 50, 41, 5, 62, 3, 42, 5, 39, 46, 43, 5, 26, 37, 45, 5, 43, 39,
|
||||
46, 5, 24, 9, 48, 5, 41, 28, 50, 5, 38, 60, 56, 5, 56, 38, 60, 5, 3, 42,
|
||||
62, 6, 51, 11, 0, 6, 5, 19, 1, 6, 54, 13, 4, 6, 19, 1, 5, 6, 36, 55, 8, 6,
|
||||
0, 51, 11, 6, 4, 54, 13, 6, 34, 60, 15, 6, 26, 62, 16, 6, 1, 5, 19, 6, 40,
|
||||
46, 25, 6, 62, 16, 26, 6, 39, 61, 30, 6, 60, 15, 34, 6, 55, 8, 36, 6, 61,
|
||||
30, 39, 6, 46, 25, 40, 6, 25, 40, 46, 6, 11, 0, 51, 6, 13, 4, 54, 6, 8, 36,
|
||||
55, 6, 15, 34, 60, 6, 30, 39, 61, 6, 16, 26, 62, 7, 38, 61, 0, 7, 35, 6, 1,
|
||||
7, 22, 29, 5, 7, 1, 35, 6, 7, 62, 55, 11, 7, 29, 5, 22, 7, 28, 56, 25, 7,
|
||||
56, 25, 28, 7, 5, 22, 29, 7, 54, 58, 30, 7, 60, 51, 32, 7, 6, 1, 35, 7, 61,
|
||||
0, 38, 7, 46, 59, 42, 7, 59, 42, 46, 7, 32, 60, 51, 7, 58, 30, 54, 7, 11,
|
||||
62, 55, 7, 25, 28, 56, 7, 30, 54, 58, 7, 42, 46, 59, 7, 51, 32, 60, 7, 0,
|
||||
38, 61, 7, 55, 11, 62, 8, 29, 40, 0, 8, 8, 20, 5, 8, 20, 5, 8, 8, 58, 22,
|
||||
11, 8, 32, 55, 12, 8, 54, 61, 15, 8, 5, 8, 20, 8, 45, 56, 21, 8, 11, 58,
|
||||
22, 8, 47, 51, 24, 8, 40, 0, 29, 8, 55, 12, 32, 8, 0, 29, 40, 8, 49, 50,
|
||||
42, 8, 56, 21, 45, 8, 51, 24, 47, 8, 50, 42, 49, 8, 42, 49, 50, 8, 24, 47,
|
||||
51, 8, 61, 15, 54, 8, 12, 32, 55, 8, 21, 45, 56, 8, 22, 11, 58, 8, 15, 54,
|
||||
61]));
|
||||
|
178
block-party/table/2254.mzn
Normal file
178
block-party/table/2254.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 63, 11, 0, 62, 39, 55, 15, 60, 19, 29, 45, 46, 9, 44, 21, 41, 7, 56, 26, 18, 34, 38, 52, 23 |
|
||||
31, 6, 10, 38, 51, 57, 42, 44, 16, 48, 11, 4, 15, 63, 35, 2, 49, 25, 8, 47, 54, 39, 21, 9 |
|
||||
23, 62, 49, 9, 25, 44, 55, 63, 11, 60, 36, 39, 33, 10, 21, 19, 56, 17, 6, 34, 32, 61, 59, 7 |
|
||||
49, 25, 57, 6, 42, 13, 41, 5, 36, 16, 28, 7, 50, 27, 2, 20, 10, 38, 35, 26, 0, 55, 43, 32 |
|
||||
47, 43, 12, 19, 54, 52, 28, 46, 42, 24, 20, 45, 0, 23, 48, 29, 3, 58, 18, 50, 16, 37, 2, 56 |
|
||||
30, 8, 50, 4, 40, 32, 46, 59, 48, 1, 5, 17, 27, 37, 28, 34, 12, 18, 45, 20, 35, 14, 53, 22 |
|
||||
43, 51, 54, 59, 17, 24, 37, 61, 60, 58, 14, 40, 29, 8, 36, 1, 31, 13, 62, 22, 3, 30, 33, 53 |
|
||||
57, 33, 31, 3, 61, 5, 15, 22, 12, 58, 1, 4, 14, 53, 30, 26, 40, 51, 41, 24, 52, 13, 27, 47 |]
|
||||
;
|
||||
% cubes: [4, 7, 6, 8, 5, 2, 3, 1]
|
||||
% symbols: [28, 62, 45, 15, 47, 51, 11, 23, 43, 60, 48, 52, 29, 48, 6, 56, 10, 29, 27, 4, 52, 35, 33, 62]
|
||||
% rotations: [22, 19, 19, 9, 5, 10, 23, 3]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 38, 60, 0, 1, 45, 52, 7,
|
||||
1, 19, 26, 9, 1, 44, 18, 11, 1, 34, 46, 15, 1, 11, 44, 18, 1, 26, 9, 19, 1,
|
||||
39, 29, 21, 1, 62, 56, 23, 1, 9, 19, 26, 1, 21, 39, 29, 1, 46, 15, 34, 1,
|
||||
60, 0, 38, 1, 29, 21, 39, 1, 63, 55, 41, 1, 18, 11, 44, 1, 52, 7, 45, 1,
|
||||
15, 34, 46, 1, 7, 45, 52, 1, 41, 63, 55, 1, 23, 62, 56, 1, 0, 38, 60, 1,
|
||||
56, 23, 62, 1, 55, 41, 63, 2, 31, 57, 2, 2, 42, 54, 4, 2, 63, 47, 6, 2, 15,
|
||||
16, 8, 2, 38, 25, 9, 2, 39, 44, 10, 2, 21, 49, 11, 2, 16, 8, 15, 2, 8, 15,
|
||||
16, 2, 49, 11, 21, 2, 9, 38, 25, 2, 57, 2, 31, 2, 51, 48, 35, 2, 25, 9, 38,
|
||||
2, 44, 10, 39, 2, 54, 4, 42, 2, 10, 39, 44, 2, 6, 63, 47, 2, 35, 51, 48, 2,
|
||||
11, 21, 49, 2, 48, 35, 51, 2, 4, 42, 54, 2, 2, 31, 57, 2, 47, 6, 63, 3, 33,
|
||||
11, 6, 3, 9, 17, 7, 3, 17, 7, 9, 3, 34, 62, 10, 3, 6, 33, 11, 3, 7, 9, 17,
|
||||
3, 23, 44, 19, 3, 25, 60, 21, 3, 44, 19, 23, 3, 60, 21, 25, 3, 39, 55, 32,
|
||||
3, 11, 6, 33, 3, 62, 10, 34, 3, 59, 56, 36, 3, 55, 32, 39, 3, 19, 23, 44,
|
||||
3, 61, 63, 49, 3, 32, 39, 55, 3, 36, 59, 56, 3, 56, 36, 59, 3, 21, 25, 60,
|
||||
3, 63, 49, 61, 3, 10, 34, 62, 3, 49, 61, 63, 4, 7, 41, 0, 4, 42, 16, 2, 4,
|
||||
57, 55, 5, 4, 38, 32, 6, 4, 41, 0, 7, 4, 28, 43, 10, 4, 20, 49, 13, 4, 2,
|
||||
42, 16, 4, 49, 13, 20, 4, 27, 26, 25, 4, 25, 27, 26, 4, 26, 25, 27, 4, 43,
|
||||
10, 28, 4, 6, 38, 32, 4, 50, 36, 35, 4, 35, 50, 36, 4, 32, 6, 38, 4, 0, 7,
|
||||
41, 4, 16, 2, 42, 4, 10, 28, 43, 4, 13, 20, 49, 4, 36, 35, 50, 4, 5, 57,
|
||||
55, 4, 55, 5, 57, 5, 42, 18, 0, 5, 3, 20, 2, 5, 20, 2, 3, 5, 37, 46, 12, 5,
|
||||
45, 28, 16, 5, 0, 42, 18, 5, 58, 56, 19, 5, 2, 3, 20, 5, 50, 43, 23, 5, 48,
|
||||
54, 24, 5, 16, 45, 28, 5, 47, 52, 29, 5, 46, 12, 37, 5, 18, 0, 42, 5, 23,
|
||||
50, 43, 5, 28, 16, 45, 5, 12, 37, 46, 5, 52, 29, 47, 5, 54, 24, 48, 5, 43,
|
||||
23, 50, 5, 29, 47, 52, 5, 24, 48, 54, 5, 19, 58, 56, 5, 56, 19, 58, 6, 28,
|
||||
40, 1, 6, 18, 22, 4, 6, 53, 12, 5, 6, 37, 20, 8, 6, 5, 53, 12, 6, 59, 50,
|
||||
14, 6, 46, 35, 17, 6, 22, 4, 18, 6, 8, 37, 20, 6, 4, 18, 22, 6, 48, 45, 27,
|
||||
6, 40, 1, 28, 6, 32, 34, 30, 6, 34, 30, 32, 6, 30, 32, 34, 6, 17, 46, 35,
|
||||
6, 20, 8, 37, 6, 1, 28, 40, 6, 27, 48, 45, 6, 35, 17, 46, 6, 45, 27, 48, 6,
|
||||
14, 59, 50, 6, 12, 5, 53, 6, 50, 14, 59, 7, 43, 24, 1, 7, 40, 37, 3, 7, 22,
|
||||
51, 8, 7, 53, 59, 13, 7, 33, 31, 14, 7, 58, 36, 17, 7, 51, 8, 22, 7, 1, 43,
|
||||
24, 7, 60, 62, 29, 7, 61, 54, 30, 7, 14, 33, 31, 7, 31, 14, 33, 7, 17, 58,
|
||||
36, 7, 3, 40, 37, 7, 37, 3, 40, 7, 24, 1, 43, 7, 8, 22, 51, 7, 59, 13, 53,
|
||||
7, 30, 61, 54, 7, 36, 17, 58, 7, 13, 53, 59, 7, 62, 29, 60, 7, 54, 30, 61,
|
||||
7, 29, 60, 62, 8, 27, 40, 1, 8, 51, 47, 3, 8, 15, 52, 4, 8, 26, 57, 5, 8,
|
||||
41, 14, 12, 8, 22, 31, 13, 8, 12, 41, 14, 8, 52, 4, 15, 8, 31, 13, 22, 8,
|
||||
33, 53, 24, 8, 57, 5, 26, 8, 40, 1, 27, 8, 61, 58, 30, 8, 13, 22, 31, 8,
|
||||
53, 24, 33, 8, 1, 27, 40, 8, 14, 12, 41, 8, 3, 51, 47, 8, 47, 3, 51, 8, 4,
|
||||
15, 52, 8, 24, 33, 53, 8, 5, 26, 57, 8, 30, 61, 58, 8, 58, 30, 61]));
|
||||
|
179
block-party/table/3237.mzn
Normal file
179
block-party/table/3237.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 10, 56, 12, 7, 39, 22, 33, 59, 21, 6, 30, 55, 27, 3, 41, 44, 57, 4, 28, 26, 60, 49, 15, 2 |
|
||||
33, 22, 38, 51, 57, 10, 1, 48, 18, 0, 21, 23, 14, 8, 27, 30, 26, 34, 11, 52, 12, 40, 63, 45 |
|
||||
34, 38, 12, 57, 54, 6, 61, 43, 58, 53, 20, 7, 25, 60, 33, 0, 40, 9, 37, 19, 15, 8, 30, 51 |
|
||||
24, 46, 15, 16, 58, 0, 7, 53, 42, 54, 21, 5, 38, 13, 45, 55, 29, 22, 56, 50, 11, 59, 34, 17 |
|
||||
39, 46, 52, 48, 41, 6, 51, 49, 32, 60, 20, 53, 2, 1, 40, 45, 13, 26, 29, 27, 50, 56, 63, 4 |
|
||||
39, 5, 52, 61, 41, 19, 24, 20, 48, 23, 36, 63, 11, 13, 42, 46, 49, 54, 62, 37, 47, 31, 35, 8 |
|
||||
61, 44, 43, 42, 29, 16, 37, 4, 25, 62, 32, 9, 5, 36, 10, 24, 3, 31, 14, 28, 47, 35, 17, 18 |
|
||||
19, 23, 16, 14, 32, 50, 44, 18, 25, 55, 43, 1, 28, 2, 9, 58, 35, 62, 3, 59, 36, 31, 47, 17 |]
|
||||
;
|
||||
% cubes: [4, 8, 5, 7, 2, 6, 3, 1]
|
||||
% symbols: [42, 58, 26, 10, 22, 54, 38, 6, 56, 50, 48, 29, 52, 8, 60, 39, 38, 19, 4, 62, 8, 61, 19, 41]
|
||||
% rotations: [23, 13, 17, 14, 6, 17, 6, 24]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 7, 4, 2, 1, 26, 56, 3, 1,
|
||||
2, 7, 4, 1, 41, 39, 6, 1, 4, 2, 7, 1, 22, 44, 10, 1, 49, 59, 12, 1, 57, 30,
|
||||
15, 1, 28, 27, 21, 1, 44, 10, 22, 1, 56, 3, 26, 1, 21, 28, 27, 1, 27, 21,
|
||||
28, 1, 15, 57, 30, 1, 60, 55, 33, 1, 6, 41, 39, 1, 39, 6, 41, 1, 10, 22,
|
||||
44, 1, 59, 12, 49, 1, 33, 60, 55, 1, 3, 26, 56, 1, 30, 15, 57, 1, 12, 49,
|
||||
59, 1, 55, 33, 60, 2, 27, 57, 0, 2, 12, 23, 1, 2, 52, 22, 8, 2, 30, 33, 10,
|
||||
2, 14, 18, 11, 2, 23, 1, 12, 2, 18, 11, 14, 2, 11, 14, 18, 2, 63, 26, 21,
|
||||
2, 8, 52, 22, 2, 1, 12, 23, 2, 21, 63, 26, 2, 57, 0, 27, 2, 33, 10, 30, 2,
|
||||
10, 30, 33, 2, 45, 51, 34, 2, 40, 48, 38, 2, 48, 38, 40, 2, 51, 34, 45, 2,
|
||||
38, 40, 48, 2, 34, 45, 51, 2, 22, 8, 52, 2, 0, 27, 57, 2, 26, 21, 63, 3,
|
||||
34, 6, 0, 3, 0, 34, 6, 3, 61, 15, 7, 3, 43, 12, 8, 3, 51, 57, 9, 3, 8, 43,
|
||||
12, 3, 7, 61, 15, 3, 38, 60, 19, 3, 30, 40, 20, 3, 58, 37, 25, 3, 40, 20,
|
||||
30, 3, 54, 53, 33, 3, 6, 0, 34, 3, 25, 58, 37, 3, 60, 19, 38, 3, 20, 30,
|
||||
40, 3, 12, 8, 43, 3, 57, 9, 51, 3, 33, 54, 53, 3, 53, 33, 54, 3, 9, 51, 57,
|
||||
3, 37, 25, 58, 3, 19, 38, 60, 3, 15, 7, 61, 4, 55, 24, 0, 4, 7, 11, 5, 4,
|
||||
11, 5, 7, 4, 5, 7, 11, 4, 50, 46, 13, 4, 59, 53, 15, 4, 22, 17, 16, 4, 16,
|
||||
22, 17, 4, 34, 29, 21, 4, 17, 16, 22, 4, 0, 55, 24, 4, 21, 34, 29, 4, 29,
|
||||
21, 34, 4, 42, 56, 38, 4, 56, 38, 42, 4, 58, 54, 45, 4, 13, 50, 46, 4, 46,
|
||||
13, 50, 4, 15, 59, 53, 4, 45, 58, 54, 4, 24, 0, 55, 4, 38, 42, 56, 4, 54,
|
||||
45, 58, 4, 53, 15, 59, 5, 27, 46, 1, 5, 32, 29, 2, 5, 48, 26, 4, 5, 45, 39,
|
||||
6, 5, 20, 63, 13, 5, 63, 13, 20, 5, 4, 48, 26, 5, 46, 1, 27, 5, 2, 32, 29,
|
||||
5, 29, 2, 32, 5, 6, 45, 39, 5, 41, 60, 40, 5, 60, 40, 41, 5, 39, 6, 45, 5,
|
||||
1, 27, 46, 5, 26, 4, 48, 5, 52, 56, 49, 5, 53, 51, 50, 5, 50, 53, 51, 5,
|
||||
56, 49, 52, 5, 51, 50, 53, 5, 49, 52, 56, 5, 40, 41, 60, 5, 13, 20, 63, 6,
|
||||
13, 37, 5, 6, 61, 54, 8, 6, 48, 62, 11, 6, 37, 5, 13, 6, 46, 39, 19, 6, 52,
|
||||
31, 20, 6, 42, 41, 23, 6, 47, 63, 24, 6, 20, 52, 31, 6, 49, 36, 35, 6, 35,
|
||||
49, 36, 6, 5, 13, 37, 6, 19, 46, 39, 6, 23, 42, 41, 6, 41, 23, 42, 6, 39,
|
||||
19, 46, 6, 63, 24, 47, 6, 62, 11, 48, 6, 36, 35, 49, 6, 31, 20, 52, 6, 8,
|
||||
61, 54, 6, 54, 8, 61, 6, 11, 48, 62, 6, 24, 47, 63, 7, 32, 17, 3, 7, 43,
|
||||
35, 4, 7, 25, 14, 5, 7, 37, 47, 9, 7, 29, 62, 10, 7, 5, 25, 14, 7, 24, 61,
|
||||
16, 7, 3, 32, 17, 7, 42, 31, 18, 7, 61, 16, 24, 7, 14, 5, 25, 7, 44, 36,
|
||||
28, 7, 62, 10, 29, 7, 18, 42, 31, 7, 17, 3, 32, 7, 4, 43, 35, 7, 28, 44,
|
||||
36, 7, 47, 9, 37, 7, 31, 18, 42, 7, 35, 4, 43, 7, 36, 28, 44, 7, 9, 37, 47,
|
||||
7, 16, 24, 61, 7, 10, 29, 62, 8, 44, 36, 1, 8, 59, 23, 2, 8, 28, 25, 3, 8,
|
||||
32, 55, 9, 8, 62, 17, 14, 8, 31, 18, 16, 8, 14, 62, 17, 8, 16, 31, 18, 8,
|
||||
50, 58, 19, 8, 2, 59, 23, 8, 3, 28, 25, 8, 25, 3, 28, 8, 18, 16, 31, 8, 55,
|
||||
9, 32, 8, 43, 47, 35, 8, 1, 44, 36, 8, 47, 35, 43, 8, 36, 1, 44, 8, 35, 43,
|
||||
47, 8, 58, 19, 50, 8, 9, 32, 55, 8, 19, 50, 58, 8, 23, 2, 59, 8, 17, 14,
|
||||
62]));
|
||||
|
179
block-party/table/3345.mzn
Normal file
179
block-party/table/3345.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 56, 29, 24, 47, 38, 15, 50, 10, 63, 30, 40, 41, 39, 62, 2, 33, 34, 36, 54, 5, 25, 7, 55, 48 |
|
||||
27, 39, 35, 46, 8, 7, 21, 54, 18, 15, 25, 1, 29, 40, 38, 63, 32, 41, 62, 16, 53, 60, 17, 52 |
|
||||
20, 25, 43, 54, 10, 50, 57, 16, 39, 7, 63, 38, 31, 36, 42, 47, 5, 33, 2, 0, 48, 56, 11, 1 |
|
||||
21, 17, 41, 11, 58, 46, 9, 47, 51, 29, 60, 33, 26, 37, 1, 31, 23, 4, 10, 6, 12, 8, 28, 45 |
|
||||
28, 19, 42, 4, 43, 26, 57, 14, 2, 34, 13, 27, 59, 61, 36, 11, 23, 50, 5, 24, 45, 40, 32, 30 |
|
||||
4, 35, 12, 59, 61, 27, 24, 26, 3, 20, 34, 18, 13, 6, 48, 51, 58, 44, 53, 57, 45, 37, 22, 49 |
|
||||
52, 8, 56, 9, 13, 22, 16, 43, 23, 6, 18, 19, 55, 62, 49, 35, 3, 42, 14, 12, 37, 53, 44, 0 |
|
||||
49, 51, 30, 15, 20, 31, 14, 52, 61, 9, 44, 0, 55, 46, 32, 21, 28, 17, 60, 58, 59, 22, 19, 3 |]
|
||||
;
|
||||
% cubes: [5, 3, 6, 1, 7, 8, 4, 2]
|
||||
% symbols: [2, 38, 26, 62, 43, 51, 31, 7, 5, 48, 37, 5, 53, 46, 21, 27, 59, 57, 12, 29, 56, 58, 46, 63]
|
||||
% rotations: [23, 21, 12, 16, 12, 6, 13, 11]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 38, 30, 2, 1, 29, 62, 5,
|
||||
1, 10, 24, 7, 1, 24, 7, 10, 1, 33, 56, 15, 1, 7, 10, 24, 1, 41, 50, 25, 1,
|
||||
62, 5, 29, 1, 2, 38, 30, 1, 56, 15, 33, 1, 40, 55, 34, 1, 48, 47, 36, 1,
|
||||
30, 2, 38, 1, 63, 54, 39, 1, 55, 34, 40, 1, 50, 25, 41, 1, 36, 48, 47, 1,
|
||||
47, 36, 48, 1, 25, 41, 50, 1, 39, 63, 54, 1, 34, 40, 55, 1, 15, 33, 56, 1,
|
||||
5, 29, 62, 1, 54, 39, 63, 2, 21, 53, 1, 2, 63, 27, 7, 2, 15, 38, 8, 2, 38,
|
||||
8, 15, 2, 39, 40, 16, 2, 32, 25, 17, 2, 62, 29, 18, 2, 53, 1, 21, 2, 17,
|
||||
32, 25, 2, 7, 63, 27, 2, 18, 62, 29, 2, 25, 17, 32, 2, 60, 54, 35, 2, 8,
|
||||
15, 38, 2, 40, 16, 39, 2, 16, 39, 40, 2, 52, 46, 41, 2, 41, 52, 46, 2, 46,
|
||||
41, 52, 2, 1, 21, 53, 2, 35, 60, 54, 2, 54, 35, 60, 2, 29, 18, 62, 2, 27,
|
||||
7, 63, 3, 25, 36, 0, 3, 54, 33, 1, 3, 31, 39, 2, 3, 63, 11, 5, 3, 42, 10,
|
||||
7, 3, 7, 42, 10, 3, 5, 63, 11, 3, 43, 56, 16, 3, 50, 47, 20, 3, 36, 0, 25,
|
||||
3, 39, 2, 31, 3, 1, 54, 33, 3, 0, 25, 36, 3, 57, 48, 38, 3, 2, 31, 39, 3,
|
||||
10, 7, 42, 3, 56, 16, 43, 3, 20, 50, 47, 3, 38, 57, 48, 3, 47, 20, 50, 3,
|
||||
33, 1, 54, 3, 16, 43, 56, 3, 48, 38, 57, 3, 11, 5, 63, 4, 58, 29, 1, 4, 45,
|
||||
11, 4, 4, 17, 37, 6, 4, 47, 41, 8, 4, 12, 33, 9, 4, 26, 51, 10, 4, 4, 45,
|
||||
11, 4, 33, 9, 12, 4, 37, 6, 17, 4, 46, 31, 21, 4, 60, 28, 23, 4, 51, 10,
|
||||
26, 4, 23, 60, 28, 4, 1, 58, 29, 4, 21, 46, 31, 4, 9, 12, 33, 4, 6, 17, 37,
|
||||
4, 8, 47, 41, 4, 11, 4, 45, 4, 31, 21, 46, 4, 41, 8, 47, 4, 10, 26, 51, 4,
|
||||
29, 1, 58, 4, 28, 23, 60, 5, 5, 59, 2, 5, 50, 30, 4, 5, 59, 2, 5, 5, 28,
|
||||
26, 11, 5, 32, 23, 13, 5, 42, 40, 14, 5, 61, 24, 19, 5, 13, 32, 23, 5, 19,
|
||||
61, 24, 5, 11, 28, 26, 5, 57, 45, 27, 5, 26, 11, 28, 5, 4, 50, 30, 5, 23,
|
||||
13, 32, 5, 36, 43, 34, 5, 43, 34, 36, 5, 14, 42, 40, 5, 40, 14, 42, 5, 34,
|
||||
36, 43, 5, 27, 57, 45, 5, 30, 4, 50, 5, 45, 27, 57, 5, 2, 5, 59, 5, 24, 19,
|
||||
61, 6, 53, 13, 3, 6, 27, 51, 4, 6, 57, 35, 6, 6, 37, 26, 12, 6, 3, 53, 13,
|
||||
6, 24, 45, 18, 6, 48, 61, 20, 6, 58, 34, 22, 6, 45, 18, 24, 6, 12, 37, 26,
|
||||
6, 51, 4, 27, 6, 22, 58, 34, 6, 6, 57, 35, 6, 26, 12, 37, 6, 49, 59, 44, 6,
|
||||
18, 24, 45, 6, 61, 20, 48, 6, 59, 44, 49, 6, 4, 27, 51, 6, 13, 3, 53, 6,
|
||||
35, 6, 57, 6, 34, 22, 58, 6, 44, 49, 59, 6, 20, 48, 61, 7, 9, 42, 0, 7, 18,
|
||||
44, 3, 7, 49, 13, 6, 7, 62, 12, 8, 7, 42, 0, 9, 7, 8, 62, 12, 7, 6, 49, 13,
|
||||
7, 55, 23, 14, 7, 37, 19, 16, 7, 44, 3, 18, 7, 16, 37, 19, 7, 35, 52, 22,
|
||||
7, 14, 55, 23, 7, 52, 22, 35, 7, 19, 16, 37, 7, 0, 9, 42, 7, 56, 53, 43, 7,
|
||||
3, 18, 44, 7, 13, 6, 49, 7, 22, 35, 52, 7, 43, 56, 53, 7, 23, 14, 55, 7,
|
||||
53, 43, 56, 7, 12, 8, 62, 8, 14, 59, 0, 8, 15, 17, 3, 8, 32, 20, 9, 8, 59,
|
||||
0, 14, 8, 17, 3, 15, 8, 3, 15, 17, 8, 28, 44, 19, 8, 9, 32, 20, 8, 49, 31,
|
||||
21, 8, 52, 30, 22, 8, 44, 19, 28, 8, 22, 52, 30, 8, 21, 49, 31, 8, 20, 9,
|
||||
32, 8, 19, 28, 44, 8, 58, 51, 46, 8, 31, 21, 49, 8, 46, 58, 51, 8, 30, 22,
|
||||
52, 8, 61, 60, 55, 8, 51, 46, 58, 8, 0, 14, 59, 8, 55, 61, 60, 8, 60, 55,
|
||||
61]));
|
||||
|
179
block-party/table/412.mzn
Normal file
179
block-party/table/412.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 29, 9, 38, 49, 7, 32, 34, 52, 25, 2, 43, 42, 4, 17, 31, 56, 58, 62, 21, 28, 37, 50, 60, 51 |
|
||||
47, 10, 39, 28, 31, 17, 61, 23, 29, 13, 1, 50, 49, 9, 37, 2, 16, 20, 26, 33, 4, 34, 46, 44 |
|
||||
5, 57, 4, 56, 47, 7, 36, 42, 18, 61, 26, 30, 0, 55, 16, 53, 33, 54, 45, 60, 12, 25, 31, 50 |
|
||||
15, 14, 59, 39, 54, 27, 35, 52, 49, 10, 5, 48, 20, 6, 19, 16, 24, 61, 37, 3, 44, 36, 11, 17 |
|
||||
62, 0, 2, 18, 45, 33, 41, 52, 48, 5, 40, 21, 14, 46, 27, 26, 56, 59, 28, 12, 55, 11, 53, 42 |
|
||||
43, 12, 58, 9, 18, 57, 60, 46, 45, 32, 39, 53, 6, 1, 11, 41, 29, 54, 14, 62, 63, 8, 47, 22 |
|
||||
55, 24, 34, 51, 22, 32, 23, 20, 63, 1, 35, 0, 7, 40, 36, 59, 3, 8, 19, 38, 15, 10, 30, 13 |
|
||||
30, 3, 22, 51, 23, 15, 27, 41, 19, 13, 44, 63, 35, 8, 58, 6, 25, 21, 38, 40, 48, 57, 24, 43 |]
|
||||
;
|
||||
% cubes: [8, 5, 2, 6, 1, 3, 4, 7]
|
||||
% symbols: [44, 45, 46, 47, 51, 0, 17, 34, 24, 27, 1, 29, 62, 18, 39, 20, 25, 5, 16, 39, 49, 45, 61, 10]
|
||||
% rotations: [22, 10, 2, 2, 3, 15, 3, 8]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 31, 7, 2, 1, 25, 21, 4, 1,
|
||||
2, 31, 7, 1, 17, 28, 9, 1, 28, 9, 17, 1, 4, 25, 21, 1, 21, 4, 25, 1, 9, 17,
|
||||
28, 1, 32, 56, 29, 1, 7, 2, 31, 1, 56, 29, 32, 1, 37, 42, 34, 1, 42, 34,
|
||||
37, 1, 50, 52, 38, 1, 34, 37, 42, 1, 60, 58, 43, 1, 62, 51, 49, 1, 52, 38,
|
||||
50, 1, 49, 62, 51, 1, 38, 50, 52, 1, 29, 32, 56, 1, 43, 60, 58, 1, 58, 43,
|
||||
60, 1, 51, 49, 62, 2, 46, 16, 1, 2, 47, 17, 2, 2, 50, 61, 4, 2, 33, 10, 9,
|
||||
2, 9, 33, 10, 2, 37, 31, 13, 2, 1, 46, 16, 2, 2, 47, 17, 2, 44, 28, 20, 2,
|
||||
39, 34, 23, 2, 49, 29, 26, 2, 20, 44, 28, 2, 26, 49, 29, 2, 13, 37, 31, 2,
|
||||
10, 9, 33, 2, 23, 39, 34, 2, 31, 13, 37, 2, 34, 23, 39, 2, 28, 20, 44, 2,
|
||||
16, 1, 46, 2, 17, 2, 47, 2, 29, 26, 49, 2, 61, 4, 50, 2, 4, 50, 61, 3, 18,
|
||||
45, 0, 3, 25, 42, 4, 3, 7, 53, 5, 3, 53, 5, 7, 3, 30, 36, 12, 3, 47, 61,
|
||||
16, 3, 45, 0, 18, 3, 42, 4, 25, 3, 31, 33, 26, 3, 36, 12, 30, 3, 33, 26,
|
||||
31, 3, 26, 31, 33, 3, 12, 30, 36, 3, 4, 25, 42, 3, 0, 18, 45, 3, 61, 16,
|
||||
47, 3, 56, 54, 50, 3, 5, 7, 53, 3, 50, 56, 54, 3, 60, 57, 55, 3, 54, 50,
|
||||
56, 3, 55, 60, 57, 3, 57, 55, 60, 3, 16, 47, 61, 4, 14, 6, 3, 4, 11, 24, 5,
|
||||
4, 3, 14, 6, 4, 19, 54, 10, 4, 24, 5, 11, 4, 6, 3, 14, 4, 27, 16, 15, 4,
|
||||
15, 27, 16, 4, 39, 61, 17, 4, 54, 10, 19, 4, 49, 37, 20, 4, 5, 11, 24, 4,
|
||||
16, 15, 27, 4, 44, 48, 35, 4, 52, 59, 36, 4, 20, 49, 37, 4, 61, 17, 39, 4,
|
||||
48, 35, 44, 4, 35, 44, 48, 4, 37, 20, 49, 4, 59, 36, 52, 4, 10, 19, 54, 4,
|
||||
36, 52, 59, 4, 17, 39, 61, 5, 46, 12, 0, 5, 11, 52, 2, 5, 27, 45, 5, 5, 52,
|
||||
2, 11, 5, 0, 46, 12, 5, 48, 28, 14, 5, 59, 42, 18, 5, 41, 55, 21, 5, 62,
|
||||
33, 26, 5, 45, 5, 27, 5, 14, 48, 28, 5, 26, 62, 33, 5, 53, 56, 40, 5, 55,
|
||||
21, 41, 5, 18, 59, 42, 5, 5, 27, 45, 5, 12, 0, 46, 5, 28, 14, 48, 5, 2, 11,
|
||||
52, 5, 56, 40, 53, 5, 21, 41, 55, 5, 40, 53, 56, 5, 42, 18, 59, 5, 33, 26,
|
||||
62, 6, 62, 12, 1, 6, 45, 14, 6, 6, 46, 58, 8, 6, 54, 22, 9, 6, 18, 32, 11,
|
||||
6, 1, 62, 12, 6, 6, 45, 14, 6, 32, 11, 18, 6, 9, 54, 22, 6, 39, 47, 29, 6,
|
||||
11, 18, 32, 6, 47, 29, 39, 6, 43, 57, 41, 6, 57, 41, 43, 6, 14, 6, 45, 6,
|
||||
58, 8, 46, 6, 29, 39, 47, 6, 60, 63, 53, 6, 22, 9, 54, 6, 41, 43, 57, 6, 8,
|
||||
46, 58, 6, 63, 53, 60, 6, 12, 1, 62, 6, 53, 60, 63, 7, 23, 15, 0, 7, 36,
|
||||
22, 1, 7, 35, 30, 3, 7, 63, 19, 7, 7, 13, 51, 8, 7, 20, 34, 10, 7, 51, 8,
|
||||
13, 7, 0, 23, 15, 7, 7, 63, 19, 7, 34, 10, 20, 7, 1, 36, 22, 7, 15, 0, 23,
|
||||
7, 40, 38, 24, 7, 3, 35, 30, 7, 59, 55, 32, 7, 10, 20, 34, 7, 30, 3, 35, 7,
|
||||
22, 1, 36, 7, 24, 40, 38, 7, 38, 24, 40, 7, 8, 13, 51, 7, 32, 59, 55, 7,
|
||||
55, 32, 59, 7, 19, 7, 63, 8, 8, 40, 3, 8, 30, 15, 6, 8, 40, 3, 8, 8, 58,
|
||||
23, 13, 8, 6, 30, 15, 8, 38, 35, 19, 8, 43, 51, 21, 8, 57, 41, 22, 8, 13,
|
||||
58, 23, 8, 25, 44, 24, 8, 44, 24, 25, 8, 48, 63, 27, 8, 15, 6, 30, 8, 19,
|
||||
38, 35, 8, 35, 19, 38, 8, 3, 8, 40, 8, 22, 57, 41, 8, 51, 21, 43, 8, 24,
|
||||
25, 44, 8, 63, 27, 48, 8, 21, 43, 51, 8, 41, 22, 57, 8, 23, 13, 58, 8, 27,
|
||||
48, 63]));
|
||||
|
179
block-party/table/4629.mzn
Normal file
179
block-party/table/4629.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 15, 39, 57, 20, 61, 36, 41, 22, 47, 43, 29, 6, 14, 17, 18, 40, 54, 34, 42, 3, 24, 13, 10, 30 |
|
||||
15, 45, 20, 19, 47, 57, 7, 46, 59, 14, 56, 17, 11, 34, 37, 62, 55, 54, 61, 16, 9, 31, 51, 2 |
|
||||
45, 17, 18, 26, 29, 11, 57, 46, 23, 22, 49, 24, 20, 53, 35, 28, 19, 38, 4, 3, 0, 52, 8, 9 |
|
||||
52, 51, 14, 2, 3, 45, 44, 16, 43, 39, 37, 21, 58, 0, 28, 36, 38, 7, 33, 1, 32, 63, 61, 6 |
|
||||
60, 36, 24, 15, 48, 23, 47, 9, 0, 10, 32, 28, 41, 46, 2, 33, 35, 25, 12, 55, 4, 44, 40, 29 |
|
||||
7, 63, 34, 16, 25, 44, 21, 39, 6, 5, 33, 30, 22, 26, 55, 41, 32, 31, 11, 18, 48, 42, 50, 27 |
|
||||
38, 63, 52, 31, 56, 49, 10, 59, 48, 19, 37, 1, 62, 8, 58, 43, 25, 5, 60, 12, 27, 50, 53, 13 |
|
||||
35, 4, 60, 13, 49, 8, 59, 21, 56, 62, 30, 1, 5, 23, 54, 40, 58, 50, 42, 53, 27, 26, 51, 12 |]
|
||||
;
|
||||
% cubes: [1, 2, 8, 3, 6, 7, 5, 4]
|
||||
% symbols: [41, 19, 62, 4, 11, 49, 28, 38, 24, 2, 49, 20, 6, 43, 47, 61, 6, 54, 54, 23, 22, 38, 4, 37]
|
||||
% rotations: [9, 7, 24, 19, 19, 11, 21, 20]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 39, 17, 3, 1, 41, 24, 6,
|
||||
1, 54, 29, 10, 1, 22, 57, 13, 1, 47, 42, 14, 1, 36, 40, 15, 1, 3, 39, 17,
|
||||
1, 61, 43, 18, 1, 34, 30, 20, 1, 57, 13, 22, 1, 6, 41, 24, 1, 10, 54, 29,
|
||||
1, 20, 34, 30, 1, 30, 20, 34, 1, 40, 15, 36, 1, 17, 3, 39, 1, 15, 36, 40,
|
||||
1, 24, 6, 41, 1, 14, 47, 42, 1, 18, 61, 43, 1, 42, 14, 47, 1, 29, 10, 54,
|
||||
1, 13, 22, 57, 1, 43, 18, 61, 2, 19, 54, 2, 2, 9, 17, 7, 2, 17, 7, 9, 2,
|
||||
59, 61, 11, 2, 37, 47, 14, 2, 57, 62, 15, 2, 45, 34, 16, 2, 7, 9, 17, 2,
|
||||
54, 2, 19, 2, 31, 46, 20, 2, 46, 20, 31, 2, 16, 45, 34, 2, 47, 14, 37, 2,
|
||||
34, 16, 45, 2, 20, 31, 46, 2, 14, 37, 47, 2, 55, 56, 51, 2, 2, 19, 54, 2,
|
||||
56, 51, 55, 2, 51, 55, 56, 2, 62, 15, 57, 2, 61, 11, 59, 2, 11, 59, 61, 2,
|
||||
15, 57, 62, 3, 24, 57, 0, 3, 17, 53, 3, 3, 20, 23, 4, 3, 19, 49, 8, 3, 26,
|
||||
38, 9, 3, 28, 45, 11, 3, 53, 3, 17, 3, 52, 46, 18, 3, 49, 8, 19, 3, 23, 4,
|
||||
20, 3, 35, 29, 22, 3, 4, 20, 23, 3, 57, 0, 24, 3, 38, 9, 26, 3, 45, 11, 28,
|
||||
3, 22, 35, 29, 3, 29, 22, 35, 3, 9, 26, 38, 3, 11, 28, 45, 3, 18, 52, 46,
|
||||
3, 8, 19, 49, 3, 46, 18, 52, 3, 3, 17, 53, 3, 0, 24, 57, 4, 1, 51, 0, 4,
|
||||
51, 0, 1, 4, 7, 6, 2, 4, 39, 28, 3, 4, 2, 7, 6, 4, 6, 2, 7, 4, 63, 16, 14,
|
||||
4, 14, 63, 16, 4, 44, 32, 21, 4, 3, 39, 28, 4, 21, 44, 32, 4, 58, 43, 33,
|
||||
4, 52, 45, 36, 4, 61, 38, 37, 4, 37, 61, 38, 4, 28, 3, 39, 4, 33, 58, 43,
|
||||
4, 32, 21, 44, 4, 36, 52, 45, 4, 0, 1, 51, 4, 45, 36, 52, 4, 43, 33, 58, 4,
|
||||
38, 37, 61, 4, 16, 14, 63, 5, 12, 41, 0, 5, 48, 10, 2, 5, 28, 47, 4, 5, 24,
|
||||
44, 9, 5, 2, 48, 10, 5, 41, 0, 12, 5, 25, 29, 15, 5, 33, 60, 23, 5, 44, 9,
|
||||
24, 5, 29, 15, 25, 5, 47, 4, 28, 5, 15, 25, 29, 5, 40, 35, 32, 5, 60, 23,
|
||||
33, 5, 32, 40, 35, 5, 46, 55, 36, 5, 35, 32, 40, 5, 0, 12, 41, 5, 9, 24,
|
||||
44, 5, 55, 36, 46, 5, 4, 28, 47, 5, 10, 2, 48, 5, 36, 46, 55, 5, 23, 33,
|
||||
60, 6, 55, 25, 5, 6, 11, 22, 6, 6, 44, 41, 7, 6, 22, 6, 11, 6, 31, 27, 16,
|
||||
6, 63, 26, 18, 6, 48, 30, 21, 6, 6, 11, 22, 6, 5, 55, 25, 6, 18, 63, 26, 6,
|
||||
16, 31, 27, 6, 21, 48, 30, 6, 27, 16, 31, 6, 33, 50, 32, 6, 50, 32, 33, 6,
|
||||
42, 39, 34, 6, 34, 42, 39, 6, 7, 44, 41, 6, 39, 34, 42, 6, 41, 7, 44, 6,
|
||||
30, 21, 48, 6, 32, 33, 50, 6, 25, 5, 55, 6, 26, 18, 63, 7, 10, 27, 1, 7,
|
||||
13, 31, 5, 7, 12, 63, 8, 7, 27, 1, 10, 7, 63, 8, 12, 7, 31, 5, 13, 7, 58,
|
||||
56, 19, 7, 37, 53, 25, 7, 1, 10, 27, 7, 5, 13, 31, 7, 53, 25, 37, 7, 49,
|
||||
43, 38, 7, 38, 49, 43, 7, 60, 62, 48, 7, 43, 38, 49, 7, 59, 52, 50, 7, 50,
|
||||
59, 52, 7, 25, 37, 53, 7, 19, 58, 56, 7, 56, 19, 58, 7, 52, 50, 59, 7, 62,
|
||||
48, 60, 7, 48, 60, 62, 7, 8, 12, 63, 8, 59, 27, 1, 8, 23, 53, 4, 8, 56, 42,
|
||||
5, 8, 40, 35, 8, 8, 13, 50, 12, 8, 50, 12, 13, 8, 60, 26, 21, 8, 53, 4, 23,
|
||||
8, 21, 60, 26, 8, 1, 59, 27, 8, 51, 58, 30, 8, 8, 40, 35, 8, 35, 8, 40, 8,
|
||||
5, 56, 42, 8, 62, 54, 49, 8, 12, 13, 50, 8, 58, 30, 51, 8, 4, 23, 53, 8,
|
||||
49, 62, 54, 8, 42, 5, 56, 8, 30, 51, 58, 8, 27, 1, 59, 8, 26, 21, 60, 8,
|
||||
54, 49, 62]));
|
||||
|
178
block-party/table/7059.mzn
Normal file
178
block-party/table/7059.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 56, 42, 49, 5, 34, 14, 40, 45, 62, 18, 12, 51, 50, 39, 26, 25, 28, 10, 11, 63, 32, 61, 19, 58 |
|
||||
17, 51, 3, 7, 25, 46, 29, 41, 57, 48, 53, 20, 56, 15, 22, 12, 60, 38, 33, 34, 27, 14, 55, 40 |
|
||||
61, 18, 23, 44, 32, 6, 52, 51, 29, 2, 22, 56, 0, 14, 19, 46, 9, 60, 40, 17, 3, 48, 50, 37 |
|
||||
47, 49, 28, 63, 27, 21, 1, 25, 45, 55, 3, 42, 54, 61, 53, 34, 48, 43, 6, 39, 29, 52, 4, 33 |
|
||||
50, 13, 38, 7, 15, 36, 21, 10, 42, 12, 23, 16, 55, 27, 45, 60, 35, 53, 44, 26, 46, 22, 0, 52 |
|
||||
36, 1, 15, 58, 37, 35, 7, 0, 21, 4, 33, 8, 19, 44, 62, 16, 17, 32, 26, 59, 30, 31, 24, 39 |
|
||||
47, 31, 38, 35, 43, 8, 62, 16, 36, 1, 41, 23, 59, 57, 49, 30, 2, 5, 24, 11, 13, 20, 9, 54 |
|
||||
57, 18, 20, 5, 28, 4, 13, 63, 30, 43, 2, 24, 8, 10, 59, 37, 41, 11, 9, 6, 47, 58, 31, 54 |]
|
||||
;
|
||||
% cubes: [6, 7, 8, 1, 4, 5, 3, 2]
|
||||
% symbols: [39, 49, 10, 28, 54, 22, 6, 38, 58, 1, 18, 12, 6, 10, 46, 7, 32, 43, 6, 19, 45, 38, 61, 40]
|
||||
% rotations: [3, 14, 16, 20, 15, 4, 11, 17]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 10, 58, 5, 1, 58, 5, 10,
|
||||
1, 50, 62, 11, 1, 19, 28, 12, 1, 25, 56, 14, 1, 26, 34, 18, 1, 28, 12, 19,
|
||||
1, 56, 14, 25, 1, 34, 18, 26, 1, 12, 19, 28, 1, 51, 40, 32, 1, 18, 26, 34,
|
||||
1, 63, 42, 39, 1, 32, 51, 40, 1, 39, 63, 42, 1, 49, 61, 45, 1, 61, 45, 49,
|
||||
1, 62, 11, 50, 1, 40, 32, 51, 1, 14, 25, 56, 1, 5, 10, 58, 1, 45, 49, 61,
|
||||
1, 11, 50, 62, 1, 42, 39, 63, 2, 14, 41, 3, 2, 38, 40, 7, 2, 17, 46, 12, 2,
|
||||
41, 3, 14, 2, 34, 51, 15, 2, 46, 12, 17, 2, 29, 27, 20, 2, 25, 48, 22, 2,
|
||||
48, 22, 25, 2, 20, 29, 27, 2, 27, 20, 29, 2, 56, 57, 33, 2, 51, 15, 34, 2,
|
||||
40, 7, 38, 2, 7, 38, 40, 2, 3, 14, 41, 2, 12, 17, 46, 2, 22, 25, 48, 2, 15,
|
||||
34, 51, 2, 55, 60, 53, 2, 60, 53, 55, 2, 57, 33, 56, 2, 33, 56, 57, 2, 53,
|
||||
55, 60, 3, 29, 40, 0, 3, 19, 32, 2, 3, 56, 52, 3, 3, 46, 61, 6, 3, 22, 50,
|
||||
9, 3, 17, 18, 14, 3, 18, 14, 17, 3, 14, 17, 18, 3, 32, 2, 19, 3, 50, 9, 22,
|
||||
3, 48, 51, 23, 3, 40, 0, 29, 3, 2, 19, 32, 3, 44, 60, 37, 3, 0, 29, 40, 3,
|
||||
60, 37, 44, 3, 61, 6, 46, 3, 51, 23, 48, 3, 9, 22, 50, 3, 23, 48, 51, 3, 3,
|
||||
56, 52, 3, 52, 3, 56, 3, 37, 44, 60, 3, 6, 46, 61, 4, 29, 42, 1, 4, 4, 48,
|
||||
3, 4, 48, 3, 4, 4, 54, 45, 6, 4, 34, 47, 21, 4, 28, 52, 25, 4, 55, 53, 27,
|
||||
4, 52, 25, 28, 4, 42, 1, 29, 4, 63, 43, 33, 4, 47, 21, 34, 4, 49, 61, 39,
|
||||
4, 1, 29, 42, 4, 33, 63, 43, 4, 6, 54, 45, 4, 21, 34, 47, 4, 3, 4, 48, 4,
|
||||
61, 39, 49, 4, 25, 28, 52, 4, 27, 55, 53, 4, 45, 6, 54, 4, 53, 27, 55, 4,
|
||||
39, 49, 61, 4, 43, 33, 63, 5, 35, 23, 0, 5, 53, 52, 7, 5, 38, 22, 10, 5,
|
||||
45, 15, 12, 5, 27, 26, 13, 5, 12, 45, 15, 5, 21, 46, 16, 5, 46, 16, 21, 5,
|
||||
10, 38, 22, 5, 0, 35, 23, 5, 13, 27, 26, 5, 26, 13, 27, 5, 23, 0, 35, 5,
|
||||
60, 50, 36, 5, 22, 10, 38, 5, 44, 55, 42, 5, 55, 42, 44, 5, 15, 12, 45, 5,
|
||||
16, 21, 46, 5, 36, 60, 50, 5, 7, 53, 52, 5, 52, 7, 53, 5, 42, 44, 55, 5,
|
||||
50, 36, 60, 6, 15, 31, 0, 6, 44, 59, 1, 6, 62, 37, 4, 6, 30, 8, 7, 6, 7,
|
||||
30, 8, 6, 31, 0, 15, 6, 36, 35, 16, 6, 33, 24, 17, 6, 21, 26, 19, 6, 26,
|
||||
19, 21, 6, 17, 33, 24, 6, 19, 21, 26, 6, 8, 7, 30, 6, 0, 15, 31, 6, 39, 58,
|
||||
32, 6, 24, 17, 33, 6, 16, 36, 35, 6, 35, 16, 36, 6, 4, 62, 37, 6, 58, 32,
|
||||
39, 6, 59, 1, 44, 6, 32, 39, 58, 6, 1, 44, 59, 6, 37, 4, 62, 7, 49, 43, 1,
|
||||
7, 41, 9, 2, 7, 54, 35, 5, 7, 30, 47, 8, 7, 2, 41, 9, 7, 31, 57, 11, 7, 23,
|
||||
62, 13, 7, 38, 20, 16, 7, 16, 38, 20, 7, 62, 13, 23, 7, 59, 36, 24, 7, 47,
|
||||
8, 30, 7, 57, 11, 31, 7, 5, 54, 35, 7, 24, 59, 36, 7, 20, 16, 38, 7, 9, 2,
|
||||
41, 7, 1, 49, 43, 7, 8, 30, 47, 7, 43, 1, 49, 7, 35, 5, 54, 7, 11, 31, 57,
|
||||
7, 36, 24, 59, 7, 13, 23, 62, 8, 31, 41, 2, 8, 37, 57, 4, 8, 11, 54, 5, 8,
|
||||
18, 10, 6, 8, 30, 9, 8, 8, 8, 30, 9, 8, 6, 18, 10, 8, 54, 5, 11, 8, 47, 24,
|
||||
13, 8, 10, 6, 18, 8, 58, 63, 20, 8, 13, 47, 24, 8, 43, 59, 28, 8, 9, 8, 30,
|
||||
8, 41, 2, 31, 8, 57, 4, 37, 8, 2, 31, 41, 8, 59, 28, 43, 8, 24, 13, 47, 8,
|
||||
5, 11, 54, 8, 4, 37, 57, 8, 63, 20, 58, 8, 28, 43, 59, 8, 20, 58, 63]));
|
||||
|
178
block-party/table/7324.mzn
Normal file
178
block-party/table/7324.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 30, 7, 63, 61, 57, 62, 12, 5, 55, 16, 49, 42, 54, 18, 13, 29, 41, 15, 6, 3, 25, 22, 0, 11 |
|
||||
29, 59, 53, 45, 57, 43, 8, 36, 22, 3, 35, 50, 41, 9, 27, 37, 10, 61, 26, 60, 42, 16, 48, 39 |
|
||||
6, 46, 22, 24, 14, 0, 29, 39, 33, 10, 32, 35, 53, 30, 9, 58, 8, 7, 62, 5, 28, 11, 20, 1 |
|
||||
27, 60, 2, 56, 32, 47, 63, 26, 18, 23, 21, 5, 49, 43, 44, 3, 39, 13, 11, 40, 19, 51, 48, 20 |
|
||||
60, 61, 37, 19, 47, 27, 24, 28, 0, 25, 43, 36, 53, 45, 33, 31, 10, 63, 35, 12, 51, 58, 23, 52 |
|
||||
48, 15, 33, 4, 8, 57, 56, 6, 49, 7, 28, 38, 47, 14, 30, 51, 12, 41, 34, 59, 20, 37, 50, 17 |
|
||||
59, 32, 62, 31, 42, 16, 58, 4, 54, 40, 36, 17, 45, 19, 44, 14, 1, 2, 38, 34, 46, 55, 21, 52 |
|
||||
40, 54, 21, 13, 17, 1, 23, 44, 2, 46, 38, 24, 50, 26, 31, 18, 15, 4, 25, 56, 55, 34, 52, 9 |]
|
||||
;
|
||||
% cubes: [1, 5, 3, 8, 4, 7, 2, 6]
|
||||
% symbols: [29, 35, 58, 4, 21, 16, 27, 30, 30, 0, 0, 9, 39, 14, 57, 7, 62, 53, 6, 13, 48, 59, 3, 8]
|
||||
% rotations: [13, 19, 13, 17, 22, 11, 14, 14]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 41, 49, 0, 1, 7, 18, 3, 1,
|
||||
63, 22, 5, 1, 54, 55, 6, 1, 18, 3, 7, 1, 61, 15, 11, 1, 25, 42, 12, 1, 57,
|
||||
16, 13, 1, 11, 61, 15, 1, 13, 57, 16, 1, 3, 7, 18, 1, 5, 63, 22, 1, 42, 12,
|
||||
25, 1, 30, 62, 29, 1, 62, 29, 30, 1, 49, 0, 41, 1, 12, 25, 42, 1, 0, 41,
|
||||
49, 1, 55, 6, 54, 1, 6, 54, 55, 1, 16, 13, 57, 1, 15, 11, 61, 1, 29, 30,
|
||||
62, 1, 22, 5, 63, 2, 27, 57, 3, 2, 42, 50, 8, 2, 60, 59, 9, 2, 35, 48, 10,
|
||||
2, 36, 53, 16, 2, 26, 41, 22, 2, 41, 22, 26, 2, 57, 3, 27, 2, 43, 37, 29,
|
||||
2, 48, 10, 35, 2, 53, 16, 36, 2, 29, 43, 37, 2, 45, 61, 39, 2, 22, 26, 41,
|
||||
2, 50, 8, 42, 2, 37, 29, 43, 2, 61, 39, 45, 2, 10, 35, 48, 2, 8, 42, 50, 2,
|
||||
16, 36, 53, 2, 3, 27, 57, 2, 9, 60, 59, 2, 59, 9, 60, 2, 39, 45, 61, 3, 58,
|
||||
6, 0, 3, 24, 7, 1, 3, 46, 30, 5, 3, 0, 58, 6, 3, 1, 24, 7, 3, 32, 20, 8, 3,
|
||||
14, 10, 9, 3, 9, 14, 10, 3, 39, 22, 11, 3, 10, 9, 14, 3, 8, 32, 20, 3, 11,
|
||||
39, 22, 3, 7, 1, 24, 3, 35, 29, 28, 3, 28, 35, 29, 3, 5, 46, 30, 3, 20, 8,
|
||||
32, 3, 62, 53, 33, 3, 29, 28, 35, 3, 22, 11, 39, 3, 30, 5, 46, 3, 33, 62,
|
||||
53, 3, 6, 0, 58, 3, 53, 33, 62, 4, 51, 26, 2, 4, 27, 47, 3, 4, 63, 19, 5,
|
||||
4, 49, 18, 11, 4, 20, 56, 13, 4, 11, 49, 18, 4, 5, 63, 19, 4, 56, 13, 20,
|
||||
4, 48, 39, 21, 4, 44, 32, 23, 4, 2, 51, 26, 4, 47, 3, 27, 4, 23, 44, 32, 4,
|
||||
21, 48, 39, 4, 60, 43, 40, 4, 40, 60, 43, 4, 32, 23, 44, 4, 3, 27, 47, 4,
|
||||
39, 21, 48, 4, 18, 11, 49, 4, 26, 2, 51, 4, 13, 20, 56, 4, 43, 40, 60, 4,
|
||||
19, 5, 63, 5, 35, 53, 0, 5, 43, 23, 10, 5, 61, 45, 12, 5, 63, 52, 19, 5,
|
||||
10, 43, 23, 5, 51, 36, 24, 5, 33, 47, 25, 5, 31, 60, 27, 5, 37, 58, 28, 5,
|
||||
60, 27, 31, 5, 47, 25, 33, 5, 53, 0, 35, 5, 24, 51, 36, 5, 58, 28, 37, 5,
|
||||
23, 10, 43, 5, 12, 61, 45, 5, 25, 33, 47, 5, 36, 24, 51, 5, 19, 63, 52, 5,
|
||||
0, 35, 53, 5, 28, 37, 58, 5, 27, 31, 60, 5, 45, 12, 61, 5, 52, 19, 63, 6,
|
||||
41, 17, 4, 6, 33, 37, 6, 6, 30, 8, 7, 6, 7, 30, 8, 6, 28, 50, 12, 6, 59,
|
||||
15, 14, 6, 14, 59, 15, 6, 4, 41, 17, 6, 38, 56, 20, 6, 50, 12, 28, 6, 8, 7,
|
||||
30, 6, 37, 6, 33, 6, 47, 49, 34, 6, 6, 33, 37, 6, 56, 20, 38, 6, 17, 4, 41,
|
||||
6, 49, 34, 47, 6, 57, 51, 48, 6, 34, 47, 49, 6, 12, 28, 50, 6, 48, 57, 51,
|
||||
6, 20, 38, 56, 6, 51, 48, 57, 6, 15, 14, 59, 7, 36, 21, 1, 7, 52, 31, 2, 7,
|
||||
62, 55, 4, 7, 59, 16, 14, 7, 14, 59, 16, 7, 58, 46, 17, 7, 34, 32, 19, 7,
|
||||
1, 36, 21, 7, 2, 52, 31, 7, 19, 34, 32, 7, 32, 19, 34, 7, 21, 1, 36, 7, 45,
|
||||
54, 38, 7, 44, 42, 40, 7, 40, 44, 42, 7, 42, 40, 44, 7, 54, 38, 45, 7, 17,
|
||||
58, 46, 7, 31, 2, 52, 7, 38, 45, 54, 7, 4, 62, 55, 7, 46, 17, 58, 7, 16,
|
||||
14, 59, 7, 55, 4, 62, 8, 18, 40, 1, 8, 25, 50, 2, 8, 9, 13, 4, 8, 13, 4, 9,
|
||||
8, 4, 9, 13, 8, 38, 52, 15, 8, 46, 31, 17, 8, 40, 1, 18, 8, 34, 44, 21, 8,
|
||||
55, 24, 23, 8, 23, 55, 24, 8, 50, 2, 25, 8, 56, 54, 26, 8, 17, 46, 31, 8,
|
||||
44, 21, 34, 8, 52, 15, 38, 8, 1, 18, 40, 8, 21, 34, 44, 8, 31, 17, 46, 8,
|
||||
2, 25, 50, 8, 15, 38, 52, 8, 26, 56, 54, 8, 24, 23, 55, 8, 54, 26, 56]));
|
||||
|
179
block-party/table/7326.mzn
Normal file
179
block-party/table/7326.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 16, 63, 9, 37, 29, 30, 31, 55, 25, 23, 60, 53, 26, 46, 13, 50, 15, 47, 28, 6, 49, 11, 48, 38 |
|
||||
44, 47, 27, 12, 41, 40, 50, 54, 43, 37, 2, 9, 51, 20, 26, 11, 17, 63, 23, 45, 34, 31, 62, 29 |
|
||||
51, 14, 11, 49, 61, 34, 24, 17, 47, 46, 38, 1, 2, 31, 32, 19, 39, 54, 37, 48, 40, 35, 10, 44 |
|
||||
48, 42, 15, 14, 5, 12, 50, 58, 56, 34, 3, 53, 20, 17, 40, 2, 30, 1, 45, 24, 62, 36, 63, 61 |
|
||||
58, 55, 49, 42, 62, 33, 5, 25, 20, 13, 44, 28, 59, 43, 21, 45, 52, 30, 29, 38, 23, 14, 1, 35 |
|
||||
60, 16, 58, 36, 57, 27, 43, 12, 46, 9, 54, 3, 0, 22, 41, 8, 7, 10, 53, 21, 4, 32, 61, 18 |
|
||||
3, 18, 32, 10, 52, 22, 8, 39, 4, 28, 42, 60, 57, 5, 56, 0, 55, 6, 24, 59, 33, 19, 7, 51 |
|
||||
0, 52, 22, 4, 56, 19, 27, 33, 13, 16, 57, 36, 41, 15, 7, 8, 21, 25, 39, 35, 18, 6, 26, 59 |]
|
||||
;
|
||||
% cubes: [1, 2, 4, 8, 3, 7, 5, 6]
|
||||
% symbols: [28, 45, 62, 15, 31, 51, 43, 7, 26, 20, 50, 35, 14, 10, 38, 61, 25, 47, 53, 52, 48, 6, 55, 54]
|
||||
% rotations: [19, 18, 1, 16, 16, 3, 16, 20]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 63, 46, 6, 1, 11, 55, 9,
|
||||
1, 55, 9, 11, 1, 29, 23, 13, 1, 60, 48, 15, 1, 30, 50, 16, 1, 13, 29, 23,
|
||||
1, 28, 26, 25, 1, 25, 28, 26, 1, 26, 25, 28, 1, 23, 13, 29, 1, 50, 16, 30,
|
||||
1, 49, 53, 31, 1, 47, 38, 37, 1, 37, 47, 38, 1, 6, 63, 46, 1, 38, 37, 47,
|
||||
1, 15, 60, 48, 1, 53, 31, 49, 1, 16, 30, 50, 1, 31, 49, 53, 1, 9, 11, 55,
|
||||
1, 48, 15, 60, 1, 46, 6, 63, 2, 62, 17, 2, 2, 50, 34, 9, 2, 44, 40, 11, 2,
|
||||
63, 29, 12, 2, 2, 62, 17, 2, 45, 47, 20, 2, 51, 43, 23, 2, 41, 37, 26, 2,
|
||||
31, 54, 27, 2, 12, 63, 29, 2, 54, 27, 31, 2, 9, 50, 34, 2, 26, 41, 37, 2,
|
||||
11, 44, 40, 2, 37, 26, 41, 2, 23, 51, 43, 2, 40, 11, 44, 2, 47, 20, 45, 2,
|
||||
20, 45, 47, 2, 34, 9, 50, 2, 43, 23, 51, 2, 27, 31, 54, 2, 17, 2, 62, 2,
|
||||
29, 12, 63, 3, 24, 40, 1, 3, 47, 37, 2, 3, 39, 38, 10, 3, 35, 17, 11, 3,
|
||||
31, 48, 14, 3, 11, 35, 17, 3, 51, 34, 19, 3, 40, 1, 24, 3, 48, 14, 31, 3,
|
||||
61, 46, 32, 3, 19, 51, 34, 3, 17, 11, 35, 3, 2, 47, 37, 3, 10, 39, 38, 3,
|
||||
38, 10, 39, 3, 1, 24, 40, 3, 49, 54, 44, 3, 32, 61, 46, 3, 37, 2, 47, 3,
|
||||
14, 31, 48, 3, 54, 44, 49, 3, 34, 19, 51, 3, 44, 49, 54, 3, 46, 32, 61, 4,
|
||||
61, 14, 1, 4, 48, 12, 2, 4, 63, 30, 3, 4, 34, 40, 5, 4, 2, 48, 12, 4, 1,
|
||||
61, 14, 4, 36, 58, 15, 4, 24, 42, 17, 4, 56, 45, 20, 4, 42, 17, 24, 4, 3,
|
||||
63, 30, 4, 40, 5, 34, 4, 58, 15, 36, 4, 5, 34, 40, 4, 17, 24, 42, 4, 20,
|
||||
56, 45, 4, 12, 2, 48, 4, 62, 53, 50, 4, 50, 62, 53, 4, 45, 20, 56, 4, 15,
|
||||
36, 58, 4, 14, 1, 61, 4, 53, 50, 62, 4, 30, 3, 63, 5, 52, 44, 1, 5, 23, 28,
|
||||
5, 5, 21, 62, 13, 5, 25, 49, 14, 5, 29, 59, 20, 5, 62, 13, 21, 5, 28, 5,
|
||||
23, 5, 49, 14, 25, 5, 5, 23, 28, 5, 59, 20, 29, 5, 35, 42, 30, 5, 45, 58,
|
||||
33, 5, 42, 30, 35, 5, 55, 43, 38, 5, 30, 35, 42, 5, 38, 55, 43, 5, 1, 52,
|
||||
44, 5, 58, 33, 45, 5, 14, 25, 49, 5, 44, 1, 52, 5, 43, 38, 55, 5, 33, 45,
|
||||
58, 5, 20, 29, 59, 5, 13, 21, 62, 6, 46, 53, 0, 6, 43, 4, 3, 6, 3, 43, 4,
|
||||
6, 54, 61, 7, 6, 60, 27, 8, 6, 41, 57, 9, 6, 18, 36, 10, 6, 58, 32, 12, 6,
|
||||
22, 21, 16, 6, 36, 10, 18, 6, 16, 22, 21, 6, 21, 16, 22, 6, 8, 60, 27, 6,
|
||||
12, 58, 32, 6, 10, 18, 36, 6, 57, 9, 41, 6, 4, 3, 43, 6, 53, 0, 46, 6, 0,
|
||||
46, 53, 6, 61, 7, 54, 6, 9, 41, 57, 6, 32, 12, 58, 6, 27, 8, 60, 6, 7, 54,
|
||||
61, 7, 3, 22, 0, 7, 22, 0, 3, 7, 24, 57, 4, 7, 59, 18, 5, 7, 51, 10, 6, 7,
|
||||
55, 42, 7, 7, 33, 60, 8, 7, 6, 51, 10, 7, 5, 59, 18, 7, 39, 32, 19, 7, 0,
|
||||
3, 22, 7, 57, 4, 24, 7, 56, 52, 28, 7, 19, 39, 32, 7, 60, 8, 33, 7, 32, 19,
|
||||
39, 7, 7, 55, 42, 7, 10, 6, 51, 7, 28, 56, 52, 7, 42, 7, 55, 7, 52, 28, 56,
|
||||
7, 4, 24, 57, 7, 18, 5, 59, 7, 8, 33, 60, 8, 19, 8, 0, 8, 25, 59, 4, 8, 33,
|
||||
22, 6, 8, 56, 16, 7, 8, 0, 19, 8, 8, 39, 41, 13, 8, 35, 52, 15, 8, 7, 56,
|
||||
16, 8, 36, 27, 18, 8, 8, 0, 19, 8, 57, 26, 21, 8, 6, 33, 22, 8, 59, 4, 25,
|
||||
8, 21, 57, 26, 8, 18, 36, 27, 8, 22, 6, 33, 8, 52, 15, 35, 8, 27, 18, 36,
|
||||
8, 41, 13, 39, 8, 13, 39, 41, 8, 15, 35, 52, 8, 16, 7, 56, 8, 26, 21, 57,
|
||||
8, 4, 25, 59]));
|
||||
|
179
block-party/table/7444.mzn
Normal file
179
block-party/table/7444.mzn
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 6, 36, 47, 53, 3, 41, 1, 13, 34, 18, 60, 23, 63, 5, 37, 52, 50, 57, 19, 22, 46, 17, 24, 11 |
|
||||
27, 34, 36, 30, 55, 58, 52, 32, 5, 57, 60, 33, 41, 42, 35, 8, 40, 9, 37, 2, 50, 39, 24, 28 |
|
||||
24, 6, 2, 28, 47, 37, 12, 44, 58, 36, 43, 32, 38, 61, 48, 49, 57, 40, 3, 23, 42, 50, 62, 1 |
|
||||
7, 59, 0, 45, 60, 22, 10, 25, 15, 38, 42, 54, 14, 51, 43, 2, 12, 4, 23, 48, 41, 21, 30, 6 |
|
||||
1, 63, 21, 18, 8, 48, 29, 56, 15, 35, 12, 43, 58, 19, 10, 33, 49, 14, 9, 4, 53, 39, 13, 47 |
|
||||
18, 53, 38, 46, 27, 34, 20, 16, 56, 32, 51, 55, 22, 19, 40, 28, 54, 62, 7, 9, 59, 5, 26, 31 |
|
||||
54, 21, 20, 45, 33, 7, 35, 49, 56, 16, 17, 10, 0, 8, 14, 63, 25, 26, 44, 31, 29, 61, 11, 13 |
|
||||
44, 20, 30, 27, 4, 11, 59, 25, 16, 39, 51, 15, 45, 3, 52, 46, 26, 31, 55, 61, 17, 62, 0, 29 |]
|
||||
;
|
||||
% cubes: [7, 8, 5, 3, 4, 1, 6, 2]
|
||||
% symbols: [13, 4, 10, 3, 43, 46, 32, 37, 45, 52, 35, 38, 38, 23, 40, 5, 26, 39, 8, 58, 60, 1, 27, 41]
|
||||
% rotations: [3, 10, 14, 19, 14, 1, 24, 19]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 46, 23, 1, 1, 18, 37, 3,
|
||||
1, 22, 36, 5, 1, 41, 52, 6, 1, 53, 57, 11, 1, 47, 17, 13, 1, 13, 47, 17, 1,
|
||||
37, 3, 18, 1, 63, 34, 19, 1, 36, 5, 22, 1, 1, 46, 23, 1, 50, 60, 24, 1, 19,
|
||||
63, 34, 1, 5, 22, 36, 1, 3, 18, 37, 1, 52, 6, 41, 1, 23, 1, 46, 1, 17, 13,
|
||||
47, 1, 60, 24, 50, 1, 6, 41, 52, 1, 57, 11, 53, 1, 11, 53, 57, 1, 24, 50,
|
||||
60, 1, 34, 19, 63, 2, 34, 42, 2, 2, 37, 41, 5, 2, 27, 58, 8, 2, 28, 30, 9,
|
||||
2, 40, 60, 24, 2, 58, 8, 27, 2, 30, 9, 28, 2, 9, 28, 30, 2, 36, 39, 32, 2,
|
||||
52, 50, 33, 2, 42, 2, 34, 2, 55, 57, 35, 2, 39, 32, 36, 2, 41, 5, 37, 2,
|
||||
32, 36, 39, 2, 60, 24, 40, 2, 5, 37, 41, 2, 2, 34, 42, 2, 33, 52, 50, 2,
|
||||
50, 33, 52, 2, 57, 35, 55, 2, 35, 55, 57, 2, 8, 27, 58, 2, 24, 40, 60, 3,
|
||||
28, 40, 1, 3, 50, 44, 2, 3, 38, 58, 3, 3, 61, 23, 6, 3, 42, 32, 12, 3, 6,
|
||||
61, 23, 3, 37, 49, 24, 3, 40, 1, 28, 3, 12, 42, 32, 3, 48, 47, 36, 3, 49,
|
||||
24, 37, 3, 58, 3, 38, 3, 1, 28, 40, 3, 32, 12, 42, 3, 62, 57, 43, 3, 2, 50,
|
||||
44, 3, 36, 48, 47, 3, 47, 36, 48, 3, 24, 37, 49, 3, 44, 2, 50, 3, 43, 62,
|
||||
57, 3, 3, 38, 58, 3, 23, 6, 61, 3, 57, 43, 62, 4, 21, 25, 0, 4, 7, 22, 2,
|
||||
4, 6, 45, 4, 4, 45, 4, 6, 4, 22, 2, 7, 4, 41, 54, 10, 4, 42, 30, 12, 4, 15,
|
||||
23, 14, 4, 23, 14, 15, 4, 25, 0, 21, 4, 2, 7, 22, 4, 14, 15, 23, 4, 0, 21,
|
||||
25, 4, 12, 42, 30, 4, 43, 60, 38, 4, 54, 10, 41, 4, 30, 12, 42, 4, 60, 38,
|
||||
43, 4, 4, 6, 45, 4, 59, 51, 48, 4, 48, 59, 51, 4, 10, 41, 54, 4, 51, 48,
|
||||
59, 4, 38, 43, 60, 5, 48, 33, 1, 5, 63, 19, 4, 5, 35, 10, 8, 5, 58, 15, 9,
|
||||
5, 8, 35, 10, 5, 13, 49, 12, 5, 49, 12, 13, 5, 47, 18, 14, 5, 9, 58, 15, 5,
|
||||
14, 47, 18, 5, 4, 63, 19, 5, 39, 56, 21, 5, 53, 43, 29, 5, 1, 48, 33, 5,
|
||||
10, 8, 35, 5, 56, 21, 39, 5, 29, 53, 43, 5, 18, 14, 47, 5, 33, 1, 48, 5,
|
||||
12, 13, 49, 5, 43, 29, 53, 5, 21, 39, 56, 5, 15, 9, 58, 5, 19, 4, 63, 6,
|
||||
16, 38, 5, 6, 22, 56, 7, 6, 53, 19, 9, 6, 38, 5, 16, 6, 34, 28, 18, 6, 9,
|
||||
53, 19, 6, 59, 55, 20, 6, 56, 7, 22, 6, 54, 51, 26, 6, 32, 40, 27, 6, 18,
|
||||
34, 28, 6, 46, 62, 31, 6, 40, 27, 32, 6, 28, 18, 34, 6, 5, 16, 38, 6, 27,
|
||||
32, 40, 6, 62, 31, 46, 6, 26, 54, 51, 6, 19, 9, 53, 6, 51, 26, 54, 6, 20,
|
||||
59, 55, 6, 7, 22, 56, 6, 55, 20, 59, 6, 31, 46, 62, 7, 56, 44, 0, 7, 63,
|
||||
54, 7, 7, 31, 21, 8, 7, 35, 29, 10, 7, 25, 17, 11, 7, 45, 26, 13, 7, 33,
|
||||
16, 14, 7, 14, 33, 16, 7, 11, 25, 17, 7, 61, 49, 20, 7, 8, 31, 21, 7, 17,
|
||||
11, 25, 7, 13, 45, 26, 7, 10, 35, 29, 7, 21, 8, 31, 7, 16, 14, 33, 7, 29,
|
||||
10, 35, 7, 0, 56, 44, 7, 26, 13, 45, 7, 20, 61, 49, 7, 7, 63, 54, 7, 44, 0,
|
||||
56, 7, 49, 20, 61, 7, 54, 7, 63, 8, 26, 51, 0, 8, 61, 20, 3, 8, 39, 52, 4,
|
||||
8, 46, 44, 11, 8, 59, 17, 15, 8, 55, 45, 16, 8, 15, 59, 17, 8, 3, 61, 20,
|
||||
8, 30, 62, 25, 8, 51, 0, 26, 8, 31, 29, 27, 8, 27, 31, 29, 8, 62, 25, 30,
|
||||
8, 29, 27, 31, 8, 52, 4, 39, 8, 11, 46, 44, 8, 16, 55, 45, 8, 44, 11, 46,
|
||||
8, 0, 26, 51, 8, 4, 39, 52, 8, 45, 16, 55, 8, 17, 15, 59, 8, 20, 3, 61, 8,
|
||||
25, 30, 62]));
|
||||
|
178
block-party/table/7661.mzn
Normal file
178
block-party/table/7661.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 62, 40, 20, 61, 42, 52, 5, 25, 37, 14, 11, 46, 36, 0, 29, 41, 32, 44, 55, 19, 39, 45, 34, 60 |
|
||||
20, 38, 14, 5, 61, 45, 18, 39, 34, 50, 1, 44, 35, 31, 27, 17, 47, 15, 0, 37, 63, 22, 55, 26 |
|
||||
27, 51, 36, 47, 21, 6, 10, 17, 43, 34, 16, 52, 12, 44, 11, 46, 42, 57, 40, 32, 2, 59, 50, 25 |
|
||||
6, 24, 8, 31, 40, 39, 59, 16, 41, 33, 45, 15, 48, 56, 20, 38, 60, 29, 14, 55, 1, 35, 51, 22 |
|
||||
3, 63, 25, 60, 26, 57, 58, 6, 12, 21, 47, 4, 1, 33, 30, 56, 23, 54, 31, 19, 18, 52, 13, 37 |
|
||||
7, 16, 4, 5, 59, 2, 12, 3, 28, 11, 58, 22, 36, 15, 13, 43, 56, 42, 21, 29, 9, 49, 53, 26 |
|
||||
13, 3, 18, 17, 50, 43, 10, 57, 9, 46, 2, 61, 28, 53, 32, 24, 49, 30, 23, 62, 48, 7, 54, 8 |
|
||||
10, 27, 23, 38, 28, 41, 30, 51, 35, 0, 48, 62, 7, 49, 19, 4, 58, 9, 24, 54, 33, 53, 63, 8 |]
|
||||
;
|
||||
% cubes: [5, 8, 6, 3, 1, 7, 2, 4]
|
||||
% symbols: [60, 19, 5, 42, 32, 46, 39, 41, 54, 0, 26, 16, 34, 32, 14, 48, 37, 28, 42, 50, 11, 50, 22, 14]
|
||||
% rotations: [7, 14, 7, 20, 20, 24, 12, 23]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 19, 40, 0, 1, 39, 46, 5,
|
||||
1, 34, 32, 11, 1, 29, 42, 14, 1, 40, 0, 19, 1, 45, 25, 20, 1, 20, 45, 25,
|
||||
1, 42, 14, 29, 1, 11, 34, 32, 1, 32, 11, 34, 1, 37, 55, 36, 1, 55, 36, 37,
|
||||
1, 46, 5, 39, 1, 0, 19, 40, 1, 62, 52, 41, 1, 14, 29, 42, 1, 60, 61, 44, 1,
|
||||
25, 20, 45, 1, 5, 39, 46, 1, 41, 62, 52, 1, 36, 37, 55, 1, 61, 44, 60, 1,
|
||||
44, 60, 61, 1, 52, 41, 62, 2, 35, 34, 0, 2, 55, 47, 1, 2, 15, 26, 5, 2, 22,
|
||||
39, 14, 2, 26, 5, 15, 2, 20, 45, 17, 2, 63, 44, 18, 2, 45, 17, 20, 2, 39,
|
||||
14, 22, 2, 5, 15, 26, 2, 61, 50, 27, 2, 37, 38, 31, 2, 0, 35, 34, 2, 34, 0,
|
||||
35, 2, 38, 31, 37, 2, 31, 37, 38, 2, 14, 22, 39, 2, 18, 63, 44, 2, 17, 20,
|
||||
45, 2, 1, 55, 47, 2, 27, 61, 50, 2, 47, 1, 55, 2, 50, 27, 61, 2, 44, 18,
|
||||
63, 3, 52, 10, 2, 3, 46, 27, 6, 3, 2, 52, 10, 3, 21, 34, 11, 3, 43, 40, 12,
|
||||
3, 50, 42, 16, 3, 36, 59, 17, 3, 34, 11, 21, 3, 47, 57, 25, 3, 6, 46, 27,
|
||||
3, 51, 44, 32, 3, 11, 21, 34, 3, 59, 17, 36, 3, 12, 43, 40, 3, 16, 50, 42,
|
||||
3, 40, 12, 43, 3, 32, 51, 44, 3, 27, 6, 46, 3, 57, 25, 47, 3, 42, 16, 50,
|
||||
3, 44, 32, 51, 3, 10, 2, 52, 3, 25, 47, 57, 3, 17, 36, 59, 4, 15, 59, 1, 4,
|
||||
39, 38, 6, 4, 35, 16, 8, 4, 48, 41, 14, 4, 59, 1, 15, 4, 8, 35, 16, 4, 40,
|
||||
33, 20, 4, 31, 29, 22, 4, 56, 55, 24, 4, 22, 31, 29, 4, 29, 22, 31, 4, 20,
|
||||
40, 33, 4, 16, 8, 35, 4, 6, 39, 38, 4, 38, 6, 39, 4, 33, 20, 40, 4, 14, 48,
|
||||
41, 4, 51, 60, 45, 4, 41, 14, 48, 4, 60, 45, 51, 4, 24, 56, 55, 4, 55, 24,
|
||||
56, 4, 1, 15, 59, 4, 45, 51, 60, 5, 12, 31, 1, 5, 57, 56, 3, 5, 58, 18, 4,
|
||||
5, 25, 52, 6, 5, 31, 1, 12, 5, 23, 47, 13, 5, 4, 58, 18, 5, 63, 33, 19, 5,
|
||||
30, 26, 21, 5, 47, 13, 23, 5, 52, 6, 25, 5, 21, 30, 26, 5, 26, 21, 30, 5,
|
||||
1, 12, 31, 5, 19, 63, 33, 5, 60, 54, 37, 5, 13, 23, 47, 5, 6, 25, 52, 5,
|
||||
37, 60, 54, 5, 3, 57, 56, 5, 56, 3, 57, 5, 18, 4, 58, 5, 54, 37, 60, 5, 33,
|
||||
19, 63, 6, 43, 7, 2, 6, 4, 49, 3, 6, 49, 3, 4, 6, 42, 26, 5, 6, 2, 43, 7,
|
||||
6, 22, 12, 9, 6, 13, 59, 11, 6, 9, 22, 12, 6, 59, 11, 13, 6, 29, 16, 15, 6,
|
||||
15, 29, 16, 6, 36, 28, 21, 6, 12, 9, 22, 6, 5, 42, 26, 6, 21, 36, 28, 6,
|
||||
16, 15, 29, 6, 28, 21, 36, 6, 26, 5, 42, 6, 7, 2, 43, 6, 3, 4, 49, 6, 56,
|
||||
58, 53, 6, 58, 53, 56, 6, 53, 56, 58, 6, 11, 13, 59, 7, 54, 49, 2, 7, 53,
|
||||
62, 3, 7, 57, 18, 7, 7, 17, 30, 8, 7, 23, 28, 9, 7, 48, 61, 10, 7, 43, 24,
|
||||
13, 7, 30, 8, 17, 7, 7, 57, 18, 7, 28, 9, 23, 7, 13, 43, 24, 7, 9, 23, 28,
|
||||
7, 8, 17, 30, 7, 50, 46, 32, 7, 24, 13, 43, 7, 32, 50, 46, 7, 61, 10, 48,
|
||||
7, 2, 54, 49, 7, 46, 32, 50, 7, 62, 3, 53, 7, 49, 2, 54, 7, 18, 7, 57, 7,
|
||||
10, 48, 61, 7, 3, 53, 62, 8, 19, 28, 0, 8, 10, 41, 4, 8, 35, 24, 7, 8, 38,
|
||||
9, 8, 8, 8, 38, 9, 8, 41, 4, 10, 8, 28, 0, 19, 8, 53, 51, 23, 8, 7, 35, 24,
|
||||
8, 49, 54, 27, 8, 0, 19, 28, 8, 33, 62, 30, 8, 62, 30, 33, 8, 24, 7, 35, 8,
|
||||
9, 8, 38, 8, 4, 10, 41, 8, 63, 58, 48, 8, 54, 27, 49, 8, 23, 53, 51, 8, 51,
|
||||
23, 53, 8, 27, 49, 54, 8, 48, 63, 58, 8, 30, 33, 62, 8, 58, 48, 63]));
|
||||
|
178
block-party/table/7750.mzn
Normal file
178
block-party/table/7750.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 30, 23, 35, 29, 62, 37, 52, 40, 10, 18, 43, 17, 41, 7, 48, 54, 46, 16, 56, 33, 27, 0, 15, 59 |
|
||||
37, 53, 47, 32, 57, 16, 48, 30, 62, 58, 10, 55, 7, 14, 13, 36, 34, 60, 43, 49, 19, 29, 1, 56 |
|
||||
61, 53, 10, 11, 50, 41, 51, 4, 5, 28, 20, 18, 33, 40, 6, 16, 12, 56, 3, 8, 49, 14, 22, 15 |
|
||||
25, 29, 19, 4, 63, 30, 50, 47, 2, 53, 38, 51, 62, 60, 55, 39, 34, 12, 3, 15, 61, 24, 46, 42 |
|
||||
13, 50, 46, 38, 24, 8, 52, 31, 6, 41, 33, 3, 54, 59, 21, 28, 40, 37, 25, 36, 17, 9, 44, 42 |
|
||||
14, 60, 9, 58, 20, 1, 43, 38, 31, 57, 61, 6, 22, 11, 36, 63, 39, 24, 42, 34, 21, 49, 26, 45 |
|
||||
35, 47, 45, 11, 22, 7, 13, 28, 51, 0, 20, 27, 19, 63, 5, 44, 52, 25, 8, 31, 23, 2, 26, 32 |
|
||||
4, 32, 12, 57, 54, 23, 18, 2, 21, 5, 0, 44, 17, 9, 45, 55, 58, 1, 35, 39, 59, 26, 48, 27 |]
|
||||
;
|
||||
% cubes: [6, 5, 7, 3, 8, 1, 2, 4]
|
||||
% symbols: [14, 24, 35, 53, 55, 48, 57, 62, 1, 21, 44, 40, 23, 62, 58, 3, 63, 41, 7, 8, 4, 18, 13, 2]
|
||||
% rotations: [5, 10, 5, 6, 13, 14, 10, 15]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 40, 35, 0, 1, 33, 23, 7,
|
||||
1, 56, 41, 10, 1, 46, 43, 15, 1, 59, 29, 16, 1, 52, 27, 17, 1, 48, 62, 18,
|
||||
1, 7, 33, 23, 1, 17, 52, 27, 1, 16, 59, 29, 1, 37, 54, 30, 1, 23, 7, 33, 1,
|
||||
0, 40, 35, 1, 54, 30, 37, 1, 35, 0, 40, 1, 10, 56, 41, 1, 15, 46, 43, 1,
|
||||
43, 15, 46, 1, 62, 18, 48, 1, 27, 17, 52, 1, 30, 37, 54, 1, 41, 10, 56, 1,
|
||||
29, 16, 59, 1, 18, 48, 62, 2, 34, 10, 1, 2, 62, 43, 7, 2, 1, 34, 10, 2, 57,
|
||||
58, 13, 2, 49, 53, 14, 2, 36, 37, 16, 2, 55, 48, 19, 2, 30, 47, 29, 2, 47,
|
||||
29, 30, 2, 60, 56, 32, 2, 10, 1, 34, 2, 37, 16, 36, 2, 16, 36, 37, 2, 7,
|
||||
62, 43, 2, 29, 30, 47, 2, 19, 55, 48, 2, 53, 14, 49, 2, 14, 49, 53, 2, 48,
|
||||
19, 55, 2, 32, 60, 56, 2, 58, 13, 57, 2, 13, 57, 58, 2, 56, 32, 60, 2, 43,
|
||||
7, 62, 3, 33, 5, 3, 3, 10, 14, 4, 3, 3, 33, 5, 3, 50, 28, 6, 3, 53, 40, 8,
|
||||
3, 14, 4, 10, 3, 56, 15, 11, 3, 20, 22, 12, 3, 4, 10, 14, 3, 11, 56, 15, 3,
|
||||
61, 41, 16, 3, 51, 49, 18, 3, 22, 12, 20, 3, 12, 20, 22, 3, 6, 50, 28, 3,
|
||||
5, 3, 33, 3, 8, 53, 40, 3, 16, 61, 41, 3, 18, 51, 49, 3, 28, 6, 50, 3, 49,
|
||||
18, 51, 3, 40, 8, 53, 3, 15, 11, 56, 3, 41, 16, 61, 4, 3, 62, 2, 4, 62, 2,
|
||||
3, 4, 12, 42, 4, 4, 42, 4, 12, 4, 29, 60, 15, 4, 24, 47, 19, 4, 47, 19, 24,
|
||||
4, 30, 39, 25, 4, 60, 15, 29, 4, 39, 25, 30, 4, 38, 46, 34, 4, 46, 34, 38,
|
||||
4, 25, 30, 39, 4, 4, 12, 42, 4, 34, 38, 46, 4, 19, 24, 47, 4, 61, 51, 50,
|
||||
4, 50, 61, 51, 4, 55, 63, 53, 4, 63, 53, 55, 4, 15, 29, 60, 4, 51, 50, 61,
|
||||
4, 2, 3, 62, 4, 53, 55, 63, 5, 52, 17, 3, 5, 25, 54, 6, 5, 28, 13, 8, 5,
|
||||
31, 46, 9, 5, 8, 28, 13, 5, 3, 52, 17, 5, 24, 41, 21, 5, 41, 21, 24, 5, 54,
|
||||
6, 25, 5, 13, 8, 28, 5, 46, 9, 31, 5, 44, 40, 33, 5, 50, 59, 36, 5, 42, 38,
|
||||
37, 5, 37, 42, 38, 5, 33, 44, 40, 5, 21, 24, 41, 5, 38, 37, 42, 5, 40, 33,
|
||||
44, 5, 9, 31, 46, 5, 59, 36, 50, 5, 17, 3, 52, 5, 6, 25, 54, 5, 36, 50, 59,
|
||||
6, 63, 14, 1, 6, 43, 21, 6, 6, 49, 38, 9, 6, 34, 60, 11, 6, 1, 63, 14, 6,
|
||||
57, 36, 20, 6, 6, 43, 21, 6, 31, 42, 22, 6, 45, 58, 24, 6, 39, 61, 26, 6,
|
||||
42, 22, 31, 6, 60, 11, 34, 6, 20, 57, 36, 6, 9, 49, 38, 6, 61, 26, 39, 6,
|
||||
22, 31, 42, 6, 21, 6, 43, 6, 58, 24, 45, 6, 38, 9, 49, 6, 36, 20, 57, 6,
|
||||
24, 45, 58, 6, 11, 34, 60, 6, 26, 39, 61, 6, 14, 1, 63, 7, 5, 22, 0, 7, 28,
|
||||
45, 2, 7, 22, 0, 5, 7, 44, 35, 7, 7, 19, 51, 8, 7, 25, 32, 11, 7, 23, 27,
|
||||
13, 7, 51, 8, 19, 7, 26, 52, 20, 7, 0, 5, 22, 7, 27, 13, 23, 7, 32, 11, 25,
|
||||
7, 52, 20, 26, 7, 13, 23, 27, 7, 45, 2, 28, 7, 47, 63, 31, 7, 11, 25, 32,
|
||||
7, 7, 44, 35, 7, 35, 7, 44, 7, 2, 28, 45, 7, 63, 31, 47, 7, 8, 19, 51, 7,
|
||||
20, 26, 52, 7, 31, 47, 63, 8, 48, 58, 0, 8, 27, 57, 1, 8, 12, 26, 2, 8, 23,
|
||||
55, 4, 8, 45, 54, 5, 8, 39, 32, 9, 8, 26, 2, 12, 8, 21, 35, 17, 8, 59, 44,
|
||||
18, 8, 35, 17, 21, 8, 55, 4, 23, 8, 2, 12, 26, 8, 57, 1, 27, 8, 9, 39, 32,
|
||||
8, 17, 21, 35, 8, 32, 9, 39, 8, 18, 59, 44, 8, 54, 5, 45, 8, 58, 0, 48, 8,
|
||||
5, 45, 54, 8, 4, 23, 55, 8, 1, 27, 57, 8, 0, 48, 58, 8, 44, 18, 59]));
|
||||
|
178
block-party/table/8848.mzn
Normal file
178
block-party/table/8848.mzn
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* author: Jean-Noël Monette
|
||||
*/
|
||||
include "globals.mzn";
|
||||
|
||||
%cubes
|
||||
set of int: cubes=1..8;
|
||||
|
||||
int: ud=0;
|
||||
int: lr=8;
|
||||
int: fb=16;
|
||||
|
||||
set of int: pos=1..24;
|
||||
set of int: symbols=0..4*4*4-1;
|
||||
|
||||
array[cubes] of var cubes: cube_at;
|
||||
array[pos] of var symbols: symbol_at;
|
||||
|
||||
%Each cube is placed once.
|
||||
constraint alldifferent(cube_at);
|
||||
|
||||
%Party constraints on the 6 faces
|
||||
constraint party([symbol_at[i] | i in 1..4]);
|
||||
constraint party([symbol_at[i + 4] | i in 1..4]);
|
||||
constraint party([symbol_at[(i - 1) * 2 + 1 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[i * 2 + lr] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + fb] | i in 1..4]);
|
||||
constraint party([symbol_at[if i < 3 then i else i+2 endif + 2 + fb] | i in 1..4]);
|
||||
|
||||
%Linking cubes and symbols
|
||||
constraint forall(i in {1,4,6,7})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+lr],symbol_at[i+fb]]));
|
||||
constraint forall(i in {2,3,5,8})(
|
||||
link_cube_and_symbols([cube_at[i],symbol_at[i+ud],symbol_at[i+fb],symbol_at[i+lr]]));
|
||||
|
||||
%Sym break
|
||||
constraint cube_at[1] = 1;
|
||||
constraint cube_at[2] < cube_at[3];
|
||||
constraint cube_at[2] < cube_at[5];
|
||||
|
||||
%better to search on symbol_at first rather than cube_at
|
||||
solve :: int_search(symbol_at, first_fail, indomain_min, complete) satisfy;
|
||||
|
||||
%introduced because of limitation in output.
|
||||
array[pos] of var 0..3: color_at = [color(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: shape_at = [shape(symbol_at[i]) |i in pos];
|
||||
array[pos] of var 0..3: fill_at = [fill(symbol_at[i]) |i in pos];
|
||||
%names (for output)
|
||||
array[1..4] of string: colorname = ["blue","red","yellow","black"];
|
||||
array[1..4] of string: fillname = ["half","plain","empty","grid"];
|
||||
array[1..4] of string: shapename = ["triangle","circle","square","heart"];
|
||||
output [show(cube_at), "\n", show(symbol_at), "\n"] ++
|
||||
["pos " ++ show(i) ++ ": cube " ++ show(cube_at[i]) ++ "\n"
|
||||
++ "u/d:\t"++fillname[fix(fill_at[i+ud])+1]++"\t"++colorname[fix(color_at[i+ud])+1]++"\t"++shapename[fix(shape_at[i+ud])+1]++"\n"
|
||||
++ "f/b:\t"++fillname[fix(fill_at[i+fb])+1]++"\t"++colorname[fix(color_at[i+fb])+1]++"\t"++shapename[fix(shape_at[i+fb])+1]++"\n"
|
||||
++ "l/r:\t"++fillname[fix(fill_at[i+lr])+1]++"\t"++colorname[fix(color_at[i+lr])+1]++"\t"++shapename[fix(shape_at[i+lr])+1]++"\n"
|
||||
| i in 1..8];%fill
|
||||
|
||||
predicate diff_or_equal(array[1..4] of var 0..3: x)
|
||||
=
|
||||
forall(i in 1..4,j in i+1..4)(x[i]!=x[j])
|
||||
\/
|
||||
forall(i in 1..4,j in i+1..4)(x[i]=x[j]);
|
||||
|
||||
|
||||
% A party is alldiff or allequal for each of the three characteristics.
|
||||
predicate party(array[1..4] of var 0..63: symbols)
|
||||
= (
|
||||
diff_or_equal([color(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([shape(symbols[i]) | i in 1..4])
|
||||
/\ diff_or_equal([fill(symbols[i]) | i in 1..4])
|
||||
);
|
||||
|
||||
|
||||
%How to implement linking functions with the advantages of CSE.
|
||||
function array[1..3] of var 0..3: fcs(var 0..63:symbol) :: promise_total =
|
||||
let { var 0..3: color; var 0..3:shape;var 0..3: fill;
|
||||
constraint symbol = 4*4*fill+4*color+shape; }
|
||||
in [fill,color,shape];
|
||||
function var 0..3: color_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[2];
|
||||
function var 0..3: color(var int:symbol) ::promise_total = color_help(fcs(symbol));
|
||||
function var 0..3: fill_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[1];
|
||||
function var 0..3: fill(var int:symbol) ::promise_total = fill_help(fcs(symbol));
|
||||
function var 0..3: shape_help(array[1..3] of var 0..3: fcs) :: promise_total = fcs[3];
|
||||
function var 0..3: shape(var int:symbol) ::promise_total = shape_help(fcs(symbol));
|
||||
|
||||
%For parameters
|
||||
function 0..3: shape(int: symbol) = symbol mod 4;
|
||||
function 0..3: color(int: symbol) = symbol mod 16 div 4;
|
||||
function 0..3: fill(int:symbol) = symbol div 16;
|
||||
|
||||
array[1..8,1..24] of int: data;
|
||||
|
||||
%Which symbol positions on a cube are next to each other on the same corner.
|
||||
%Made by hand, I do not think there is any hope for finding a simple formula that could be used in precomputation :-)
|
||||
%Actually it might be divided by three and have a disjunction in link_cube_and_symbols
|
||||
array[1..24,1..3] of int: pp = [|21,12,7
|
||||
|23,17,11
|
||||
|24,4,18
|
||||
|22,8,3
|
||||
|1,6,16
|
||||
|2,14,20
|
||||
|4,18,24
|
||||
|3,22,8
|
||||
|7,21,12
|
||||
|5,10,15
|
||||
|6,16,1
|
||||
|8,3,22
|
||||
|16,1,6
|
||||
|15,5,10
|
||||
|13,9,19
|
||||
|14,20,2
|
||||
|18,24,4
|
||||
|20,2,14
|
||||
|19,13,9
|
||||
|17,11,23
|
||||
|12,7,21
|
||||
|11,23,17
|
||||
|9,19,13
|
||||
|10,15,5
|
||||
|];
|
||||
%% ---------- DATA ----------
|
||||
data =[| 32, 4, 28, 47, 2, 54, 21, 0, 6, 40, 17, 42, 26, 50, 23, 44, 46, 55, 19, 63, 12, 41, 29, 20 |
|
||||
7, 44, 29, 3, 9, 35, 36, 30, 27, 37, 10, 39, 19, 11, 51, 0, 34, 18, 28, 32, 46, 1, 21, 8 |
|
||||
52, 47, 48, 33, 58, 4, 8, 3, 5, 16, 13, 36, 38, 42, 49, 18, 29, 41, 7, 21, 53, 6, 62, 24 |
|
||||
17, 54, 34, 24, 1, 26, 9, 7, 47, 57, 39, 50, 43, 22, 13, 15, 45, 27, 41, 30, 48, 35, 23, 20 |
|
||||
5, 23, 48, 50, 13, 10, 45, 16, 40, 2, 18, 9, 58, 11, 32, 43, 28, 51, 22, 3, 0, 57, 20, 59 |
|
||||
31, 43, 60, 52, 24, 25, 37, 49, 35, 51, 15, 62, 1, 63, 54, 6, 8, 27, 58, 39, 14, 61, 33, 56 |
|
||||
5, 17, 25, 12, 57, 63, 62, 46, 31, 33, 45, 60, 30, 19, 53, 34, 4, 56, 61, 40, 38, 59, 55, 14 |
|
||||
12, 38, 10, 56, 61, 44, 22, 60, 49, 26, 52, 36, 2, 16, 53, 15, 31, 42, 37, 55, 11, 25, 59, 14 |]
|
||||
;
|
||||
% cubes: [1, 8, 3, 6, 5, 2, 7, 4]
|
||||
% symbols: [47, 36, 42, 33, 3, 34, 17, 48, 55, 11, 47, 8, 11, 10, 19, 9, 20, 22, 21, 15, 23, 21, 40, 50]
|
||||
% rotations: [7, 21, 16, 2, 18, 20, 6, 1]
|
||||
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate link_cube_and_symbols(array [1..4] of var int: cs) =
|
||||
table_int(cs, array2d(1..192, index_set(cs), [1, 28, 41, 0, 1, 40, 23, 2,
|
||||
1, 50, 63, 4, 1, 19, 26, 6, 1, 42, 21, 12, 1, 29, 46, 17, 1, 26, 6, 19, 1,
|
||||
47, 55, 20, 1, 12, 42, 21, 1, 2, 40, 23, 1, 6, 19, 26, 1, 41, 0, 28, 1, 46,
|
||||
17, 29, 1, 54, 44, 32, 1, 23, 2, 40, 1, 0, 28, 41, 1, 21, 12, 42, 1, 32,
|
||||
54, 44, 1, 17, 29, 46, 1, 55, 20, 47, 1, 63, 4, 50, 1, 44, 32, 54, 1, 20,
|
||||
47, 55, 1, 4, 50, 63, 2, 7, 35, 0, 2, 30, 29, 1, 2, 18, 8, 3, 2, 35, 0, 7,
|
||||
2, 3, 18, 8, 2, 37, 51, 9, 2, 21, 34, 10, 2, 32, 44, 11, 2, 8, 3, 18, 2,
|
||||
27, 28, 19, 2, 34, 10, 21, 2, 28, 19, 27, 2, 19, 27, 28, 2, 1, 30, 29, 2,
|
||||
29, 1, 30, 2, 44, 11, 32, 2, 10, 21, 34, 2, 0, 7, 35, 2, 46, 39, 36, 2, 51,
|
||||
9, 37, 2, 36, 46, 39, 2, 11, 32, 44, 2, 39, 36, 46, 2, 9, 37, 51, 3, 48, 6,
|
||||
3, 3, 18, 52, 4, 3, 7, 38, 5, 3, 3, 48, 6, 3, 38, 5, 7, 3, 53, 36, 8, 3,
|
||||
62, 29, 13, 3, 49, 58, 16, 3, 52, 4, 18, 3, 47, 42, 21, 3, 33, 41, 24, 3,
|
||||
13, 62, 29, 3, 41, 24, 33, 3, 8, 53, 36, 3, 5, 7, 38, 3, 24, 33, 41, 3, 21,
|
||||
47, 42, 3, 42, 21, 47, 3, 6, 3, 48, 3, 58, 16, 49, 3, 4, 18, 52, 3, 36, 8,
|
||||
53, 3, 16, 49, 58, 3, 29, 13, 62, 4, 57, 13, 1, 4, 34, 35, 7, 4, 48, 50, 9,
|
||||
4, 1, 57, 13, 4, 17, 26, 15, 4, 26, 15, 17, 4, 24, 27, 20, 4, 30, 54, 22,
|
||||
4, 45, 39, 23, 4, 27, 20, 24, 4, 15, 17, 26, 4, 20, 24, 27, 4, 54, 22, 30,
|
||||
4, 35, 7, 34, 4, 7, 34, 35, 4, 23, 45, 39, 4, 43, 47, 41, 4, 47, 41, 43, 4,
|
||||
39, 23, 45, 4, 41, 43, 47, 4, 50, 9, 48, 4, 9, 48, 50, 4, 22, 30, 54, 4,
|
||||
13, 1, 57, 5, 9, 45, 0, 5, 32, 13, 2, 5, 23, 11, 3, 5, 10, 43, 5, 5, 45, 0,
|
||||
9, 5, 43, 5, 10, 5, 3, 23, 11, 5, 2, 32, 13, 5, 48, 57, 16, 5, 20, 28, 18,
|
||||
5, 28, 18, 20, 5, 58, 40, 22, 5, 11, 3, 23, 5, 18, 20, 28, 5, 13, 2, 32, 5,
|
||||
22, 58, 40, 5, 5, 10, 43, 5, 0, 9, 45, 5, 57, 16, 48, 5, 51, 59, 50, 5, 59,
|
||||
50, 51, 5, 16, 48, 57, 5, 40, 22, 58, 5, 50, 51, 59, 6, 35, 58, 1, 6, 31,
|
||||
25, 6, 6, 15, 33, 8, 6, 62, 37, 14, 6, 33, 8, 15, 6, 51, 54, 24, 6, 6, 31,
|
||||
25, 6, 56, 52, 27, 6, 25, 6, 31, 6, 8, 15, 33, 6, 58, 1, 35, 6, 14, 62, 37,
|
||||
6, 43, 63, 39, 6, 63, 39, 43, 6, 60, 61, 49, 6, 54, 24, 51, 6, 27, 56, 52,
|
||||
6, 24, 51, 54, 6, 52, 27, 56, 6, 1, 35, 58, 6, 61, 49, 60, 6, 49, 60, 61,
|
||||
6, 37, 14, 62, 6, 39, 43, 63, 7, 45, 55, 4, 7, 63, 34, 5, 7, 56, 14, 12, 7,
|
||||
12, 56, 14, 7, 19, 40, 17, 7, 40, 17, 19, 7, 59, 46, 25, 7, 31, 61, 30, 7,
|
||||
61, 30, 31, 7, 53, 57, 33, 7, 5, 63, 34, 7, 60, 62, 38, 7, 17, 19, 40, 7,
|
||||
55, 4, 45, 7, 25, 59, 46, 7, 57, 33, 53, 7, 4, 45, 55, 7, 14, 12, 56, 7,
|
||||
33, 53, 57, 7, 46, 25, 59, 7, 62, 38, 60, 7, 30, 31, 61, 7, 38, 60, 62, 7,
|
||||
34, 5, 63, 8, 49, 37, 2, 8, 25, 60, 10, 8, 36, 22, 11, 8, 44, 15, 12, 8,
|
||||
56, 42, 14, 8, 12, 44, 15, 8, 55, 38, 16, 8, 11, 36, 22, 8, 60, 10, 25, 8,
|
||||
53, 61, 26, 8, 52, 59, 31, 8, 22, 11, 36, 8, 2, 49, 37, 8, 16, 55, 38, 8,
|
||||
14, 56, 42, 8, 15, 12, 44, 8, 37, 2, 49, 8, 59, 31, 52, 8, 61, 26, 53, 8,
|
||||
38, 16, 55, 8, 42, 14, 56, 8, 31, 52, 59, 8, 10, 25, 60, 8, 26, 53, 61]));
|
||||
|
836
jp-encoding/table/data100.mzn
Normal file
836
jp-encoding/table/data100.mzn
Normal file
@ -0,0 +1,836 @@
|
||||
%
|
||||
% jp-encoding.mzn
|
||||
%
|
||||
|
||||
%
|
||||
% There are several popular character encodings in Japan.
|
||||
% (EUC-JP, SJIS, UTF-8)
|
||||
%
|
||||
% If they are mixed into one text file (by accident or something),
|
||||
% text information will be lost.
|
||||
% So we can define a problem "recovering original encodings" for byte stream.
|
||||
%
|
||||
% In this problem, byte stream (as variable 'stream') is given as input
|
||||
% and encodings are assigned as output (as variable 'encoding').
|
||||
%
|
||||
|
||||
include "table.mzn";
|
||||
|
||||
% *_score tables have -log(probability of appearance) * 10 for each encoding.
|
||||
|
||||
array[1..256] of int: sjis_score = [
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 57, 135, 135, 135, 135, 135,
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
|
||||
74, 135, 128, 119, 135, 100, 135, 135, 96, 96, 112, 104, 106, 92, 106, 107,
|
||||
97, 92, 99, 95, 98, 106, 107, 103, 97, 101, 105, 135, 135, 111, 135, 119,
|
||||
65, 46, 45, 64, 75, 74, 79, 78, 71, 74, 79, 76, 71, 79, 59, 64,
|
||||
81, 78, 70, 67, 80, 81, 70, 82, 69, 81, 75, 72, 62, 60, 73, 70,
|
||||
76, 79, 75, 66, 77, 75, 78, 73, 77, 43, 43, 79, 54, 68, 68, 61,
|
||||
73, 67, 80, 66, 69, 53, 51, 72, 73, 68, 74, 71, 77, 80, 77, 135,
|
||||
77, 28, 11, 51, 75, 73, 69, 69, 51, 47, 49, 49, 44, 49, 41, 47,
|
||||
44, 48, 48, 47, 50, 46, 45, 48, 63, 76, 75, 79, 74, 68, 63, 73,
|
||||
50, 67, 40, 80, 45, 79, 56, 71, 59, 42, 45, 55, 67, 49, 68, 58,
|
||||
69, 53, 65, 54, 69, 45, 57, 50, 64, 60, 65, 54, 67, 44, 49, 58,
|
||||
66, 47, 58, 74, 43, 47, 43, 59, 43, 45, 62, 62, 40, 45, 60, 72,
|
||||
71, 69, 72, 68, 61, 80, 62, 68, 72, 68, 70, 75, 51, 66, 67, 61,
|
||||
47, 56, 59, 61, 62, 53, 53, 47, 51, 43, 49, 60, 74, 60, 83, 74,
|
||||
47, 47, 76, 71, 78, 82, 77, 83, 80, 81, 70, 67, 67, 135, 135, 135
|
||||
];
|
||||
array[1..256] of int: eucjp_score = [
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 57, 135, 135, 135, 135, 135,
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
|
||||
74, 135, 128, 119, 135, 100, 135, 135, 96, 96, 112, 104, 106, 92, 106, 107,
|
||||
97, 92, 99, 95, 98, 106, 107, 103, 97, 101, 105, 135, 135, 111, 135, 119,
|
||||
135, 112, 114, 100, 108, 102, 135, 113, 121, 110, 124, 135, 111, 106, 111, 111,
|
||||
100, 135, 114, 109, 112, 124, 135, 135, 124, 119, 128, 128, 121, 128, 135, 135,
|
||||
135, 94, 128, 102, 104, 95, 113, 97, 108, 90, 124, 124, 99, 101, 95, 90,
|
||||
105, 135, 93, 99, 94, 108, 128, 113, 135, 124, 117, 135, 135, 135, 135, 135,
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
|
||||
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
|
||||
135, 28, 41, 44, 11, 50, 45, 72, 55, 64, 57, 42, 45, 54, 65, 46,
|
||||
49, 49, 51, 48, 50, 48, 54, 41, 45, 45, 52, 44, 48, 45, 49, 39,
|
||||
43, 50, 51, 43, 49, 53, 40, 43, 41, 50, 34, 36, 48, 45, 38, 43,
|
||||
53, 66, 62, 66, 61, 62, 49, 50, 59, 62, 62, 63, 63, 68, 50, 63,
|
||||
63, 58, 46, 55, 57, 59, 58, 52, 50, 46, 49, 43, 48, 58, 63, 58,
|
||||
73, 67, 46, 46, 70, 68, 58, 66, 71, 73, 72, 74, 66, 61, 58, 135
|
||||
];
|
||||
array[1..256] of int: utf8_score = [
|
||||
139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 61, 139, 139, 139, 139, 139,
|
||||
139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139,
|
||||
78, 139, 132, 123, 139, 104, 139, 139, 100, 100, 116, 108, 110, 96, 110, 111,
|
||||
101, 96, 103, 99, 102, 110, 111, 107, 101, 105, 109, 139, 139, 115, 139, 139,
|
||||
139, 116, 118, 104, 112, 107, 139, 117, 125, 114, 128, 139, 115, 110, 115, 115,
|
||||
104, 139, 118, 113, 116, 128, 139, 139, 128, 123, 132, 132, 125, 132, 139, 139,
|
||||
139, 98, 132, 107, 108, 99, 117, 101, 112, 95, 128, 128, 103, 105, 99, 94,
|
||||
109, 139, 97, 103, 98, 112, 132, 117, 139, 128, 121, 139, 139, 139, 139, 139,
|
||||
36, 17, 27, 51, 42, 55, 47, 54, 41, 40, 49, 38, 42, 47, 64, 48,
|
||||
53, 52, 49, 45, 56, 51, 56, 46, 58, 50, 58, 52, 57, 51, 65, 46,
|
||||
51, 53, 63, 48, 54, 54, 44, 48, 45, 54, 45, 46, 61, 53, 42, 47,
|
||||
53, 61, 63, 57, 61, 63, 62, 62, 48, 59, 45, 53, 39, 57, 49, 57,
|
||||
139, 139, 139, 132, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 118, 139,
|
||||
139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139,
|
||||
139, 139, 68, 14, 42, 36, 40, 44, 44, 47, 139, 139, 139, 139, 139, 40,
|
||||
139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139
|
||||
];
|
||||
|
||||
|
||||
%
|
||||
% labels for encoding
|
||||
%
|
||||
|
||||
int: e_ascii = 0;
|
||||
int: e_euc_jp = 1;
|
||||
int: e_sjis = 2;
|
||||
int: e_utf8 = 3;
|
||||
int: e_unknown = 4;
|
||||
|
||||
%
|
||||
% labels for byte_status
|
||||
%
|
||||
|
||||
int: b_ascii = 0;
|
||||
|
||||
int: b_euc1 = 1;
|
||||
int: b_euc2 = 2;
|
||||
|
||||
int: b_sjis1_1 = 3;
|
||||
int: b_sjis2_1 = 4;
|
||||
int: b_sjis2_2 = 5;
|
||||
|
||||
int: b_utf8_2_1 = 6;
|
||||
int: b_utf8_2_2 = 7;
|
||||
int: b_utf8_3_1 = 8;
|
||||
int: b_utf8_3_2 = 9;
|
||||
int: b_utf8_3_3 = 10;
|
||||
int: b_utf8_4_1 = 11;
|
||||
int: b_utf8_4_2 = 12;
|
||||
int: b_utf8_4_3 = 13;
|
||||
int: b_utf8_4_4 = 14;
|
||||
|
||||
int: b_unknown = 15;
|
||||
|
||||
%
|
||||
% test data
|
||||
%
|
||||
% int: len = 12;
|
||||
% array[1..len] of int: stream = [ 227, 129, 138, 227, 129, 175, 227, 130, 136, 227, 129, 134 ];
|
||||
int: len;
|
||||
set of int: rng = 1..len;
|
||||
|
||||
array[rng] of int: stream;
|
||||
|
||||
% int: len = 3 ;
|
||||
% array[rng] of int: stream = [ 65, 66, 67 ];
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
% Variables
|
||||
|
||||
array[rng] of var 0..b_unknown: byte_status;
|
||||
array[rng] of var 0..e_unknown: encoding;
|
||||
array[rng] of var 0..1: char_start;
|
||||
|
||||
set of int: scoreType = 0..max(i in 1..256)(eucjp_score[i] + sjis_score[i] + utf8_score[i]) + 1000;
|
||||
int: maxObj = len * (max(i in 1..256)(eucjp_score[i] + sjis_score[i] + utf8_score[i]) + 1000);
|
||||
var 0..maxObj: objective;
|
||||
|
||||
constraint objective = sum (i in rng) (
|
||||
score_of(encoding[i],stream[i])
|
||||
);
|
||||
|
||||
function var scoreType: score_of(var int: encoding_i, int: stream_i) =
|
||||
let{
|
||||
var scoreType: score_i;
|
||||
constraint score_computation(encoding_i,stream_i, score_i);
|
||||
} in score_i;
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
% Constraints
|
||||
|
||||
constraint forall (i in rng) (
|
||||
if i >= 2 then link_statuses(byte_status[i],byte_status[i-1]) else true endif
|
||||
/\
|
||||
link_vars(encoding[i],byte_status[i],char_start[i])
|
||||
/\
|
||||
init(byte_status[i],i)
|
||||
/\
|
||||
stream_to_status(i,stream,byte_status[i])
|
||||
);
|
||||
|
||||
|
||||
predicate stream_to_status(int:i, array[int] of int: stream, var int: byte_status_i) =
|
||||
( forall([
|
||||
%
|
||||
% ASCII
|
||||
%
|
||||
if (stream[i] < 128) then true else
|
||||
byte_status_i != b_ascii endif
|
||||
,
|
||||
%
|
||||
% UTF-8
|
||||
%
|
||||
|
||||
% C2-DF, 80-BF
|
||||
if (i >= len) then
|
||||
byte_status_i != b_utf8_2_1
|
||||
else
|
||||
if ((194 <= stream[i] /\ stream[i] <= 223)
|
||||
/\ (128 <= stream[i+1] /\ stream[i+1] <= 191))
|
||||
then true else
|
||||
byte_status_i != b_utf8_2_1
|
||||
endif
|
||||
endif
|
||||
,
|
||||
|
||||
% E0-EF, 80-BF, 80-BF
|
||||
if (i >= len - 1) then
|
||||
byte_status_i != b_utf8_3_1
|
||||
else
|
||||
if ((224 <= stream[i] /\ stream[i] <= 239)
|
||||
/\ (128 <= stream[i+1] /\ stream[i+1] <= 191)
|
||||
/\ (128 <= stream[i+2] /\ stream[i+2] <= 191))
|
||||
then true else
|
||||
byte_status_i != b_utf8_3_1
|
||||
endif
|
||||
endif
|
||||
,
|
||||
|
||||
% F0-F7, 80-BF, 80-BF, 80-BF
|
||||
if (i >= len - 2) then
|
||||
byte_status_i != b_utf8_4_1
|
||||
else
|
||||
if (240 <= stream[i] /\ stream[i] <= 247
|
||||
/\ 128 <= stream[i+1] /\ stream[i+1] <= 191
|
||||
/\ 128 <= stream[i+2] /\ stream[i+2] <= 191
|
||||
/\ 128 <= stream[i+3] /\ stream[i+3] <= 191)
|
||||
then true else
|
||||
byte_status_i != b_utf8_4_1
|
||||
endif
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% EUC-JP (CP51932)
|
||||
% (A1-A8, AD, B0-F4, F9-FC), (A1-FE)
|
||||
%
|
||||
if (i >= len) then
|
||||
byte_status_i !=b_euc1
|
||||
else
|
||||
if ((161 <= stream[i] /\ stream[i] <= 168)
|
||||
\/ (173 = stream[i])
|
||||
\/ (176 <= stream[i] /\ stream[i] <= 244)
|
||||
\/ (249 <= stream[i] /\ stream[i] <= 252))
|
||||
/\ (161 <= stream[i+1] /\ stream[i+1] <= 254)
|
||||
then true else
|
||||
byte_status_i != b_euc1
|
||||
endif
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% SJIS
|
||||
%
|
||||
|
||||
% (A1-DF)
|
||||
if (161 <= stream[i] /\ stream[i] <= 223)
|
||||
then true else
|
||||
byte_status_i != b_sjis1_1
|
||||
endif
|
||||
,
|
||||
|
||||
% (81-9F, E0-FC), (40-7E, 80-FC)
|
||||
if (i >= len) then
|
||||
byte_status_i != b_sjis2_1
|
||||
else
|
||||
if ((129 <= stream[i] /\ stream[i] <= 159)
|
||||
\/ (224 <= stream[i] /\ stream[i] <= 252))
|
||||
/\ ((64 <= stream[i+1] /\ stream[i+1] <= 126)
|
||||
\/ (128 <= stream[i+1] /\ stream[i+1] <= 252))
|
||||
then true else
|
||||
byte_status_i != b_sjis2_1
|
||||
endif
|
||||
endif
|
||||
])
|
||||
);
|
||||
|
||||
predicate stream_to_status_old(int:i, array[int] of int: stream, var int: byte_status_i) =
|
||||
( forall([
|
||||
%
|
||||
% ASCII
|
||||
%
|
||||
if (stream[i] < 128) then true else
|
||||
byte_status_i != b_ascii endif
|
||||
,
|
||||
%
|
||||
% UTF-8
|
||||
%
|
||||
|
||||
% C2-DF, 80-BF
|
||||
if (i >= len) then
|
||||
byte_status_i != b_utf8_2_1
|
||||
else
|
||||
byte_status_i = b_utf8_2_1 ->
|
||||
((194 <= stream[i] /\ stream[i] <= 223)
|
||||
/\ (128 <= stream[i+1] /\ stream[i+1] <= 191))
|
||||
endif
|
||||
,
|
||||
|
||||
% E0-EF, 80-BF, 80-BF
|
||||
if (i >= len - 1) then
|
||||
byte_status_i != b_utf8_3_1
|
||||
else
|
||||
byte_status_i = b_utf8_3_1 ->
|
||||
((224 <= stream[i] /\ stream[i] <= 239)
|
||||
/\ (128 <= stream[i+1] /\ stream[i+1] <= 191)
|
||||
/\ (128 <= stream[i+2] /\ stream[i+2] <= 191))
|
||||
endif
|
||||
,
|
||||
|
||||
% F0-F7, 80-BF, 80-BF, 80-BF
|
||||
if (i >= len - 2) then
|
||||
byte_status_i != b_utf8_4_1
|
||||
else
|
||||
byte_status_i = b_utf8_4_1 ->
|
||||
(240 <= stream[i] /\ stream[i] <= 247
|
||||
/\ 128 <= stream[i+1] /\ stream[i+1] <= 191
|
||||
/\ 128 <= stream[i+2] /\ stream[i+2] <= 191
|
||||
/\ 128 <= stream[i+3] /\ stream[i+3] <= 191)
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% EUC-JP (CP51932)
|
||||
% (A1-A8, AD, B0-F4, F9-FC), (A1-FE)
|
||||
%
|
||||
if (i >= len) then
|
||||
byte_status_i !=b_euc1
|
||||
else
|
||||
byte_status_i = b_euc1 ->
|
||||
((161 <= stream[i] /\ stream[i] <= 168)
|
||||
\/ (173 = stream[i])
|
||||
\/ (176 <= stream[i] /\ stream[i] <= 244)
|
||||
\/ (249 <= stream[i] /\ stream[i] <= 252))
|
||||
/\ (161 <= stream[i+1] /\ stream[i+1] <= 254)
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% SJIS
|
||||
%
|
||||
|
||||
% (A1-DF)
|
||||
byte_status_i = b_sjis1_1 ->
|
||||
(161 <= stream[i] /\ stream[i] <= 223)
|
||||
,
|
||||
|
||||
% (81-9F, E0-FC), (40-7E, 80-FC)
|
||||
if (i >= len) then
|
||||
byte_status_i != b_sjis2_1
|
||||
else
|
||||
byte_status_i = b_sjis2_1 ->
|
||||
((129 <= stream[i] /\ stream[i] <= 159)
|
||||
\/ (224 <= stream[i] /\ stream[i] <= 252))
|
||||
/\ ((64 <= stream[i+1] /\ stream[i+1] <= 126)
|
||||
\/ (128 <= stream[i+1] /\ stream[i+1] <= 252))
|
||||
endif
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
predicate init(var int: byte_status_i, int: i) =
|
||||
( forall([
|
||||
%
|
||||
% UTF-8
|
||||
%
|
||||
|
||||
% C2-DF, 80-BF
|
||||
if (i < 2) then
|
||||
byte_status_i != b_utf8_2_2
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
|
||||
% E0-EF, 80-BF, 80-BF
|
||||
if (i < 2) then
|
||||
byte_status_i != b_utf8_3_2
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
if (i < 3) then
|
||||
byte_status_i != b_utf8_3_3
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
|
||||
% F0-F7, 80-BF, 80-BF, 80-BF
|
||||
if (i < 2) then
|
||||
byte_status_i != b_utf8_4_2
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
if (i < 3) then
|
||||
byte_status_i != b_utf8_4_3
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
if (i < 4) then
|
||||
byte_status_i != b_utf8_4_4
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% EUC-JP (CP51932)
|
||||
% (A1-A8, AD, B0-F4, F9-FC), (A1-FE)
|
||||
%
|
||||
if (i < 2) then
|
||||
byte_status_i != b_euc2
|
||||
else
|
||||
true
|
||||
endif
|
||||
,
|
||||
|
||||
%
|
||||
% SJIS
|
||||
%
|
||||
|
||||
% (A1-DF)
|
||||
|
||||
% (81-9F, E0-FC), (40-7E, 80-FC)
|
||||
if (i < 2) then
|
||||
byte_status_i != b_sjis2_2
|
||||
else
|
||||
true
|
||||
endif
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
% Search and Solve
|
||||
|
||||
solve
|
||||
:: seq_search([
|
||||
int_search(byte_status, first_fail, indomain_split, complete),
|
||||
int_search(char_start, input_order, indomain_max, complete),
|
||||
int_search(encoding, first_fail, indomain_split, complete)
|
||||
])
|
||||
minimize objective;
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
% Output
|
||||
|
||||
output [
|
||||
"encoding = ", show(encoding), ";\n",
|
||||
"byte_status = ", show(byte_status), ";\n",
|
||||
"char_start = ", show(char_start), ";\n",
|
||||
"constraint objective = ", show(objective), ";\n"
|
||||
];
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
%% ---------- DATA ----------
|
||||
len = 164;
|
||||
stream = [
|
||||
227,
|
||||
129,
|
||||
157,
|
||||
227,
|
||||
129,
|
||||
147,
|
||||
227,
|
||||
129,
|
||||
167,
|
||||
230,
|
||||
180,
|
||||
155,
|
||||
228,
|
||||
184,
|
||||
173,
|
||||
227,
|
||||
129,
|
||||
174,
|
||||
227,
|
||||
129,
|
||||
149,
|
||||
227,
|
||||
129,
|
||||
179,
|
||||
227,
|
||||
130,
|
||||
140,
|
||||
230,
|
||||
150,
|
||||
185,
|
||||
227,
|
||||
129,
|
||||
175,
|
||||
228,
|
||||
184,
|
||||
128,
|
||||
233,
|
||||
128,
|
||||
154,
|
||||
227,
|
||||
130,
|
||||
138,
|
||||
227,
|
||||
129,
|
||||
167,
|
||||
227,
|
||||
129,
|
||||
175,
|
||||
227,
|
||||
129,
|
||||
170,
|
||||
227,
|
||||
129,
|
||||
132,
|
||||
227,
|
||||
128,
|
||||
130,
|
||||
10,
|
||||
227,
|
||||
129,
|
||||
130,
|
||||
227,
|
||||
130,
|
||||
139,
|
||||
230,
|
||||
151,
|
||||
165,
|
||||
227,
|
||||
129,
|
||||
174,
|
||||
230,
|
||||
154,
|
||||
174,
|
||||
230,
|
||||
150,
|
||||
185,
|
||||
227,
|
||||
129,
|
||||
174,
|
||||
228,
|
||||
186,
|
||||
139,
|
||||
227,
|
||||
129,
|
||||
167,
|
||||
227,
|
||||
129,
|
||||
130,
|
||||
227,
|
||||
130,
|
||||
139,
|
||||
227,
|
||||
128,
|
||||
130,
|
||||
228,
|
||||
184,
|
||||
128,
|
||||
228,
|
||||
186,
|
||||
186,
|
||||
227,
|
||||
129,
|
||||
174,
|
||||
228,
|
||||
184,
|
||||
139,
|
||||
228,
|
||||
186,
|
||||
186,
|
||||
227,
|
||||
129,
|
||||
140,
|
||||
227,
|
||||
128,
|
||||
129,
|
||||
231,
|
||||
190,
|
||||
133,
|
||||
231,
|
||||
148,
|
||||
159,
|
||||
233,
|
||||
150,
|
||||
128,
|
||||
227,
|
||||
129,
|
||||
174,
|
||||
228,
|
||||
184,
|
||||
139,
|
||||
227,
|
||||
129,
|
||||
167,
|
||||
233,
|
||||
155,
|
||||
168,
|
||||
227,
|
||||
130,
|
||||
132,
|
||||
227,
|
||||
129,
|
||||
191,
|
||||
227,
|
||||
130,
|
||||
146,
|
||||
229,
|
||||
190,
|
||||
133,
|
||||
227,
|
||||
129,
|
||||
163,
|
||||
227,
|
||||
129,
|
||||
166,
|
||||
227,
|
||||
129,
|
||||
132,
|
||||
227,
|
||||
129,
|
||||
159,
|
||||
227,
|
||||
128,
|
||||
130,
|
||||
10
|
||||
];
|
||||
%% ---------- GENERATED TABLE ----------
|
||||
include "table.mzn";
|
||||
|
||||
predicate score_computation(var 0..e_unknown: encoding_i, var 0..255: stream_i,
|
||||
var scoreType: score_i) =
|
||||
table_int([encoding_i, stream_i, score_i], array2d(1..1280,
|
||||
index_set([encoding_i, stream_i, score_i]), [0, 0, 0, 0, 1, 0, 0, 2, 0, 0,
|
||||
3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0,
|
||||
11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18,
|
||||
0, 0, 19, 0, 0, 20, 0, 0, 21, 0, 0, 22, 0, 0, 23, 0, 0, 24, 0, 0, 25, 0, 0,
|
||||
26, 0, 0, 27, 0, 0, 28, 0, 0, 29, 0, 0, 30, 0, 0, 31, 0, 0, 32, 0, 0, 33,
|
||||
0, 0, 34, 0, 0, 35, 0, 0, 36, 0, 0, 37, 0, 0, 38, 0, 0, 39, 0, 0, 40, 0, 0,
|
||||
41, 0, 0, 42, 0, 0, 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, 0, 0, 47, 0, 0, 48,
|
||||
0, 0, 49, 0, 0, 50, 0, 0, 51, 0, 0, 52, 0, 0, 53, 0, 0, 54, 0, 0, 55, 0, 0,
|
||||
56, 0, 0, 57, 0, 0, 58, 0, 0, 59, 0, 0, 60, 0, 0, 61, 0, 0, 62, 0, 0, 63,
|
||||
0, 0, 64, 0, 0, 65, 0, 0, 66, 0, 0, 67, 0, 0, 68, 0, 0, 69, 0, 0, 70, 0, 0,
|
||||
71, 0, 0, 72, 0, 0, 73, 0, 0, 74, 0, 0, 75, 0, 0, 76, 0, 0, 77, 0, 0, 78,
|
||||
0, 0, 79, 0, 0, 80, 0, 0, 81, 0, 0, 82, 0, 0, 83, 0, 0, 84, 0, 0, 85, 0, 0,
|
||||
86, 0, 0, 87, 0, 0, 88, 0, 0, 89, 0, 0, 90, 0, 0, 91, 0, 0, 92, 0, 0, 93,
|
||||
0, 0, 94, 0, 0, 95, 0, 0, 96, 0, 0, 97, 0, 0, 98, 0, 0, 99, 0, 0, 100, 0,
|
||||
0, 101, 0, 0, 102, 0, 0, 103, 0, 0, 104, 0, 0, 105, 0, 0, 106, 0, 0, 107,
|
||||
0, 0, 108, 0, 0, 109, 0, 0, 110, 0, 0, 111, 0, 0, 112, 0, 0, 113, 0, 0,
|
||||
114, 0, 0, 115, 0, 0, 116, 0, 0, 117, 0, 0, 118, 0, 0, 119, 0, 0, 120, 0,
|
||||
0, 121, 0, 0, 122, 0, 0, 123, 0, 0, 124, 0, 0, 125, 0, 0, 126, 0, 0, 127,
|
||||
0, 0, 128, 0, 0, 129, 0, 0, 130, 0, 0, 131, 0, 0, 132, 0, 0, 133, 0, 0,
|
||||
134, 0, 0, 135, 0, 0, 136, 0, 0, 137, 0, 0, 138, 0, 0, 139, 0, 0, 140, 0,
|
||||
0, 141, 0, 0, 142, 0, 0, 143, 0, 0, 144, 0, 0, 145, 0, 0, 146, 0, 0, 147,
|
||||
0, 0, 148, 0, 0, 149, 0, 0, 150, 0, 0, 151, 0, 0, 152, 0, 0, 153, 0, 0,
|
||||
154, 0, 0, 155, 0, 0, 156, 0, 0, 157, 0, 0, 158, 0, 0, 159, 0, 0, 160, 0,
|
||||
0, 161, 0, 0, 162, 0, 0, 163, 0, 0, 164, 0, 0, 165, 0, 0, 166, 0, 0, 167,
|
||||
0, 0, 168, 0, 0, 169, 0, 0, 170, 0, 0, 171, 0, 0, 172, 0, 0, 173, 0, 0,
|
||||
174, 0, 0, 175, 0, 0, 176, 0, 0, 177, 0, 0, 178, 0, 0, 179, 0, 0, 180, 0,
|
||||
0, 181, 0, 0, 182, 0, 0, 183, 0, 0, 184, 0, 0, 185, 0, 0, 186, 0, 0, 187,
|
||||
0, 0, 188, 0, 0, 189, 0, 0, 190, 0, 0, 191, 0, 0, 192, 0, 0, 193, 0, 0,
|
||||
194, 0, 0, 195, 0, 0, 196, 0, 0, 197, 0, 0, 198, 0, 0, 199, 0, 0, 200, 0,
|
||||
0, 201, 0, 0, 202, 0, 0, 203, 0, 0, 204, 0, 0, 205, 0, 0, 206, 0, 0, 207,
|
||||
0, 0, 208, 0, 0, 209, 0, 0, 210, 0, 0, 211, 0, 0, 212, 0, 0, 213, 0, 0,
|
||||
214, 0, 0, 215, 0, 0, 216, 0, 0, 217, 0, 0, 218, 0, 0, 219, 0, 0, 220, 0,
|
||||
0, 221, 0, 0, 222, 0, 0, 223, 0, 0, 224, 0, 0, 225, 0, 0, 226, 0, 0, 227,
|
||||
0, 0, 228, 0, 0, 229, 0, 0, 230, 0, 0, 231, 0, 0, 232, 0, 0, 233, 0, 0,
|
||||
234, 0, 0, 235, 0, 0, 236, 0, 0, 237, 0, 0, 238, 0, 0, 239, 0, 0, 240, 0,
|
||||
0, 241, 0, 0, 242, 0, 0, 243, 0, 0, 244, 0, 0, 245, 0, 0, 246, 0, 0, 247,
|
||||
0, 0, 248, 0, 0, 249, 0, 0, 250, 0, 0, 251, 0, 0, 252, 0, 0, 253, 0, 0,
|
||||
254, 0, 0, 255, 0, 1, 164, 11, 1, 161, 28, 1, 202, 34, 1, 203, 36, 1, 206,
|
||||
38, 1, 191, 39, 1, 198, 40, 1, 162, 41, 1, 183, 41, 1, 200, 41, 1, 171, 42,
|
||||
1, 192, 43, 1, 195, 43, 1, 199, 43, 1, 207, 43, 1, 235, 43, 1, 163, 44, 1,
|
||||
187, 44, 1, 166, 45, 1, 172, 45, 1, 184, 45, 1, 185, 45, 1, 189, 45, 1,
|
||||
205, 45, 1, 175, 46, 1, 226, 46, 1, 233, 46, 1, 242, 46, 1, 243, 46, 1,
|
||||
179, 48, 1, 181, 48, 1, 188, 48, 1, 204, 48, 1, 236, 48, 1, 176, 49, 1,
|
||||
177, 49, 1, 190, 49, 1, 196, 49, 1, 214, 49, 1, 234, 49, 1, 165, 50, 1,
|
||||
180, 50, 1, 193, 50, 1, 201, 50, 1, 215, 50, 1, 222, 50, 1, 232, 50, 1,
|
||||
178, 51, 1, 194, 51, 1, 186, 52, 1, 231, 52, 1, 197, 53, 1, 208, 53, 1,
|
||||
173, 54, 1, 182, 54, 1, 168, 55, 1, 227, 55, 1, 10, 57, 1, 170, 57, 1, 228,
|
||||
57, 1, 225, 58, 1, 230, 58, 1, 237, 58, 1, 239, 58, 1, 246, 58, 1, 254, 58,
|
||||
1, 216, 59, 1, 229, 59, 1, 212, 61, 1, 253, 61, 1, 210, 62, 1, 213, 62, 1,
|
||||
217, 62, 1, 218, 62, 1, 219, 63, 1, 220, 63, 1, 223, 63, 1, 224, 63, 1,
|
||||
238, 63, 1, 169, 64, 1, 174, 65, 1, 209, 66, 1, 211, 66, 1, 247, 66, 1,
|
||||
252, 66, 1, 241, 67, 1, 221, 68, 1, 245, 68, 1, 244, 70, 1, 248, 71, 1,
|
||||
167, 72, 1, 250, 72, 1, 240, 73, 1, 249, 73, 1, 32, 74, 1, 251, 74, 1, 105,
|
||||
90, 1, 111, 90, 1, 45, 92, 1, 49, 92, 1, 114, 93, 1, 97, 94, 1, 116, 94, 1,
|
||||
51, 95, 1, 101, 95, 1, 110, 95, 1, 40, 96, 1, 41, 96, 1, 48, 97, 1, 56, 97,
|
||||
1, 103, 97, 1, 52, 98, 1, 50, 99, 1, 108, 99, 1, 115, 99, 1, 37, 100, 1,
|
||||
67, 100, 1, 80, 100, 1, 57, 101, 1, 109, 101, 1, 69, 102, 1, 99, 102, 1,
|
||||
55, 103, 1, 43, 104, 1, 100, 104, 1, 58, 105, 1, 112, 105, 1, 44, 106, 1,
|
||||
46, 106, 1, 53, 106, 1, 77, 106, 1, 47, 107, 1, 54, 107, 1, 68, 108, 1,
|
||||
104, 108, 1, 117, 108, 1, 83, 109, 1, 73, 110, 1, 61, 111, 1, 76, 111, 1,
|
||||
78, 111, 1, 79, 111, 1, 42, 112, 1, 65, 112, 1, 84, 112, 1, 71, 113, 1,
|
||||
102, 113, 1, 119, 113, 1, 66, 114, 1, 82, 114, 1, 122, 117, 1, 35, 119, 1,
|
||||
63, 119, 1, 89, 119, 1, 72, 121, 1, 92, 121, 1, 74, 124, 1, 85, 124, 1, 88,
|
||||
124, 1, 106, 124, 1, 107, 124, 1, 121, 124, 1, 34, 128, 1, 90, 128, 1, 91,
|
||||
128, 1, 93, 128, 1, 98, 128, 1, 118, 128, 1, 0, 135, 1, 1, 135, 1, 2, 135,
|
||||
1, 3, 135, 1, 4, 135, 1, 5, 135, 1, 6, 135, 1, 7, 135, 1, 8, 135, 1, 9,
|
||||
135, 1, 11, 135, 1, 12, 135, 1, 13, 135, 1, 14, 135, 1, 15, 135, 1, 16,
|
||||
135, 1, 17, 135, 1, 18, 135, 1, 19, 135, 1, 20, 135, 1, 21, 135, 1, 22,
|
||||
135, 1, 23, 135, 1, 24, 135, 1, 25, 135, 1, 26, 135, 1, 27, 135, 1, 28,
|
||||
135, 1, 29, 135, 1, 30, 135, 1, 31, 135, 1, 33, 135, 1, 36, 135, 1, 38,
|
||||
135, 1, 39, 135, 1, 59, 135, 1, 60, 135, 1, 62, 135, 1, 64, 135, 1, 70,
|
||||
135, 1, 75, 135, 1, 81, 135, 1, 86, 135, 1, 87, 135, 1, 94, 135, 1, 95,
|
||||
135, 1, 96, 135, 1, 113, 135, 1, 120, 135, 1, 123, 135, 1, 124, 135, 1,
|
||||
125, 135, 1, 126, 135, 1, 127, 135, 1, 128, 135, 1, 129, 135, 1, 130, 135,
|
||||
1, 131, 135, 1, 132, 135, 1, 133, 135, 1, 134, 135, 1, 135, 135, 1, 136,
|
||||
135, 1, 137, 135, 1, 138, 135, 1, 139, 135, 1, 140, 135, 1, 141, 135, 1,
|
||||
142, 135, 1, 143, 135, 1, 144, 135, 1, 145, 135, 1, 146, 135, 1, 147, 135,
|
||||
1, 148, 135, 1, 149, 135, 1, 150, 135, 1, 151, 135, 1, 152, 135, 1, 153,
|
||||
135, 1, 154, 135, 1, 155, 135, 1, 156, 135, 1, 157, 135, 1, 158, 135, 1,
|
||||
159, 135, 1, 160, 135, 1, 255, 135, 2, 130, 11, 2, 129, 28, 2, 162, 40, 2,
|
||||
204, 40, 2, 142, 41, 2, 169, 42, 2, 105, 43, 2, 106, 43, 2, 196, 43, 2,
|
||||
198, 43, 2, 200, 43, 2, 233, 43, 2, 140, 44, 2, 144, 44, 2, 189, 44, 2, 66,
|
||||
45, 2, 150, 45, 2, 164, 45, 2, 170, 45, 2, 181, 45, 2, 201, 45, 2, 205, 45,
|
||||
2, 65, 46, 2, 149, 46, 2, 137, 47, 2, 143, 47, 2, 147, 47, 2, 193, 47, 2,
|
||||
197, 47, 2, 224, 47, 2, 231, 47, 2, 240, 47, 2, 241, 47, 2, 145, 48, 2,
|
||||
146, 48, 2, 151, 48, 2, 138, 49, 2, 139, 49, 2, 141, 49, 2, 173, 49, 2,
|
||||
190, 49, 2, 234, 49, 2, 148, 50, 2, 160, 50, 2, 183, 50, 2, 118, 51, 2,
|
||||
131, 51, 2, 136, 51, 2, 220, 51, 2, 232, 51, 2, 117, 53, 2, 177, 53, 2,
|
||||
229, 53, 2, 230, 53, 2, 108, 54, 2, 179, 54, 2, 187, 54, 2, 171, 55, 2,
|
||||
166, 56, 2, 225, 56, 2, 10, 57, 2, 182, 57, 2, 175, 58, 2, 191, 58, 2, 194,
|
||||
58, 2, 78, 59, 2, 168, 59, 2, 199, 59, 2, 226, 59, 2, 93, 60, 2, 185, 60,
|
||||
2, 206, 60, 2, 235, 60, 2, 237, 60, 2, 111, 61, 2, 212, 61, 2, 223, 61, 2,
|
||||
227, 61, 2, 92, 62, 2, 202, 62, 2, 203, 62, 2, 214, 62, 2, 228, 62, 2, 152,
|
||||
63, 2, 158, 63, 2, 67, 64, 2, 79, 64, 2, 184, 64, 2, 64, 65, 2, 178, 65, 2,
|
||||
186, 65, 2, 99, 66, 2, 115, 66, 2, 192, 66, 2, 221, 66, 2, 83, 67, 2, 113,
|
||||
67, 2, 161, 67, 2, 172, 67, 2, 188, 67, 2, 222, 67, 2, 251, 67, 2, 252, 67,
|
||||
2, 109, 68, 2, 110, 68, 2, 121, 68, 2, 157, 68, 2, 174, 68, 2, 211, 68, 2,
|
||||
215, 68, 2, 217, 68, 2, 88, 69, 2, 116, 69, 2, 134, 69, 2, 135, 69, 2, 176,
|
||||
69, 2, 180, 69, 2, 209, 69, 2, 82, 70, 2, 86, 70, 2, 95, 70, 2, 218, 70, 2,
|
||||
250, 70, 2, 72, 71, 2, 76, 71, 2, 123, 71, 2, 167, 71, 2, 208, 71, 2, 243,
|
||||
71, 2, 91, 72, 2, 119, 72, 2, 207, 72, 2, 210, 72, 2, 216, 72, 2, 94, 73,
|
||||
2, 103, 73, 2, 112, 73, 2, 120, 73, 2, 133, 73, 2, 159, 73, 2, 32, 74, 2,
|
||||
69, 74, 2, 73, 74, 2, 122, 74, 2, 156, 74, 2, 195, 74, 2, 236, 74, 2, 239,
|
||||
74, 2, 68, 75, 2, 90, 75, 2, 98, 75, 2, 101, 75, 2, 132, 75, 2, 154, 75, 2,
|
||||
219, 75, 2, 75, 76, 2, 96, 76, 2, 153, 76, 2, 242, 76, 2, 100, 77, 2, 104,
|
||||
77, 2, 124, 77, 2, 126, 77, 2, 128, 77, 2, 246, 77, 2, 71, 78, 2, 81, 78,
|
||||
2, 102, 78, 2, 244, 78, 2, 70, 79, 2, 74, 79, 2, 77, 79, 2, 97, 79, 2, 107,
|
||||
79, 2, 155, 79, 2, 165, 79, 2, 84, 80, 2, 114, 80, 2, 125, 80, 2, 163, 80,
|
||||
2, 213, 80, 2, 248, 80, 2, 80, 81, 2, 85, 81, 2, 89, 81, 2, 249, 81, 2, 87,
|
||||
82, 2, 245, 82, 2, 238, 83, 2, 247, 83, 2, 45, 92, 2, 49, 92, 2, 51, 95, 2,
|
||||
40, 96, 2, 41, 96, 2, 48, 97, 2, 56, 97, 2, 52, 98, 2, 50, 99, 2, 37, 100,
|
||||
2, 57, 101, 2, 55, 103, 2, 43, 104, 2, 58, 105, 2, 44, 106, 2, 46, 106, 2,
|
||||
53, 106, 2, 47, 107, 2, 54, 107, 2, 61, 111, 2, 42, 112, 2, 35, 119, 2, 63,
|
||||
119, 2, 34, 128, 2, 0, 135, 2, 1, 135, 2, 2, 135, 2, 3, 135, 2, 4, 135, 2,
|
||||
5, 135, 2, 6, 135, 2, 7, 135, 2, 8, 135, 2, 9, 135, 2, 11, 135, 2, 12, 135,
|
||||
2, 13, 135, 2, 14, 135, 2, 15, 135, 2, 16, 135, 2, 17, 135, 2, 18, 135, 2,
|
||||
19, 135, 2, 20, 135, 2, 21, 135, 2, 22, 135, 2, 23, 135, 2, 24, 135, 2, 25,
|
||||
135, 2, 26, 135, 2, 27, 135, 2, 28, 135, 2, 29, 135, 2, 30, 135, 2, 31,
|
||||
135, 2, 33, 135, 2, 36, 135, 2, 38, 135, 2, 39, 135, 2, 59, 135, 2, 60,
|
||||
135, 2, 62, 135, 2, 127, 135, 2, 253, 135, 2, 254, 135, 2, 255, 135, 3,
|
||||
227, 14, 3, 129, 17, 3, 130, 27, 3, 128, 36, 3, 229, 36, 3, 139, 38, 3,
|
||||
188, 39, 3, 137, 40, 3, 230, 40, 3, 239, 40, 3, 136, 41, 3, 132, 42, 3,
|
||||
140, 42, 3, 174, 42, 3, 228, 42, 3, 166, 44, 3, 231, 44, 3, 232, 44, 3,
|
||||
147, 45, 3, 168, 45, 3, 170, 45, 3, 186, 45, 3, 151, 46, 3, 159, 46, 3,
|
||||
171, 46, 3, 134, 47, 3, 141, 47, 3, 175, 47, 3, 233, 47, 3, 143, 48, 3,
|
||||
163, 48, 3, 167, 48, 3, 184, 48, 3, 138, 49, 3, 146, 49, 3, 190, 49, 3,
|
||||
153, 50, 3, 131, 51, 3, 149, 51, 3, 157, 51, 3, 160, 51, 3, 145, 52, 3,
|
||||
155, 52, 3, 144, 53, 3, 161, 53, 3, 173, 53, 3, 176, 53, 3, 187, 53, 3,
|
||||
135, 54, 3, 164, 54, 3, 165, 54, 3, 169, 54, 3, 133, 55, 3, 148, 56, 3,
|
||||
150, 56, 3, 156, 57, 3, 179, 57, 3, 189, 57, 3, 191, 57, 3, 152, 58, 3,
|
||||
154, 58, 3, 185, 59, 3, 10, 61, 3, 172, 61, 3, 177, 61, 3, 180, 61, 3, 182,
|
||||
62, 3, 183, 62, 3, 162, 63, 3, 178, 63, 3, 181, 63, 3, 142, 64, 3, 158, 65,
|
||||
3, 226, 68, 3, 32, 78, 3, 111, 94, 3, 105, 95, 3, 45, 96, 3, 49, 96, 3,
|
||||
114, 97, 3, 97, 98, 3, 116, 98, 3, 51, 99, 3, 101, 99, 3, 110, 99, 3, 40,
|
||||
100, 3, 41, 100, 3, 48, 101, 3, 56, 101, 3, 103, 101, 3, 52, 102, 3, 50,
|
||||
103, 3, 108, 103, 3, 115, 103, 3, 37, 104, 3, 67, 104, 3, 80, 104, 3, 57,
|
||||
105, 3, 109, 105, 3, 55, 107, 3, 69, 107, 3, 99, 107, 3, 43, 108, 3, 100,
|
||||
108, 3, 58, 109, 3, 112, 109, 3, 44, 110, 3, 46, 110, 3, 53, 110, 3, 77,
|
||||
110, 3, 47, 111, 3, 54, 111, 3, 68, 112, 3, 104, 112, 3, 117, 112, 3, 83,
|
||||
113, 3, 73, 114, 3, 61, 115, 3, 76, 115, 3, 78, 115, 3, 79, 115, 3, 42,
|
||||
116, 3, 65, 116, 3, 84, 116, 3, 71, 117, 3, 102, 117, 3, 119, 117, 3, 66,
|
||||
118, 3, 82, 118, 3, 206, 118, 3, 122, 121, 3, 35, 123, 3, 89, 123, 3, 72,
|
||||
125, 3, 92, 125, 3, 74, 128, 3, 85, 128, 3, 88, 128, 3, 106, 128, 3, 107,
|
||||
128, 3, 121, 128, 3, 34, 132, 3, 90, 132, 3, 91, 132, 3, 93, 132, 3, 98,
|
||||
132, 3, 118, 132, 3, 195, 132, 3, 0, 139, 3, 1, 139, 3, 2, 139, 3, 3, 139,
|
||||
3, 4, 139, 3, 5, 139, 3, 6, 139, 3, 7, 139, 3, 8, 139, 3, 9, 139, 3, 11,
|
||||
139, 3, 12, 139, 3, 13, 139, 3, 14, 139, 3, 15, 139, 3, 16, 139, 3, 17,
|
||||
139, 3, 18, 139, 3, 19, 139, 3, 20, 139, 3, 21, 139, 3, 22, 139, 3, 23,
|
||||
139, 3, 24, 139, 3, 25, 139, 3, 26, 139, 3, 27, 139, 3, 28, 139, 3, 29,
|
||||
139, 3, 30, 139, 3, 31, 139, 3, 33, 139, 3, 36, 139, 3, 38, 139, 3, 39,
|
||||
139, 3, 59, 139, 3, 60, 139, 3, 62, 139, 3, 63, 139, 3, 64, 139, 3, 70,
|
||||
139, 3, 75, 139, 3, 81, 139, 3, 86, 139, 3, 87, 139, 3, 94, 139, 3, 95,
|
||||
139, 3, 96, 139, 3, 113, 139, 3, 120, 139, 3, 123, 139, 3, 124, 139, 3,
|
||||
125, 139, 3, 126, 139, 3, 127, 139, 3, 192, 139, 3, 193, 139, 3, 194, 139,
|
||||
3, 196, 139, 3, 197, 139, 3, 198, 139, 3, 199, 139, 3, 200, 139, 3, 201,
|
||||
139, 3, 202, 139, 3, 203, 139, 3, 204, 139, 3, 205, 139, 3, 207, 139, 3,
|
||||
208, 139, 3, 209, 139, 3, 210, 139, 3, 211, 139, 3, 212, 139, 3, 213, 139,
|
||||
3, 214, 139, 3, 215, 139, 3, 216, 139, 3, 217, 139, 3, 218, 139, 3, 219,
|
||||
139, 3, 220, 139, 3, 221, 139, 3, 222, 139, 3, 223, 139, 3, 224, 139, 3,
|
||||
225, 139, 3, 234, 139, 3, 235, 139, 3, 236, 139, 3, 237, 139, 3, 238, 139,
|
||||
3, 240, 139, 3, 241, 139, 3, 242, 139, 3, 243, 139, 3, 244, 139, 3, 245,
|
||||
139, 3, 246, 139, 3, 247, 139, 3, 248, 139, 3, 249, 139, 3, 250, 139, 3,
|
||||
251, 139, 3, 252, 139, 3, 253, 139, 3, 254, 139, 3, 255, 139, 4, 0, 1000,
|
||||
4, 1, 1000, 4, 2, 1000, 4, 3, 1000, 4, 4, 1000, 4, 5, 1000, 4, 6, 1000, 4,
|
||||
7, 1000, 4, 8, 1000, 4, 9, 1000, 4, 10, 1000, 4, 11, 1000, 4, 12, 1000, 4,
|
||||
13, 1000, 4, 14, 1000, 4, 15, 1000, 4, 16, 1000, 4, 17, 1000, 4, 18, 1000,
|
||||
4, 19, 1000, 4, 20, 1000, 4, 21, 1000, 4, 22, 1000, 4, 23, 1000, 4, 24,
|
||||
1000, 4, 25, 1000, 4, 26, 1000, 4, 27, 1000, 4, 28, 1000, 4, 29, 1000, 4,
|
||||
30, 1000, 4, 31, 1000, 4, 32, 1000, 4, 33, 1000, 4, 34, 1000, 4, 35, 1000,
|
||||
4, 36, 1000, 4, 37, 1000, 4, 38, 1000, 4, 39, 1000, 4, 40, 1000, 4, 41,
|
||||
1000, 4, 42, 1000, 4, 43, 1000, 4, 44, 1000, 4, 45, 1000, 4, 46, 1000, 4,
|
||||
47, 1000, 4, 48, 1000, 4, 49, 1000, 4, 50, 1000, 4, 51, 1000, 4, 52, 1000,
|
||||
4, 53, 1000, 4, 54, 1000, 4, 55, 1000, 4, 56, 1000, 4, 57, 1000, 4, 58,
|
||||
1000, 4, 59, 1000, 4, 60, 1000, 4, 61, 1000, 4, 62, 1000, 4, 63, 1000, 4,
|
||||
64, 1000, 4, 65, 1000, 4, 66, 1000, 4, 67, 1000, 4, 68, 1000, 4, 69, 1000,
|
||||
4, 70, 1000, 4, 71, 1000, 4, 72, 1000, 4, 73, 1000, 4, 74, 1000, 4, 75,
|
||||
1000, 4, 76, 1000, 4, 77, 1000, 4, 78, 1000, 4, 79, 1000, 4, 80, 1000, 4,
|
||||
81, 1000, 4, 82, 1000, 4, 83, 1000, 4, 84, 1000, 4, 85, 1000, 4, 86, 1000,
|
||||
4, 87, 1000, 4, 88, 1000, 4, 89, 1000, 4, 90, 1000, 4, 91, 1000, 4, 92,
|
||||
1000, 4, 93, 1000, 4, 94, 1000, 4, 95, 1000, 4, 96, 1000, 4, 97, 1000, 4,
|
||||
98, 1000, 4, 99, 1000, 4, 100, 1000, 4, 101, 1000, 4, 102, 1000, 4, 103,
|
||||
1000, 4, 104, 1000, 4, 105, 1000, 4, 106, 1000, 4, 107, 1000, 4, 108, 1000,
|
||||
4, 109, 1000, 4, 110, 1000, 4, 111, 1000, 4, 112, 1000, 4, 113, 1000, 4,
|
||||
114, 1000, 4, 115, 1000, 4, 116, 1000, 4, 117, 1000, 4, 118, 1000, 4, 119,
|
||||
1000, 4, 120, 1000, 4, 121, 1000, 4, 122, 1000, 4, 123, 1000, 4, 124, 1000,
|
||||
4, 125, 1000, 4, 126, 1000, 4, 127, 1000, 4, 128, 1000, 4, 129, 1000, 4,
|
||||
130, 1000, 4, 131, 1000, 4, 132, 1000, 4, 133, 1000, 4, 134, 1000, 4, 135,
|
||||
1000, 4, 136, 1000, 4, 137, 1000, 4, 138, 1000, 4, 139, 1000, 4, 140, 1000,
|
||||
4, 141, 1000, 4, 142, 1000, 4, 143, 1000, 4, 144, 1000, 4, 145, 1000, 4,
|
||||
146, 1000, 4, 147, 1000, 4, 148, 1000, 4, 149, 1000, 4, 150, 1000, 4, 151,
|
||||
1000, 4, 152, 1000, 4, 153, 1000, 4, 154, 1000, 4, 155, 1000, 4, 156, 1000,
|
||||
4, 157, 1000, 4, 158, 1000, 4, 159, 1000, 4, 160, 1000, 4, 161, 1000, 4,
|
||||
162, 1000, 4, 163, 1000, 4, 164, 1000, 4, 165, 1000, 4, 166, 1000, 4, 167,
|
||||
1000, 4, 168, 1000, 4, 169, 1000, 4, 170, 1000, 4, 171, 1000, 4, 172, 1000,
|
||||
4, 173, 1000, 4, 174, 1000, 4, 175, 1000, 4, 176, 1000, 4, 177, 1000, 4,
|
||||
178, 1000, 4, 179, 1000, 4, 180, 1000, 4, 181, 1000, 4, 182, 1000, 4, 183,
|
||||
1000, 4, 184, 1000, 4, 185, 1000, 4, 186, 1000, 4, 187, 1000, 4, 188, 1000,
|
||||
4, 189, 1000, 4, 190, 1000, 4, 191, 1000, 4, 192, 1000, 4, 193, 1000, 4,
|
||||
194, 1000, 4, 195, 1000, 4, 196, 1000, 4, 197, 1000, 4, 198, 1000, 4, 199,
|
||||
1000, 4, 200, 1000, 4, 201, 1000, 4, 202, 1000, 4, 203, 1000, 4, 204, 1000,
|
||||
4, 205, 1000, 4, 206, 1000, 4, 207, 1000, 4, 208, 1000, 4, 209, 1000, 4,
|
||||
210, 1000, 4, 211, 1000, 4, 212, 1000, 4, 213, 1000, 4, 214, 1000, 4, 215,
|
||||
1000, 4, 216, 1000, 4, 217, 1000, 4, 218, 1000, 4, 219, 1000, 4, 220, 1000,
|
||||
4, 221, 1000, 4, 222, 1000, 4, 223, 1000, 4, 224, 1000, 4, 225, 1000, 4,
|
||||
226, 1000, 4, 227, 1000, 4, 228, 1000, 4, 229, 1000, 4, 230, 1000, 4, 231,
|
||||
1000, 4, 232, 1000, 4, 233, 1000, 4, 234, 1000, 4, 235, 1000, 4, 236, 1000,
|
||||
4, 237, 1000, 4, 238, 1000, 4, 239, 1000, 4, 240, 1000, 4, 241, 1000, 4,
|
||||
242, 1000, 4, 243, 1000, 4, 244, 1000, 4, 245, 1000, 4, 246, 1000, 4, 247,
|
||||
1000, 4, 248, 1000, 4, 249, 1000, 4, 250, 1000, 4, 251, 1000, 4, 252, 1000,
|
||||
4, 253, 1000, 4, 254, 1000, 4, 255, 1000]));
|
||||
|
||||
predicate link_vars(var int: encoding_i, var int: byte_status_i,
|
||||
var int: char_start_i) =
|
||||
table_int([encoding_i, byte_status_i, char_start_i], array2d(1..14,
|
||||
index_set([encoding_i, byte_status_i, char_start_i]), [0, 0, 1, 1, 1, 1, 1,
|
||||
2, 0, 2, 3, 1, 2, 4, 1, 2, 5, 0, 3, 7, 0, 3, 8, 1, 3, 9, 0, 3, 10, 0, 3,
|
||||
12, 0, 3, 13, 0, 3, 14, 0, 4, 15, 1]));
|
||||
|
||||
predicate link_statuses(var int: byte_status_i, var int: byte_status_im1) =
|
||||
table_int([byte_status_i, byte_status_im1], array2d(1..54,
|
||||
index_set([byte_status_i, byte_status_im1]), [0, 0, 0, 2, 0, 3, 0, 5, 0, 7,
|
||||
0, 10, 0, 14, 0, 15, 1, 0, 1, 2, 1, 3, 1, 5, 1, 7, 1, 10, 1, 14, 1, 15, 2,
|
||||
1, 3, 0, 3, 2, 3, 3, 3, 5, 3, 7, 3, 10, 3, 14, 3, 15, 4, 0, 4, 2, 4, 3, 4,
|
||||
5, 4, 7, 4, 10, 4, 14, 4, 15, 5, 4, 8, 0, 8, 2, 8, 3, 8, 5, 8, 7, 8, 10, 8,
|
||||
14, 8, 15, 9, 8, 10, 9, 13, 12, 14, 13, 15, 0, 15, 2, 15, 3, 15, 5, 15, 7,
|
||||
15, 10, 15, 14, 15, 15]));
|
||||
|
1689
jp-encoding/table/data1000.mzn
Normal file
1689
jp-encoding/table/data1000.mzn
Normal file
File diff suppressed because it is too large
Load Diff
2444
jp-encoding/table/data1700.mzn
Normal file
2444
jp-encoding/table/data1700.mzn
Normal file
File diff suppressed because it is too large
Load Diff
1273
jp-encoding/table/data400.mzn
Normal file
1273
jp-encoding/table/data400.mzn
Normal file
File diff suppressed because it is too large
Load Diff
1498
jp-encoding/table/data800.mzn
Normal file
1498
jp-encoding/table/data800.mzn
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user