PermLib

test-common.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 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 namespace permlib { namespace test {
00050 
00051 struct GroupInformation {
00052     std::string filename;
00053     unsigned int n;
00054     unsigned int order;
00055     
00056     GroupInformation(const std::string &f, unsigned int _n, unsigned int _order) : filename(f), n(_n), order(_order) {}
00057 };
00058 
00059 const GroupInformation info_trivial("../data/G_trivial42", 42, 1);
00060 const GroupInformation info_test33("../data/G_test33", 33, 163680);
00061 const GroupInformation info_psu4_3("../data/G_psu4_3", 820, 3265920);
00062 const GroupInformation info_1997("../data/G_test1997", 13, 13*12*9*4);
00063 const GroupInformation info_e6("../data/G_e6", 36, 51840);
00064 const GroupInformation info_e7("../data/G_e7", 63, 1451520);
00065 const GroupInformation info_e8("../data/G_e8", 120, 348364800);
00066 const GroupInformation info_cyclic500("../data/G_cyclic500", 500, 500);
00067 const GroupInformation info_cyclic10("../data/G_cyclic10", 10, 10);
00068 const GroupInformation info_cyclic37("../data/G_cyclic37", 37, 37);
00069 const GroupInformation info_cyclic37_2("../data/G_cyclic37-2", 74, 37);
00070 const GroupInformation info_myciel3("../data/G_myciel3", 33, 60);
00071 const GroupInformation info_cov1075("../data/G_cov1075", 120, 3628800L);
00072 // wreath product of S_3 and S_5
00073 const GroupInformation info_S3wrS5("../data/G_S3wrS5", 15, 933120L);
00074 // wreath product of S_5 and S_3
00075 const GroupInformation info_S5wrS3("../data/G_S5wrS3", 15, 10368000L);
00076 const GroupInformation info_S6("../data/G_S6", 6, 720L);
00077 const GroupInformation info_S6_3("../data/G_S6-3", 18, 720L);
00078 // Klein four-group ~ C_2 x C_2
00079 const GroupInformation info_Klein4("../data/G_klein4", 4, 4L);
00080 
00081 template<class PERM>
00082 unsigned int readGroup(const std::string &filename, std::list<typename PERM::ptr> &groupGenerators) {
00083     std::ifstream file;
00084     file.open(filename.c_str());
00085         if (!file.is_open()) {
00086                 std::cerr << "opening " << filename << " failed" << std::endl;
00087         BOOST_REQUIRE(file.is_open());
00088                 return 0;
00089         }
00090     
00091     unsigned int n;
00092     file >> n;
00093 
00094     std::string line;
00095     while (!file.eof()) {
00096         std::getline(file, line);
00097         if (line.length() < 1)
00098             continue;
00099                 boost::shared_ptr<PERM> gen(new PERM(n, line));
00100         groupGenerators.push_back(gen);
00101     }
00102     file.close();
00103     
00104     return n;
00105 }
00106 
00107 using namespace permlib;
00108 
00109 template<class PERM,class TRANS>
00110 struct Constructor {
00111         typedef PERM PERMtype;
00112         typedef TRANS TRANStype;
00113 };
00114 
00115 template<class PERM,class TRANS>
00116 struct ConstructDeterministic1 : public Constructor<PERM,TRANS> {
00117         BSGS<PERM, TRANS> operator()(const GroupInformation& info) {
00118                 std::list<typename PERM::ptr> groupGenerators;
00119                 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators);
00120 
00121                 SchreierSimsConstruction<PERM, TRANS> ssc(n);
00122                 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end());
00123                 
00124                 return bsgs;
00125         }
00126 };
00127 
00128 template<class PERM,class TRANS>
00129 struct ConstructDeterministic2 : public Constructor<PERM,TRANS> {
00130         BSGS<PERM, TRANS> operator()(const GroupInformation& info) {
00131                 std::list<typename PERM::ptr> groupGenerators;
00132                 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators);
00133 
00134                 SchreierSimsConstruction<PERM, TRANS> ssc(n);
00135                 BSGS<PERM, TRANS> bsgs(n);
00136                 bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end());
00137                 
00138                 return bsgs;
00139         }
00140 };
00141 
00142 template<class PERM,class TRANS>
00143 struct ConstructRandomized : public Constructor<PERM,TRANS> {
00144         BSGS<PERM, TRANS> operator()(const GroupInformation& info) {
00145                 std::list<typename PERM::ptr> groupGenerators;
00146                 const unsigned int n = readGroup<PERM>(info.filename, groupGenerators);
00147 
00148                 ProductReplacementGenerator<PERM> rng(n, groupGenerators.begin(), groupGenerators.end());
00149                 RandomSchreierSimsConstruction<PERM, TRANS> ssc(n, &rng, info.order);
00150                 bool result = false;
00151                 BSGS<PERM, TRANS> bsgs = ssc.construct(groupGenerators.begin(), groupGenerators.end(), result);
00152                 BOOST_REQUIRE(result);
00153                 
00154                 return bsgs;
00155         }
00156 };
00157 
00158 template<class PERM,class TRANS>
00159 BSGS<PERM, TRANS> construct(const GroupInformation& info) {
00160         return ConstructDeterministic1<PERM,TRANS>()(info);
00161 }
00162 
00163 template<class PERM, class TRANS>
00164 BSGS<PERM, TRANS> constructCyclicGroup(unsigned int n) {
00165         CyclicGroupConstruction<TRANS> cycConstruct(n);
00166         return cycConstruct.construct();
00167 }
00168 
00169 template<class PERM>
00170 void checkImage(const unsigned long* Delta, unsigned long DeltaSize, const unsigned long* Phi, const boost::shared_ptr<PERM> &repr) {
00171         std::list<unsigned long> imgList(Phi, Phi+DeltaSize);
00172         for (unsigned int j = 0; j < DeltaSize; ++j) {
00173                 std::list<unsigned long>::iterator it = std::find(imgList.begin(), imgList.end(), *repr / Delta[j]);
00174                 BOOST_REQUIRE( it != imgList.end() );
00175                 imgList.erase(it);
00176         }
00177         BOOST_CHECK( imgList.size() == 0 );
00178 }
00179 
00180 } } // end NS
00181 
00182 #endif // - TEST_COMMON_H_