permlib  0.2.9
Library for permutation computations
matrix_refinement1.h
1 // ---------------------------------------------------------------------------
2 //
3 // This file is part of PermLib.
4 //
5 // Copyright (c) 2009-2011 Thomas Rehn <thomas@carmen76.de>
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 // 1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // 3. The name of the author may not be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 
32 
33 #ifndef MATRIXREFINEMENT1_H_
34 #define MATRIXREFINEMENT1_H_
35 
36 #include <permlib/predicate/pointwise_stabilizer_predicate.h>
37 #include <permlib/search/partition/refinement.h>
38 
39 namespace permlib {
40 namespace partition {
41 
43 
47 template<class PERM,class MATRIX>
48 class MatrixRefinement1 : public Refinement<PERM> {
49 public:
51  explicit MatrixRefinement1(unsigned long n, const MATRIX& matrix);
52 
53  virtual unsigned int apply(Partition& pi) const;
54 
55  virtual bool init(Partition& pi);
56 
57 private:
58  const MATRIX& m_matrix;
59  std::vector<std::list<unsigned long> > m_diagonalPartition;
60 };
61 
62 template<class PERM,class MATRIX>
63 MatrixRefinement1<PERM,MATRIX>::MatrixRefinement1(unsigned long n, const MATRIX& matrix)
64  : Refinement<PERM>(n, Default), m_matrix(matrix)
65 {
66 }
67 
68 template<class PERM,class MATRIX>
70  BOOST_ASSERT( this->initialized() );
71 
72  unsigned int ret = 0;
73  std::list<int>::const_iterator cellPairIt = Refinement<PERM>::m_cellPairs.begin();
74  while (cellPairIt != Refinement<PERM>::m_cellPairs.end()) {
75  unsigned long cell = *cellPairIt;
76  ++cellPairIt;
77  while (cellPairIt != Refinement<PERM>::m_cellPairs.end() && *cellPairIt != -1) {
78  unsigned long diagIndex = *cellPairIt;
79  if (pi.intersect(m_diagonalPartition[diagIndex].begin(), m_diagonalPartition[diagIndex].end(), cell))
80  ++ret;
81  ++cellPairIt;
82  }
83  ++cellPairIt;
84  }
85  return ret;
86 }
87 
88 
89 template<class PERM,class MATRIX>
91  m_diagonalPartition.resize(m_matrix.k());
92  for (unsigned long i = 0; i < m_matrix.dimension(); ++i) {
93  m_diagonalPartition[m_matrix.at(i,i)].push_back(i);
94  }
95 
96  bool foundIntersection = false;
97  for (unsigned int c = 0; c < pi.cells(); ++c) {
98  Refinement<PERM>::m_cellPairs.push_back(c);
99  for (unsigned long i = 0; i < m_diagonalPartition.size(); ++i) {
100  if (pi.intersect(m_diagonalPartition[i].begin(), m_diagonalPartition[i].end(), c)) {
101  Refinement<PERM>::m_cellPairs.push_back(i);
102  foundIntersection = true;
103  }
104  }
105  Refinement<PERM>::m_cellPairs.push_back(-1);
106  }
107  if (foundIntersection) {
108  typename Refinement<PERM>::RefinementPtr ref(new MatrixRefinement1<PERM,MATRIX>(*this));
110  return true;
111  }
112  return false;
113 }
114 
115 
116 }
117 }
118 
119 #endif // -- MATRIXREFINEMENT1_H_
virtual unsigned int apply(Partition &pi) const
applies (left-)refinement to pi which is the original partition this refinement was initialized to ...
Definition: matrix_refinement1.h:69
base class for a -refinement which is used in an R-base and bound to an initial partition ...
Definition: refinement.h:53
partition
Definition: partition.h:48
MatrixRefinement1(unsigned long n, const MATRIX &matrix)
constructor
Definition: matrix_refinement1.h:63
unsigned long cells() const
number of cells in this partition
Definition: partition.h:157
virtual bool init(Partition &pi)
initializes refinement
Definition: matrix_refinement1.h:90
bool intersect(ForwardIterator begin, ForwardIterator end, unsigned int j)
intersects the j-th cell of this partition with a given set
Definition: partition.h:186
concrete -refinement for symmetric matrix automorphisms
Definition: matrix_refinement1.h:48
Definition: abstract_bsgs.h:49