Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
491d21a7
Commit
491d21a7
authored
Apr 13, 2013
by
Tiago Peixoto
Browse files
Implement circular_graph()
parent
203d04bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/graph/generation/graph_complete.cc
View file @
491d21a7
...
...
@@ -26,7 +26,14 @@ using namespace std;
using
namespace
boost
;
using
namespace
graph_tool
;
void
complete
(
GraphInterface
&
gi
,
size_t
N
,
bool
directed
,
bool
self_loops
)
void
complete
(
GraphInterface
&
gi
,
size_t
N
,
bool
directed
,
bool
self_loops
)
{
get_complete
()(
gi
.
GetGraph
(),
N
,
directed
,
self_loops
);
}
void
circular
(
GraphInterface
&
gi
,
size_t
N
,
size_t
k
,
bool
directed
,
bool
self_loops
)
{
get_circular
()(
gi
.
GetGraph
(),
N
,
k
,
directed
,
self_loops
);
}
src/graph/generation/graph_complete.hh
View file @
491d21a7
...
...
@@ -36,11 +36,37 @@ struct get_complete
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_
t
j
=
(
directed
)
?
0
:
i
;
j
<
N
;
++
j
)
for
(
in
t
j
=
directed
?
0
:
i
;
j
<
N
;
++
j
)
{
if
(
!
self_loops
&&
j
==
i
)
continue
;
add_edge
(
vertex
(
i
,
g
),
vertex
(
j
,
g
),
g
);
add_edge
(
vertex
(
i
,
g
),
vertex
(
j
,
g
),
g
);
}
}
}
};
struct
get_circular
{
template
<
class
Graph
>
void
operator
()(
Graph
&
g
,
size_t
N
,
size_t
k
,
bool
directed
,
bool
self_loops
)
const
{
for
(
int
i
=
0
;
i
<
N
;
++
i
)
add_vertex
(
g
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
for
(
int
j
=
i
;
j
<
i
+
k
+
1
;
++
j
)
{
if
(
!
self_loops
&&
j
==
i
)
continue
;
add_edge
(
vertex
(
i
,
g
),
vertex
(
j
%
N
,
g
),
g
);
if
(
directed
&&
j
!=
i
)
add_edge
(
vertex
(
j
%
N
,
g
),
vertex
(
i
,
g
),
g
);
}
}
}
...
...
src/graph/generation/graph_generation.cc
View file @
491d21a7
...
...
@@ -100,6 +100,7 @@ void geometric(GraphInterface& gi, python::object opoints, double r,
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
);
void
circular
(
GraphInterface
&
gi
,
size_t
N
,
size_t
k
,
bool
directed
,
bool
self_loops
);
using
namespace
boost
::
python
;
...
...
@@ -117,4 +118,5 @@ BOOST_PYTHON_MODULE(libgraph_tool_generation)
def
(
"geometric"
,
&
geometric
);
def
(
"price"
,
&
price
);
def
(
"complete"
,
&
complete
);
def
(
"circular"
,
&
circular
);
}
src/graph_tool/generation/__init__.py
View file @
491d21a7
...
...
@@ -38,6 +38,7 @@ Summary
geometric_graph
price_network
complete_graph
circular_graph
Contents
++++++++
...
...
@@ -56,7 +57,7 @@ import sys, numpy, numpy.random
__all__
=
[
"random_graph"
,
"random_rewire"
,
"predecessor_tree"
,
"line_graph"
,
"graph_union"
,
"triangulation"
,
"lattice"
,
"geometric_graph"
,
"price_network"
,
"complete_graph"
]
"price_network"
,
"complete_graph"
,
"circular_graph"
]
def
random_graph
(
N
,
deg_sampler
,
deg_corr
=
None
,
cache_probs
=
True
,
directed
=
True
,
...
...
@@ -1205,6 +1206,49 @@ def complete_graph(N, self_loops=False, directed=False):
libgraph_tool_generation
.
complete
(
g
.
_Graph__graph
,
N
,
directed
,
self_loops
)
return
g
def
circular_graph
(
N
,
k
=
1
,
self_loops
=
False
,
directed
=
False
):
r
"""
Generate a circular graph.
Parameters
----------
N : ``int``
Number of vertices.
k : ``int`` (optional, default: ``True``)
Number of nearest neighbours to be connected.
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
-------
circular_graph : :class:`~graph_tool.Graph`
A circular graph.
Examples
--------
>>> g = gt.circular_graph(30, 2)
>>> pos = gt.sfdp_layout(g, cooling_step=0.95)
>>> gt.graph_draw(g, pos=pos, output_size=(300,300), output="circular.pdf")
<...>
.. testcode::
:hide:
gt.graph_draw(g, pos=pos, output_size=(300,300), output="circular.png")
.. figure:: circular.*
A circular graph with :math:`N=30` vertices, and :math:`k=2`.
"""
g
=
Graph
(
directed
=
directed
)
libgraph_tool_generation
.
circular
(
g
.
_Graph__graph
,
N
,
k
,
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