Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tiago Peixoto
graph-tool
Commits
945ca547
Commit
945ca547
authored
Apr 13, 2013
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement complete_graph()
parent
98795441
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
1 deletion
+135
-1
src/graph/generation/Makefile.am
src/graph/generation/Makefile.am
+2
-0
src/graph/generation/graph_complete.cc
src/graph/generation/graph_complete.cc
+32
-0
src/graph/generation/graph_complete.hh
src/graph/generation/graph_complete.hh
+51
-0
src/graph/generation/graph_generation.cc
src/graph/generation/graph_generation.cc
+2
-0
src/graph_tool/generation/__init__.py
src/graph_tool/generation/__init__.py
+48
-1
No files found.
src/graph/generation/Makefile.am
View file @
945ca547
...
...
@@ -25,6 +25,7 @@ libgraph_tool_generation_la_SOURCES = \
graph_triangulation.cc
\
graph_lattice.cc
\
graph_geometric.cc
\
graph_complete.cc
\
graph_price.cc
...
...
@@ -36,5 +37,6 @@ libgraph_tool_generation_la_include_HEADERS = \
graph_triangulation.hh
\
graph_lattice.hh
\
graph_geometric.hh
\
graph_complete.hh
\
graph_price.hh
\
sampler.hh
src/graph/generation/graph_complete.cc
0 → 100644
View file @
945ca547
// 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
);
}
src/graph/generation/graph_complete.hh
0 → 100644
View file @
945ca547
// 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
src/graph/generation/graph_generation.cc
View file @
945ca547
...
...
@@ -99,6 +99,7 @@ void geometric(GraphInterface& gi, python::object opoints, double r,
python
::
object
orange
,
bool
periodic
,
boost
::
any
pos
);
void
price
(
GraphInterface
&
gi
,
size_t
N
,
double
gamma
,
double
c
,
size_t
m
,
rng_t
&
rng
);
void
complete
(
GraphInterface
&
gi
,
size_t
N
,
bool
directed
,
bool
self_loops
);
using
namespace
boost
::
python
;
...
...
@@ -115,4 +116,5 @@ BOOST_PYTHON_MODULE(libgraph_tool_generation)
def
(
"lattice"
,
&
lattice
);
def
(
"geometric"
,
&
geometric
);
def
(
"price"
,
&
price
);
def
(
"complete"
,
&
complete
);
}
src/graph_tool/generation/__init__.py
View file @
945ca547
...
...
@@ -37,6 +37,7 @@ Summary
lattice
geometric_graph
price_network
complete_graph
Contents
++++++++
...
...
@@ -55,7 +56,7 @@ import sys, numpy, numpy.random
__all__
=
[
"random_graph"
,
"random_rewire"
,
"predecessor_tree"
,
"line_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
,
...
...
@@ -1158,6 +1159,52 @@ def lattice(shape, periodic=False):
libgraph_tool_generation
.
lattice
(
g
.
_Graph__graph
,
shape
,
periodic
)
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
):
r
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment