OKlibrary  0.2.1.6
Generators.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 16.6.2003 (Swansea)
00002 /* Copyright 2003 - 2007, 2011 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 
00014 #ifndef GENERATORSWAECHTER_jhg4erC
00015 #define GENERATORSWAECHTER_jhg4erC
00016 
00017 #include <utility>
00018 
00019 #include <boost/graph/graph_traits.hpp>
00020 
00021 #include <boost/concept_check.hpp>
00022 
00023 #include <OKlib/Combinatorics/Graphs/BoostSupport/Concepts_Graphs.hpp>
00024 
00025 namespace Generators {
00026 
00027   template <typename Graph>
00028   Graph complete_graph(typename boost::graph_traits<Graph>::vertices_size_type n) {
00029     boost::function_requires<Concepts_Graphs::VertexListSizeConstructibleGraphConcept<Graph> >();
00030     boost::function_requires<boost::EdgeMutableGraphConcept<Graph> >();
00031     boost::function_requires<boost::AssignableConcept<Graph> >();
00032     boost::function_requires<boost::CopyConstructibleConcept<Graph> >();
00033     Graph g(n);
00034     complete_graph_imp(g, typename boost::graph_traits<Graph>::directed_category());
00035     return g;
00036   }
00037   template <typename Graph>
00038   inline void complete_graph_imp(Graph& g, boost::directed_tag) {
00039     typedef typename boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
00040     const std::pair<vertex_iterator, vertex_iterator> pi = vertices(g);
00041     for (vertex_iterator i = pi.first; i != pi.second; ++i)
00042       for (vertex_iterator j = ++vertex_iterator(i); j != pi.second; ++j) {
00043         add_edge(*i, *j, g);
00044         add_edge(*j, *i, g);
00045       }
00046   }
00047   template<typename Graph>
00048   inline void complete_graph_imp(Graph& g, boost::undirected_tag) {
00049     typedef typename boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
00050     const std::pair<vertex_iterator, vertex_iterator> pi = vertices(g);
00051     for (vertex_iterator i = pi.first; i != pi.second; ++i)
00052       for (vertex_iterator j = ++vertex_iterator(i); j != pi.second; ++j)
00053         add_edge(*i, *j, g);
00054   }
00055 
00056 }
00057 
00058 #endif
00059