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
f2bdc674
Commit
f2bdc674
authored
Mar 11, 2012
by
Tiago Peixoto
Browse files
Improve label_parallel_edges()
parent
fa2b7b99
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph/stats/graph_parallel.cc
View file @
f2bdc674
...
...
@@ -27,12 +27,13 @@ using namespace std;
using
namespace
boost
;
using
namespace
graph_tool
;
void
do_label_parallel_edges
(
GraphInterface
&
gi
,
boost
::
any
property
)
void
do_label_parallel_edges
(
GraphInterface
&
gi
,
boost
::
any
property
,
bool
mark_only
,
bool
count_all
)
{
GraphInterface
::
edge_index_map_t
edge_index
=
any_cast
<
GraphInterface
::
edge_index_map_t
>
(
gi
.
GetEdgeIndex
());
run_action
<>
()(
gi
,
bind
<
void
>
(
label_parallel_edges
(),
_1
,
edge_index
,
_2
),
edge_index
,
_2
,
mark_only
,
count_all
),
edge_scalar_properties
())(
property
);
}
...
...
src/graph/stats/graph_parallel.hh
View file @
f2bdc674
...
...
@@ -33,7 +33,7 @@ struct label_parallel_edges
{
template
<
class
Graph
,
class
EdgeIndexMap
,
class
ParallelMap
>
void
operator
()(
const
Graph
&
g
,
EdgeIndexMap
edge_index
,
ParallelMap
parallel
)
const
ParallelMap
parallel
,
bool
mark_only
,
bool
count_all
)
const
{
typedef
typename
graph_traits
<
Graph
>::
edge_descriptor
edge_t
;
...
...
@@ -45,14 +45,11 @@ struct label_parallel_edges
if
(
v
==
graph_traits
<
Graph
>::
null_vertex
())
continue
;
tr1
::
unordered_set
<
edge_t
,
DescriptorHash
<
EdgeIndexMap
>
>
p_edges
(
0
,
DescriptorHash
<
EdgeIndexMap
>
(
edge_index
));
typename
graph_traits
<
Graph
>::
out_edge_iterator
e1
,
e2
,
e_end1
,
e_end2
;
for
(
tie
(
e1
,
e_end1
)
=
out_edges
(
v
,
g
);
e1
!=
e_end1
;
++
e1
)
{
if
(
p_edges
.
find
(
*
e1
)
!=
p_edges
.
end
()
)
if
(
get
(
parallel
,
*
e1
)
!=
0
)
continue
;
// do not visit edges twice in undirected graphs
...
...
@@ -60,14 +57,11 @@ struct label_parallel_edges
target
(
*
e1
,
g
)
<
v
)
continue
;
size_t
n
=
0
;
size_t
n
=
count_all
?
1
:
0
;
put
(
parallel
,
*
e1
,
n
);
for
(
tie
(
e2
,
e_end2
)
=
out_edges
(
v
,
g
);
e2
!=
e_end2
;
++
e2
)
if
(
*
e2
!=
*
e1
&&
target
(
*
e1
,
g
)
==
target
(
*
e2
,
g
))
{
put
(
parallel
,
*
e2
,
++
n
);
p_edges
.
insert
(
*
e2
);
}
put
(
parallel
,
*
e2
,
mark_only
?
1
:
++
n
);
}
}
}
...
...
src/graph_tool/stats/__init__.py
View file @
f2bdc674
...
...
@@ -19,8 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
``graph_tool.stats`` -
Graph S
tatistics
---------------------------------------
``graph_tool.stats`` -
Miscellaneous s
tatistics
---------------------------------------
--------
Summary
+++++++
...
...
@@ -278,15 +278,21 @@ def remove_labeled_edges(g, label):
g
.
pop_filter
(
all
=
False
,
directed
=
True
,
reversed
=
True
)
def
label_parallel_edges
(
g
,
eprop
=
None
):
def
label_parallel_edges
(
g
,
mark_only
=
False
,
count_all
=
False
,
eprop
=
None
):
r
"""Label edges which are parallel, i.e, have the same source and target
vertices. For each parallel edge set :math:`PE`, the labelling starts from 0
to :math:`|PE|-1`. If the `eprop` parameter is given (a
:class:`~graph_tool.PropertyMap`), the labelling is stored there."""
if
eprop
==
None
:
eprop
=
g
.
new_edge_property
(
"int32_t"
)
to :math:`|PE|-1`. (If `count_all==True`, the range is 0 to :math:`|PE|`
instead). If `mark_only==True`, all parallel edges are simply marked with
the value 1. If the `eprop` parameter is given
(a :class:`~graph_tool.PropertyMap`), the labelling is stored there."""
if
eprop
is
None
:
if
mark_only
:
eprop
=
g
.
new_edge_property
(
"bool"
)
else
:
eprop
=
g
.
new_edge_property
(
"int32_t"
)
libgraph_tool_stats
.
\
label_parallel_edges
(
g
.
_Graph__graph
,
_prop
(
"e"
,
g
,
eprop
))
label_parallel_edges
(
g
.
_Graph__graph
,
_prop
(
"e"
,
g
,
eprop
),
mark_only
,
count_all
)
return
eprop
...
...
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