OKlibrary  0.2.1.6
PdVanderWaerden.cpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 20.11.2010 (Swansea)
00002 /* Copyright 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/VanderWaerden.hpp>
00025 
00026 namespace {
00027 
00028 #  ifndef UINT_TYPE_VDW
00029 #    define UINT_TYPE_VDW unsigned long  
00030 #  endif
00031 
00032   typedef UINT_TYPE_VDW uint_type;
00033 
00034   enum { errcode_parameter = 1, errcode_parameter_values = 2 };
00035         
00036   const std::string program = "VanderWaerden";
00037   const std::string err = "ERROR[" + program + "]: ";
00038 
00039   const std::string version = "0.1.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 vertices.\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::Pd_arithprog_ohg<uint_type> vdw_generator;
00057     typedef vdw_generator::set_system_type set_system_type;
00058     typedef vdw_generator::hyperedge_type hyperedge_type;
00059 
00060     const set_system_type G(vdw_generator()(k,n));
00061 
00062     std::cout << "c Palindromised hypergraph with arithmetic-progression length " << k << " and " << n << " vertices.\n";
00063     std::cout << "p cnf " << (n+1)/2 << " " << G.size() << "\n";
00064 
00065     for (set_system_type::const_iterator i = G.begin(); i != G.end(); ++i) {
00066       const hyperedge_type H = *i;
00067       for (hyperedge_type::const_iterator j = H.begin(); j != H.end(); ++j)
00068         std::cout << *j << " ";
00069       std::cout << "0\n";
00070     }
00071 
00072   }
00073   catch (boost::bad_lexical_cast&) {
00074     std::cerr << err << "Both parameters must be non-negative integers\n"
00075     "in the range given by UINT_TYPE_VDW (default = unsigned int).\n";
00076     return(errcode_parameter_values);
00077   }
00078 
00079 }