permlib  0.2.6
Library for permutation computations
 All Classes Functions Variables Typedefs Enumerations Friends
include/permlib/redundant_base_point_insertion_strategy.h
00001 // ---------------------------------------------------------------------------
00002 //
00003 //  This file is part of PermLib.
00004 //
00005 // Copyright (c) 2009-2011 Thomas Rehn <thomas@carmen76.de>
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions
00010 // are met:
00011 // 1. Redistributions of source code must retain the above copyright
00012 //    notice, this list of conditions and the following disclaimer.
00013 // 2. Redistributions in binary form must reproduce the above copyright
00014 //    notice, this list of conditions and the following disclaimer in the
00015 //    documentation and/or other materials provided with the distribution.
00016 // 3. The name of the author may not be used to endorse or promote products
00017 //    derived from this software without specific prior written permission.
00018 // 
00019 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00020 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00021 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00022 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00024 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00028 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // ---------------------------------------------------------------------------
00031 
00032 
00033 #ifndef REDUNDANT_BASE_POINT_INSERTION_STRATEGY_H_
00034 #define REDUNDANT_BASE_POINT_INSERTION_STRATEGY_H_
00035 
00036 namespace permlib {
00037 
00038 template <class PERM, class TRANS>
00039 struct BSGS;
00040 
00042 template <class PERM, class TRANS>
00043 class RedundantBasePointInsertionStrategy {
00044 public:
00046 
00049         RedundantBasePointInsertionStrategy(const BSGS<PERM,TRANS> &bsgs) : m_bsgs(bsgs) {}
00050 
00051         // virtual destructor
00052         virtual ~RedundantBasePointInsertionStrategy() {}
00053         
00055 
00060         virtual int findInsertionPoint(dom_int beta, std::list<typename PERM::ptr> &S_i) const = 0;
00061 protected:
00063         const BSGS<PERM,TRANS> &m_bsgs;
00064 };
00065 
00067 template <class PERM, class TRANS>
00068 class TrivialRedundantBasePointInsertionStrategy : public RedundantBasePointInsertionStrategy<PERM,TRANS> {
00069 public:
00071         TrivialRedundantBasePointInsertionStrategy(const BSGS<PERM,TRANS> &bsgs) : RedundantBasePointInsertionStrategy<PERM,TRANS>(bsgs) {}
00072         
00073         virtual int findInsertionPoint(dom_int beta, std::list<typename PERM::ptr> &S_i) const {
00074                 const std::vector<dom_int> &B = RedundantBasePointInsertionStrategy<PERM,TRANS>::m_bsgs.B;
00075                 const std::vector<TRANS> &U = RedundantBasePointInsertionStrategy<PERM,TRANS>::m_bsgs.U;
00076                 for (unsigned int i=0; i<B.size(); ++i) {
00077                         if (beta == B[i])
00078                                 return -i-1;
00079                 }
00080                 int pos = B.size();
00081                 while (pos > 0 && U[pos-1].size() == 1)
00082                         --pos;
00083                 return pos;
00084         }
00085 };
00086 
00088 template <class PERM, class TRANS>
00089 class FirstRedundantBasePointInsertionStrategy : public RedundantBasePointInsertionStrategy<PERM,TRANS> {
00090 public:
00092         FirstRedundantBasePointInsertionStrategy(const BSGS<PERM,TRANS> &bsgs) : RedundantBasePointInsertionStrategy<PERM,TRANS>(bsgs) {}
00093         
00094         virtual int findInsertionPoint(dom_int beta, std::list<typename PERM::ptr> &S_i) const {
00095                 const std::vector<dom_int> &B = RedundantBasePointInsertionStrategy<PERM,TRANS>::m_bsgs.B;
00096                 const std::list<typename PERM::ptr> &S = RedundantBasePointInsertionStrategy<PERM,TRANS>::m_bsgs.S;
00097                 typename std::vector<dom_int>::const_iterator bIt = B.begin();
00098                 int pos = B.size();
00099                 for (unsigned int i=0; i<B.size(); ++i) {
00100                         if (beta == B[i])
00101                                 return -i-1;
00102                         
00103                         ++bIt;
00104                         const PointwiseStabilizerPredicate<PERM> stab_i(B.begin(), bIt);
00105                         S_i.clear();
00106 
00107                         //TODO: don't create temporary copy
00108                         //      place directly into predicate
00109                         std::copy_if(S.begin(), S.end(), std::back_inserter(S_i), stab_i);
00110 
00111                         StabilizesPointPredicate<PERM> stab_beta(S_i.begin(), S_i.end());
00112                         if (stab_beta(beta)) {
00113                                 pos = i+1;
00114                                 break;
00115                         }
00116                 }
00117                 return pos;
00118         }
00119 };
00120 
00121 }
00122 
00123 #endif // -- REDUNDANT_BASE_POINT_INSERTION_STRATEGY_H_