Commit 945ca547 authored by Tiago Peixoto's avatar Tiago Peixoto

Implement complete_graph()

parent 98795441
...@@ -25,6 +25,7 @@ libgraph_tool_generation_la_SOURCES = \ ...@@ -25,6 +25,7 @@ libgraph_tool_generation_la_SOURCES = \
graph_triangulation.cc \ graph_triangulation.cc \
graph_lattice.cc \ graph_lattice.cc \
graph_geometric.cc \ graph_geometric.cc \
graph_complete.cc \
graph_price.cc graph_price.cc
...@@ -36,5 +37,6 @@ libgraph_tool_generation_la_include_HEADERS = \ ...@@ -36,5 +37,6 @@ libgraph_tool_generation_la_include_HEADERS = \
graph_triangulation.hh \ graph_triangulation.hh \
graph_lattice.hh \ graph_lattice.hh \
graph_geometric.hh \ graph_geometric.hh \
graph_complete.hh \
graph_price.hh \ graph_price.hh \
sampler.hh sampler.hh
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2013 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_complete.hh"
#include <boost/python.hpp>
using namespace std;
using namespace boost;
using namespace graph_tool;
void complete(GraphInterface& gi, size_t N, bool directed, bool self_loops)
{
get_complete()(gi.GetGraph(), N, directed, self_loops);
}
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2013 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef GRAPH_COMPLETE_HH
#define GRAPH_COMPLETE_HH
#include <iostream>
#include "graph_util.hh"
namespace graph_tool
{
using namespace std;
using namespace boost;
struct get_complete
{
template <class Graph>
void operator()(Graph& g, size_t N, bool directed, bool self_loops) const
{
for (int i = 0; i < N; ++i)
add_vertex(g);
for (int i = 0; i < N; ++i)
{
for (size_t j = (directed) ? 0 : i; j < N; ++j)
{
if (!self_loops && j == i)
continue;
add_edge(vertex(i, g), vertex(j, g), g);
}
}
}
};
} // namespace graph_tool
#endif // GRAPH_COMPLETE_HH
...@@ -99,6 +99,7 @@ void geometric(GraphInterface& gi, python::object opoints, double r, ...@@ -99,6 +99,7 @@ void geometric(GraphInterface& gi, python::object opoints, double r,
python::object orange, bool periodic, boost::any pos); python::object orange, bool periodic, boost::any pos);
void price(GraphInterface& gi, size_t N, double gamma, double c, size_t m, void price(GraphInterface& gi, size_t N, double gamma, double c, size_t m,
rng_t& rng); rng_t& rng);
void complete(GraphInterface& gi, size_t N, bool directed, bool self_loops);
using namespace boost::python; using namespace boost::python;
...@@ -115,4 +116,5 @@ BOOST_PYTHON_MODULE(libgraph_tool_generation) ...@@ -115,4 +116,5 @@ BOOST_PYTHON_MODULE(libgraph_tool_generation)
def("lattice", &lattice); def("lattice", &lattice);
def("geometric", &geometric); def("geometric", &geometric);
def("price", &price); def("price", &price);
def("complete", &complete);
} }
...@@ -37,6 +37,7 @@ Summary ...@@ -37,6 +37,7 @@ Summary
lattice lattice
geometric_graph geometric_graph
price_network price_network
complete_graph
Contents Contents
++++++++ ++++++++
...@@ -55,7 +56,7 @@ import sys, numpy, numpy.random ...@@ -55,7 +56,7 @@ import sys, numpy, numpy.random
__all__ = ["random_graph", "random_rewire", "predecessor_tree", "line_graph", __all__ = ["random_graph", "random_rewire", "predecessor_tree", "line_graph",
"graph_union", "triangulation", "lattice", "geometric_graph", "graph_union", "triangulation", "lattice", "geometric_graph",
"price_network"] "price_network", "complete_graph"]
def random_graph(N, deg_sampler, deg_corr=None, cache_probs=True, directed=True, def random_graph(N, deg_sampler, deg_corr=None, cache_probs=True, directed=True,
...@@ -1158,6 +1159,52 @@ def lattice(shape, periodic=False): ...@@ -1158,6 +1159,52 @@ def lattice(shape, periodic=False):
libgraph_tool_generation.lattice(g._Graph__graph, shape, periodic) libgraph_tool_generation.lattice(g._Graph__graph, shape, periodic)
return g return g
def complete_graph(N, self_loops=False, directed=False):
r"""
Generate complete graph.
Parameters
----------
N : ``int``
Number of vertices.
self_loops : bool (optional, default: ``False``)
If ``True``, self-loops are included.
directed : bool (optional, default: ``False``)
If ``True``, a directed graph is generated.
Returns
-------
complete_graph : :class:`~graph_tool.Graph`
A complete graph.
Examples
--------
>>> g = gt.complete_graph(30)
>>> pos = gt.sfdp_layout(g, cooling_step=0.95, epsilon=1e-2)
>>> gt.graph_draw(g, pos=pos, output_size=(300,300), output="complete.pdf")
<...>
.. testcode::
:hide:
gt.graph_draw(g, pos=pos, output_size=(300,300), output="complete.png")
.. figure:: complete.*
A complete graph with :math:`N=30` vertices.
References
----------
.. [complete] http://en.wikipedia.org/wiki/Complete_graph
"""
g = Graph(directed=directed)
libgraph_tool_generation.complete(g._Graph__graph, N, directed, self_loops)
return g
def geometric_graph(points, radius, ranges=None): def geometric_graph(points, radius, ranges=None):
r""" r"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment