PermLib
|
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 TEST_COMMON_H_ 00034 #define TEST_COMMON_H_ 00035 00036 #include <list> 00037 #include <boost/shared_ptr.hpp> 00038 00039 #include <permlib/common.h> 00040 #include <permlib/bsgs.h> 00041 #include <permlib/construct/schreier_sims_construction.h> 00042 #include <permlib/construct/random_schreier_sims_construction.h> 00043 #include <permlib/construct/cyclic_group_construction.h> 00044 #include <permlib/generator/product_replacement_generator.h> 00045 00046 #include <iostream> 00047 #include <fstream> 00048 00049 #include "group_data.h" 00050 00051 namespace permlib { namespace test { 00052 00053 template<class PERM,class TRANS> 00054 struct Constructor { 00055 typedef PERM PERMtype; 00056 typedef TRANS TRANStype; 00057 }; 00058 00059 template<class PERM,class TRANS> 00060 struct ConstructDeterministic1 : public Constructor<PERM,TRANS> { 00061 BSGS<PERM, TRANS> operator()(const GroupInformation& info) { 00062 std::list<typename PERM::ptr> groupGenerators; 00063 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators); 00064 BOOST_REQUIRE_GT(n, 0); 00065 00066 SchreierSimsConstruction<PERM, TRANS> ssc(n); 00067 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end()); 00068 00069 return bsgs; 00070 } 00071 }; 00072 00073 template<class PERM,class TRANS> 00074 struct ConstructDeterministic2 : public Constructor<PERM,TRANS> { 00075 BSGS<PERM, TRANS> operator()(const GroupInformation& info) { 00076 std::list<typename PERM::ptr> groupGenerators; 00077 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators); 00078 BOOST_REQUIRE_GT(n, 0); 00079 00080 SchreierSimsConstruction<PERM, TRANS> ssc(n); 00081 BSGS<PERM, TRANS> bsgs(n); 00082 bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end()); 00083 00084 return bsgs; 00085 } 00086 }; 00087 00088 template<class PERM,class TRANS> 00089 struct ConstructRandomized : public Constructor<PERM,TRANS> { 00090 BSGS<PERM, TRANS> operator()(const GroupInformation& info) { 00091 std::list<typename PERM::ptr> groupGenerators; 00092 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators); 00093 BOOST_REQUIRE_GT(n, 0); 00094 00095 ProductReplacementGenerator<PERM> rng(n, groupGenerators.begin(), groupGenerators.end()); 00096 RandomSchreierSimsConstruction<PERM, TRANS> ssc(n, &rng, info.order); 00097 bool result = false; 00098 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end(), result); 00099 BOOST_REQUIRE(result); 00100 00101 return bsgs; 00102 } 00103 }; 00104 00105 template<class PERM,class TRANS> 00106 BSGS<PERM, TRANS> construct(const GroupInformation& info) { 00107 return ConstructDeterministic1<PERM,TRANS>()(info); 00108 } 00109 00110 template<class PERM, class TRANS> 00111 BSGS<PERM, TRANS> constructCyclicGroup(unsigned int n) { 00112 CyclicGroupConstruction<TRANS> cycConstruct(n); 00113 return cycConstruct.construct(); 00114 } 00115 00116 template<class PERM> 00117 void checkImage(const unsigned long* Delta, unsigned long DeltaSize, const unsigned long* Phi, const boost::shared_ptr<PERM> &repr) { 00118 std::list<unsigned long> imgList(Phi, Phi+DeltaSize); 00119 for (unsigned int j = 0; j < DeltaSize; ++j) { 00120 std::list<unsigned long>::iterator it = std::find(imgList.begin(), imgList.end(), *repr / Delta[j]); 00121 BOOST_REQUIRE( it != imgList.end() ); 00122 imgList.erase(it); 00123 } 00124 BOOST_CHECK( imgList.size() == 0 ); 00125 } 00126 00127 } } // end NS 00128 00129 #endif // - TEST_COMMON_H_