Skip to content
GitLab
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
4a5bc229
Commit
4a5bc229
authored
Oct 19, 2016
by
Tiago Peixoto
Browse files
clustering.local_clustering(): Fix bug with directed graphs
parent
c8d01f45
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph/clustering/graph_clustering.cc
View file @
4a5bc229
...
...
@@ -34,25 +34,19 @@ using namespace graph_tool;
boost
::
python
::
tuple
global_clustering
(
GraphInterface
&
g
)
{
double
c
,
c_err
;
bool
directed
=
g
.
get_directed
();
g
.
set_directed
(
false
);
run_action
<
graph_tool
::
detail
::
never_directed
>
()
(
g
,
std
::
bind
(
get_global_clustering
(),
std
::
placeholders
::
_1
,
std
::
ref
(
c
),
std
::
ref
(
c_err
)))();
g
.
set_directed
(
directed
);
return
boost
::
python
::
make_tuple
(
c
,
c_err
);
}
void
local_clustering
(
GraphInterface
&
g
,
boost
::
any
prop
)
{
bool
directed
=
g
.
get_directed
();
g
.
set_directed
(
false
);
run_action
<
graph_tool
::
detail
::
never_directed
>
()
run_action
<>
()
(
g
,
std
::
bind
(
set_clustering_to_property
(),
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
),
writable_vertex_scalar_properties
())(
prop
);
g
.
set_directed
(
directed
);
}
using
namespace
boost
::
python
;
...
...
src/graph/clustering/graph_clustering.hh
View file @
4a5bc229
...
...
@@ -46,7 +46,7 @@ using namespace boost;
template
<
class
Graph
,
class
VProp
>
pair
<
int
,
int
>
get_triangles
(
typename
graph_traits
<
Graph
>::
vertex_descriptor
v
,
VProp
&
mark
,
const
Graph
&
g
)
const
Graph
&
g
)
{
size_t
triangles
=
0
;
...
...
@@ -74,7 +74,10 @@ get_triangles(typename graph_traits<Graph>::vertex_descriptor v, VProp& mark,
mark
[
n
]
=
false
;
size_t
k
=
out_degree
(
v
,
g
);
return
make_pair
(
triangles
/
2
,
(
k
*
(
k
-
1
))
/
2
);
if
(
is_directed
::
apply
<
Graph
>::
type
::
value
)
return
make_pair
(
triangles
,
(
k
*
(
k
-
1
)));
else
return
make_pair
(
triangles
/
2
,
(
k
*
(
k
-
1
))
/
2
);
}
...
...
@@ -124,7 +127,6 @@ struct set_clustering_to_property
void
operator
()(
const
Graph
&
g
,
ClustMap
clust_map
)
const
{
typedef
typename
property_traits
<
ClustMap
>::
value_type
c_type
;
typename
get_undirected_graph
<
Graph
>::
type
ug
(
g
);
vector
<
bool
>
mask
(
num_vertices
(
g
),
false
);
#pragma omp parallel if (num_vertices(g) > OPENMP_MIN_THRESH) \
...
...
@@ -133,7 +135,7 @@ struct set_clustering_to_property
(
g
,
[
&
](
auto
v
)
{
auto
triangles
=
get_triangles
(
v
,
mask
,
u
g
);
// get from ug
auto
triangles
=
get_triangles
(
v
,
mask
,
g
);
double
clustering
=
(
triangles
.
second
>
0
)
?
double
(
triangles
.
first
)
/
triangles
.
second
:
0.0
;
...
...
src/graph_tool/clustering/__init__.py
View file @
4a5bc229
...
...
@@ -130,10 +130,10 @@ def local_clustering(g, prop=None, undirected=True):
:doi:`10.1038/30918`
"""
if
prop
==
None
:
if
prop
is
None
:
prop
=
g
.
new_vertex_property
(
"double"
)
if
g
.
is_directed
()
and
undirected
:
g
=
GraphView
(
g
,
directed
=
False
)
g
=
GraphView
(
g
,
directed
=
False
,
skip_properties
=
True
)
_gt
.
local_clustering
(
g
.
_Graph__graph
,
_prop
(
"v"
,
g
,
prop
))
return
prop
...
...
@@ -191,6 +191,8 @@ def global_clustering(g):
:doi:`10.1137/S003614450342480`
"""
if
g
.
is_directed
():
g
=
GraphView
(
g
,
directed
=
False
,
skip_properties
=
True
)
c
=
_gt
.
global_clustering
(
g
.
_Graph__graph
)
return
c
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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