PermLib
|
00001 // --------------------------------------------------------------------------- 00002 // 00003 // This file is part of PermLib. 00004 // 00005 // Copyright (c) 2009-2010 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 struct GroupInformation { 00037 std::string filename; 00038 unsigned int n; 00039 unsigned int order; 00040 00041 GroupInformation(const std::string &f, unsigned int _n, unsigned int _order) : filename(f), n(_n), order(_order) {} 00042 }; 00043 00044 const GroupInformation info_psu4_3("../data/G_psu4_3", 820, 3265920); 00045 const GroupInformation info_1997("../data/G_test1997", 13, 13*12*9*4); 00046 const GroupInformation info_e6("../data/G_e6", 36, 51840); 00047 const GroupInformation info_e7("../data/G_e7", 63, 1451520); 00048 const GroupInformation info_e8("../data/G_e8", 120, 348364800); 00049 const GroupInformation info_cyclic500("../data/G_cyclic500", 500, 500); 00050 00051 00052 #include <list> 00053 #include <boost/shared_ptr.hpp> 00054 00055 #include <permlib/common.h> 00056 #include <permlib/bsgs.h> 00057 #include <permlib/construct/schreier_sims_construction.h> 00058 #include <permlib/construct/random_schreier_sims_construction.h> 00059 #include <permlib/generator/product_replacement_generator.h> 00060 00061 template<class PERM> 00062 unsigned int readGroup(const std::string &filename, std::list<typename PERM::ptr> &groupGenerators) { 00063 std::ifstream file; 00064 file.open(filename.c_str()); 00065 if (!file.is_open()) { 00066 std::cerr << "opening " << filename << " failed" << std::endl; 00067 BOOST_REQUIRE(file.is_open()); 00068 return 0; 00069 } 00070 00071 unsigned int n; 00072 file >> n; 00073 00074 std::string line; 00075 while (!file.eof()) { 00076 std::getline(file, line); 00077 if (line.length() < 1) 00078 continue; 00079 boost::shared_ptr<PERM> gen(new PERM(n, line)); 00080 groupGenerators.push_back(gen); 00081 } 00082 file.close(); 00083 00084 return n; 00085 } 00086 00087 using namespace permlib; 00088 00089 template<class PERM,class TRANS> 00090 BSGS<PERM,TRANS> construct(const std::string &filename) { 00091 std::list<typename PERM::ptr> groupGenerators; 00092 const unsigned int n = readGroup<PERM>(filename, groupGenerators); 00093 00094 SchreierSimsConstruction<PERM, TRANS> ssc(n); 00095 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end()); 00096 00097 return bsgs; 00098 } 00099 00100 template<class PERM,class TRANS> 00101 BSGS<PERM,TRANS> construct2(const std::string &filename, unsigned long order) { 00102 std::list<typename PERM::ptr> groupGenerators; 00103 const unsigned int n = readGroup<PERM>(filename, groupGenerators); 00104 00105 ProductReplacementGenerator<PERM> rng(groupGenerators.begin(), groupGenerators.end()); 00106 RandomSchreierSimsConstruction<PERM, TRANS> ssc(n, &rng, order); 00107 bool result = false; 00108 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end(), result); 00109 BOOST_REQUIRE(result); 00110 00111 return bsgs; 00112 } 00113 00114 template<class PERM> 00115 void checkImage(const unsigned long* Delta, unsigned long DeltaSize, const unsigned long* Phi, const boost::shared_ptr<PERM> &repr) { 00116 std::list<unsigned long> imgList(Phi, Phi+DeltaSize); 00117 for (unsigned int j = 0; j < DeltaSize; ++j) { 00118 std::list<unsigned long>::iterator it = std::find(imgList.begin(), imgList.end(), *repr / Delta[j]); 00119 BOOST_REQUIRE( it != imgList.end() ); 00120 imgList.erase(it); 00121 } 00122 BOOST_CHECK( imgList.size() == 0 ); 00123 } 00124 00125 #endif // - TEST_COMMON_H_