main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:40 for Gecode by
doxygen
1.8.3.1
gecode
minimodel
ldsb.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <chris.mears@monash.edu>
5
*
6
* Copyright:
7
* Christopher Mears, 2012
8
*
9
* Last modified:
10
* $Date: 2013-03-07 17:39:13 +0100 (Thu, 07 Mar 2013) $ by $Author: schulte $
11
* $Revision: 13458 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
namespace
Gecode {
39
42
template
<
class
A>
43
SymmetryHandle
44
rows_interchange
(
const
Matrix<A>
& m) {
45
typename
Matrix<A>::ArgsType
xs;
46
for
(
int
r
= 0 ;
r
< m.
height
() ;
r
++)
47
xs << m.
row
(
r
);
48
return
VariableSequenceSymmetry
(xs, m.
width
());
49
}
50
53
template
<
class
A>
54
SymmetryHandle
55
columns_interchange
(
const
Matrix<A>
& m) {
56
typename
Matrix<A>::ArgsType
xs;
57
for
(
int
c
= 0 ;
c
< m.
width
() ;
c
++)
58
xs << m.
col
(
c
);
59
return
VariableSequenceSymmetry
(xs, m.
height
());
60
}
61
64
template
<
class
A>
65
SymmetryHandle
66
rows_reflect
(
const
Matrix<A>
& m) {
67
int
nrows = m.
height
();
68
int
ncols = m.
width
();
69
// Length of each sequence in the symmetry.
70
int
length = (nrows/2) * ncols;
71
typename
Matrix<A>::ArgsType
xs(length * 2);
72
for
(
int
i
= 0 ;
i
< length ;
i
++) {
73
// Break position i into its coordinates
74
int
r1 =
i
/ncols;
75
int
c1 =
i
%ncols;
76
// r2 is the row symmetric with r1
77
int
r2 = nrows - r1 - 1;
78
// The column remains the same
79
int
c2 = c1;
80
xs[
i
] = m(c1,r1);
81
xs[length+
i
] = m(c2,r2);
82
}
83
return
VariableSequenceSymmetry
(xs, length);
84
}
85
88
template
<
class
A>
89
SymmetryHandle
columns_reflect
(
const
Matrix<A>
& m) {
90
int
nrows = m.
height
();
91
int
ncols = m.
width
();
92
// Length of each sequence in the symmetry.
93
int
length = (ncols/2) * nrows;
94
typename
Matrix<A>::ArgsType
xs(length * 2);
95
for
(
int
i
= 0 ;
i
< length ;
i
++) {
96
// Break position i into its coordinates
97
int
r1 =
i
/ncols;
98
int
c1 =
i
%ncols;
99
// c2 is the column symmetric with c1
100
int
c2 = ncols - c1 - 1;
101
// The row remains the same
102
int
r2 = r1;
103
xs[
i
] = m(c1,r1);
104
xs[length+
i
] = m(c2,r2);
105
}
106
return
VariableSequenceSymmetry
(xs, length);
107
}
108
111
template
<
class
A>
112
SymmetryHandle
diagonal_reflect
(
const
Matrix<A>
& m) {
113
int
nrows = m.
height
();
114
int
ncols = m.
width
();
115
116
IntVarArgs
a1;
117
IntVarArgs
a2;
118
119
for
(
int
i
= 0 ;
i
< nrows ;
i
++) {
120
for
(
int
j =
i
+1 ; j < ncols ; j++) {
121
a1 << m(j,
i
);
122
a2 << m(
i
,j);
123
}
124
}
125
126
IntVarArgs
aboth;
127
aboth << a1;
128
aboth << a2;
129
return
VariableSequenceSymmetry
(aboth, a1.
size
());
130
}
131
}
132
133
// STATISTICS: minimodel-any