Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
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-05-22 04:21:36 +0200 (Wed, 22 May 2013) $ by $Author: mears $
11  * $Revision: 13653 $
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
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
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>
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>
113  int nrows = m.height();
114  int ncols = m.width();
115 
116  typename Matrix<A>::ArgsType a1;
117  typename Matrix<A>::ArgsType 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  typename Matrix<A>::ArgsType aboth;
127  aboth << a1;
128  aboth << a2;
129  return VariableSequenceSymmetry(aboth, a1.size());
130  }
131 }
132 
133 // STATISTICS: minimodel-any
int height(void) const
Return the height of the matrix.
Definition: matrix.hpp:150
SymmetryHandle columns_interchange(const Matrix< A > &m)
Interchangeable columns symmetry specification.
Definition: ldsb.hpp:55
int width(void) const
Return the width of the matrix.
Definition: matrix.hpp:147
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
A reference-counted pointer to a SymmetryObject.
Definition: int.hh:4263
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Slice< A > row(int r) const
Access row r.
Definition: matrix.hpp:181
ArrayTraits< A >::ArgsType ArgsType
The type of the Args-array type for ValueType values.
Definition: minimodel.hh:2003
SymmetryHandle columns_reflect(const Matrix< A > &m)
Reflect columns symmetry specification.
Definition: ldsb.hpp:89
SymmetryHandle diagonal_reflect(const Matrix< A > &m)
Reflect around main diagonal symmetry specification.
Definition: ldsb.hpp:112
SymmetryHandle rows_interchange(const Matrix< A > &m)
Interchangeable rows symmetry specification.
Definition: ldsb.hpp:44
Matrix-interface for arrays.
Definition: minimodel.hh:1924
SymmetryHandle VariableSequenceSymmetry(const IntVarArgs &vars, int ss)
Variable sequences in x of size ss are interchangeable.
Definition: ldsb.cpp:94
Gecode toplevel namespace
Slice< A > col(int c) const
Access column c.
Definition: matrix.hpp:187
SymmetryHandle rows_reflect(const Matrix< A > &m)
Reflect rows symmetry specification.
Definition: ldsb.hpp:66