Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
43
Issues
43
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
808318a6
Commit
808318a6
authored
Jul 02, 2013
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement vertex reordering during graph copy
parent
cbc77236
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
src/graph/graph.hh
src/graph/graph.hh
+2
-1
src/graph/graph_copy.cc
src/graph/graph_copy.cc
+8
-5
src/graph_tool/__init__.py
src/graph_tool/__init__.py
+10
-1
No files found.
src/graph/graph.hh
View file @
808318a6
...
...
@@ -59,7 +59,8 @@ class GraphInterface
public:
GraphInterface
();
GraphInterface
(
const
GraphInterface
&
g
,
bool
keep_ref
,
python
::
object
ovprops
,
python
::
object
oeprops
);
python
::
object
ovprops
,
python
::
object
oeprops
,
python
::
object
vorder
);
~
GraphInterface
();
// useful enums
...
...
src/graph/graph_copy.cc
View file @
808318a6
...
...
@@ -83,12 +83,13 @@ struct do_graph_copy
{
template
<
class
GraphTgt
,
class
GraphSrc
,
class
TgtVertexIndexMap
,
class
SrcVertexIndexMap
,
class
TgtEdgeIndexMap
,
class
SrcEdgeIndexMap
>
class
SrcEdgeIndexMap
,
class
OrderMap
>
void
operator
()(
const
GraphSrc
&
src
,
GraphTgt
&
tgt
,
TgtVertexIndexMap
src_vertex_index
,
SrcVertexIndexMap
tgt_vertex_index
,
TgtEdgeIndexMap
,
SrcEdgeIndexMap
tgt_edge_index
,
OrderMap
vertex_order
,
vector
<
pair
<
reference_wrapper
<
boost
::
any
>
,
reference_wrapper
<
boost
::
any
>
>
>&
vprops
,
vector
<
pair
<
reference_wrapper
<
boost
::
any
>
,
reference_wrapper
<
boost
::
any
>
>
>&
eprops
)
const
{
...
...
@@ -98,7 +99,8 @@ struct do_graph_copy
{
if
(
src_vertex_index
[
*
v
]
>=
index_map
.
size
())
index_map
.
resize
(
src_vertex_index
[
*
v
]
+
1
);
typename
graph_traits
<
GraphTgt
>::
vertex_descriptor
new_v
=
typename
graph_traits
<
GraphTgt
>::
vertex_descriptor
new_v
=
get
(
vertex_order
,
*
v
);
while
(
new_v
>=
num_vertices
(
tgt
))
add_vertex
(
tgt
);
index_map
[
src_vertex_index
[
*
v
]]
=
tgt_vertex_index
[
new_v
];
...
...
@@ -126,7 +128,8 @@ struct do_graph_copy
// copy constructor
GraphInterface
::
GraphInterface
(
const
GraphInterface
&
gi
,
bool
keep_ref
,
python
::
object
ovprops
,
python
::
object
oeprops
)
python
::
object
ovprops
,
python
::
object
oeprops
,
python
::
object
vorder
)
:
_mg
(
keep_ref
?
gi
.
_mg
:
shared_ptr
<
multigraph_t
>
(
new
multigraph_t
())),
_vertex_index
(
get
(
vertex_index
,
*
_mg
)),
_edge_index
(
get
(
edge_index_t
(),
*
_mg
)),
...
...
@@ -159,7 +162,7 @@ GraphInterface::GraphInterface(const GraphInterface& gi, bool keep_ref,
(
const_cast
<
GraphInterface
&>
(
gi
),
bind
<
void
>
(
do_graph_copy
(),
_1
,
ref
(
*
_mg
),
gi
.
_vertex_index
,
_vertex_index
,
gi
.
_edge_index
,
_edge_index
,
ref
(
vprops
),
ref
(
eprops
))
)(
);
gi
.
_edge_index
,
_edge_index
,
_2
,
ref
(
vprops
),
ref
(
eprops
))
,
vertex_scalar_properties
())(
avorder
);
// filters will be copied in python
}
src/graph_tool/__init__.py
View file @
808318a6
...
...
@@ -1020,6 +1020,10 @@ class Graph(object):
``prune``, to specify a different behavior to vertex, edge, and reversal
filters, respectively.
If ``vorder`` is specified, it should correspond to a vertex
:class:`~graph_tool.PropertyMap` specifying the ordering of the vertices in
the copied graph.
The graph is implemented as an `adjacency list`_, where both vertex and edge
lists are C++ STL vectors.
...
...
@@ -1027,7 +1031,7 @@ class Graph(object):
"""
def
__init__
(
self
,
g
=
None
,
directed
=
True
,
prune
=
False
):
def
__init__
(
self
,
g
=
None
,
directed
=
True
,
prune
=
False
,
vorder
=
None
):
self
.
__properties
=
{}
self
.
__known_properties
=
{}
self
.
__filter_state
=
{
"reversed"
:
False
,
...
...
@@ -1055,6 +1059,11 @@ class Graph(object):
for
k
,
v
in
g
.
edge_properties
.
items
():
eprops
.
append
([
_prop
(
"e"
,
g
,
v
),
libcore
.
any
()])
# The vertex ordering
if
vorder
is
None
:
vorder
=
g
.
new_vertex_property
(
"int"
)
vorder
.
fa
=
numpy
.
arange
(
g
.
num_vertices
())
# The actual copying of the graph and property maps
self
.
__graph
=
libcore
.
GraphInterface
(
g
.
__graph
,
False
,
vprops
,
eprops
)
...
...
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