OKlibrary  0.2.1.6
GreenTao.cpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 17.10.2009 (Swansea)
00002 /* Copyright 2009, 2010 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 
00019 #include <iostream>
00020 #include <string>
00021 
00022 #include <boost/lexical_cast.hpp>
00023 
00024 #include <OKlib/Combinatorics/Hypergraphs/Generators/GreenTao.hpp>
00025 
00026 namespace {
00027 
00028 #  ifndef UINT_TYPE_GT
00029 #    define UINT_TYPE_GT unsigned long  
00030 #  endif
00031 
00032   typedef UINT_TYPE_GT uint_type;
00033 
00034   enum { errcode_parameter = 1, errcode_parameter_values = 2 };
00035         
00036   const std::string program = "GreenTao";
00037   const std::string err = "ERROR[" + program + "]: ";
00038 
00039   const std::string version = "0.2";
00040 
00041 }
00042 
00043 int main(const int argc, const char* const argv[]) {
00044 
00045   if (argc != 3) {
00046     std::cerr << err << "Exactly two arguments are needed,\n"
00047     "the length k of arithmetic progressions, and the number n of primes.\n";
00048     return errcode_parameter;
00049   }
00050 
00051   try {
00052 
00053     const uint_type k = boost::lexical_cast<uint_type>(argv[1]);
00054     const uint_type n = boost::lexical_cast<uint_type>(argv[2]);
00055 
00056     typedef OKlib::Combinatorics::Hypergraphs::Generators::GreenTao<uint_type> gt_generator;
00057     typedef gt_generator::set_system_type set_system_type;
00058     typedef gt_generator::hyperedge_type hyperedge_type;
00059     const gt_generator g(k,n);
00060 
00061     const set_system_type G(g.hyperedge_set());
00062 
00063     std::cout << "c Green-Tao hypergraph with arithmetic-progression length " << g.k << " and " << g.nver() << " vertices.\n";
00064     std::cout << "c The prime numbers are used directly as vertices.\n";
00065     std::cout << "p cnf " << g.max_index() << " " << G.size() << "\n";
00066 
00067     for (set_system_type::const_iterator i = G.begin(); i != G.end(); ++i) {
00068       const hyperedge_type H = *i;
00069       for (hyperedge_type::const_iterator j = H.begin(); j != H.end(); ++j)
00070         std::cout << *j << " ";
00071       std::cout << "0\n";
00072     }
00073 
00074   }
00075   catch (boost::bad_lexical_cast&) {
00076     std::cerr << err << "Both parameters must be non-negative integers\n"
00077     "in the range given by UINT_TYPE_GT (default = unsigned long).\n";
00078     return(errcode_parameter_values);
00079   }
00080 
00081 }