OKlibrary  0.2.1.6
MinimumTransversals_GreenTao.cpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 15.11.2009 (Swansea)
00002 /* Copyright 2009 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00031 #include <set>
00032 #include <vector>
00033 #include <stdexcept>
00034 #include <cassert>
00035 
00036 #include <OKlib/Combinatorics/Hypergraphs/Generators/GreenTao.hpp>
00037 #include <OKlib/Combinatorics/Hypergraphs/Transversals/Bounded/VertexBranching.hpp>
00038 
00039 #include <OKlib/Combinatorics/Hypergraphs/Transversals/Bounded/MinimumTransversalsMongen.hpp>
00040 
00041 namespace OKlib {
00042  namespace Combinatorics {
00043   namespace Hypergraphs {
00044    namespace Transversals {
00045     namespace Bounded {
00046 
00047       typedef OKlib::Combinatorics::Hypergraphs::Generators::GreenTao<vertex_type> GT_hypergraph_type;
00048       typedef GT_hypergraph_type::set_system_type set_system_type;
00049 
00050       typedef OKlib::Combinatorics::Hypergraphs::Transversals::Bounded::DirectStratification<set_system_type, vertex_type> Strata_t;
00051 
00052       struct Wrapper {
00053         Wrapper() : S(0) {}
00054         void set(const vertex_type k, const vertex_type N) {
00055           if (S) delete S;
00056           GT_hypergraph_type G(k, N);
00057           S = new Strata_t(G.hyperedge_set(), G.vertex_set());  
00058         }
00059         hyperedge_list_type operator()(const vertex_type n) const {
00060           assert(S);
00061           return S -> operator()(n);
00062         }
00063         ~Wrapper() { delete S; }
00064 
00065         private :
00066           const Strata_t* S;
00067       };
00068 
00069       Wrapper prog_gen;
00070 
00071 
00072       void initialise(const vertex_type N, const parameter_type& P) {
00073         if (P.size() < 1)
00074           throw std::runtime_error
00075             ("ERROR[MinimumTransversals_GreenTao]: "
00076              "The progression-length must be provided as parameter.");
00077         prog_gen.set(P[0], N);
00078       }
00079 
00080       hyperedge_list_type generator(const vertex_type n) {
00081         return prog_gen(n);
00082       }
00083 
00084     }
00085    }
00086   }
00087  }
00088 }
00089