Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode {
35
38 template<class A>
41 typename Matrix<A>::ArgsType xs;
42 for (int r = 0 ; r < m.height() ; r++)
43 xs << m.row(r);
44 return VariableSequenceSymmetry(xs, m.width());
45 }
46
49 template<class A>
52 typename Matrix<A>::ArgsType xs;
53 for (int c = 0 ; c < m.width() ; c++)
54 xs << m.col(c);
55 return VariableSequenceSymmetry(xs, m.height());
56 }
57
60 template<class A>
63 int nrows = m.height();
64 int ncols = m.width();
65 // Length of each sequence in the symmetry.
66 int length = (nrows/2) * ncols;
67 typename Matrix<A>::ArgsType xs(length * 2);
68 for (int i = 0 ; i < length ; i++) {
69 // Break position i into its coordinates
70 int r1 = i/ncols;
71 int c1 = i%ncols;
72 // r2 is the row symmetric with r1
73 int r2 = nrows - r1 - 1;
74 // The column remains the same
75 int c2 = c1;
76 xs[i] = m(c1,r1);
77 xs[length+i] = m(c2,r2);
78 }
79 return VariableSequenceSymmetry(xs, length);
80 }
81
84 template<class A>
86 int nrows = m.height();
87 int ncols = m.width();
88 // Length of each sequence in the symmetry.
89 int length = (ncols/2) * nrows;
90 typename Matrix<A>::ArgsType xs(length * 2);
91 for (int i = 0 ; i < length ; i++) {
92 // Break position i into its coordinates
93 int r1 = i/ncols;
94 int c1 = i%ncols;
95 // c2 is the column symmetric with c1
96 int c2 = ncols - c1 - 1;
97 // The row remains the same
98 int r2 = r1;
99 xs[i] = m(c1,r1);
100 xs[length+i] = m(c2,r2);
101 }
102 return VariableSequenceSymmetry(xs, length);
103 }
104
107 template<class A>
109 int nrows = m.height();
110 int ncols = m.width();
111
112 typename Matrix<A>::ArgsType a1;
113 typename Matrix<A>::ArgsType a2;
114
115 for (int i = 0 ; i < nrows ; i++) {
116 for (int j = i+1 ; j < ncols ; j++) {
117 a1 << m(j,i);
118 a2 << m(i,j);
119 }
120 }
121
122 typename Matrix<A>::ArgsType aboth;
123 aboth << a1;
124 aboth << a2;
125 return VariableSequenceSymmetry(aboth, a1.size());
126 }
127}
128
129// STATISTICS: minimodel-any
int width(void) const
Return the width of the matrix.
Definition matrix.hpp:143
Slice< A > col(int c) const
Access column c.
Definition matrix.hpp:183
Slice< A > row(int r) const
Access row r.
Definition matrix.hpp:177
Matrix(A a, int w, int h)
Basic constructor.
Definition matrix.hpp:127
ArrayTraits< A >::ArgsType ArgsType
The type of the Args-array type for ValueType values.
int height(void) const
Return the height of the matrix.
Definition matrix.hpp:146
A reference-counted pointer to a SymmetryObject.
Definition int.hh:5270
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
SymmetryHandle rows_reflect(const Matrix< A > &m)
Reflect rows symmetry specification.
Definition ldsb.hpp:62
SymmetryHandle columns_reflect(const Matrix< A > &m)
Reflect columns symmetry specification.
Definition ldsb.hpp:85
SymmetryHandle rows_interchange(const Matrix< A > &m)
Interchangeable rows symmetry specification.
Definition ldsb.hpp:40
SymmetryHandle VariableSequenceSymmetry(const IntVarArgs &x, int ss)
Variable sequences in x of size ss are interchangeable.
Definition ldsb.cpp:90
SymmetryHandle diagonal_reflect(const Matrix< A > &m)
Reflect around main diagonal symmetry specification.
Definition ldsb.hpp:108
SymmetryHandle columns_interchange(const Matrix< A > &m)
Interchangeable columns symmetry specification.
Definition ldsb.hpp:51