Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tiago Peixoto
graph-tool
Commits
fa6816e0
Commit
fa6816e0
authored
Sep 13, 2015
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove "permissions" control in Graph class
parent
26553a42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
75 deletions
+1
-75
src/graph_tool/__init__.py
src/graph_tool/__init__.py
+0
-17
src/graph_tool/search/__init__.py
src/graph_tool/search/__init__.py
+1
-58
No files found.
src/graph_tool/__init__.py
View file @
fa6816e0
...
...
@@ -1621,10 +1621,6 @@ class Graph(object):
# directedness is always a filter
self
.
set_directed
(
g
.
is_directed
())
# modification permissions
self
.
__perms
=
{
"add_edge"
:
True
,
"del_edge"
:
True
,
"add_vertex"
:
True
,
"del_vertex"
:
True
}
def
copy
(
self
):
"""Return a deep copy of self. All :ref:`internal property maps <sec_internal_props>`
are also copied."""
...
...
@@ -1655,10 +1651,6 @@ class Graph(object):
# Graph access
# ============
def
__check_perms
(
self
,
ptype
):
if
not
self
.
__perms
[
ptype
]:
raise
RuntimeError
(
"the graph cannot be modified at this point!"
)
def
vertices
(
self
):
"""Return an :meth:`iterator <iterator.__iter__>` over the vertices.
...
...
@@ -1759,7 +1751,6 @@ class Graph(object):
if
n
==
0
:
return
(
None
for
i
in
range
(
0
,
0
))
self
.
__check_perms
(
"add_vertex"
)
v
=
libcore
.
add_vertex
(
self
.
__graph
,
n
)
vfilt
=
self
.
get_vertex_filter
()
...
...
@@ -1815,8 +1806,6 @@ class Graph(object):
the graph will no longer be the same.
"""
self
.
__check_perms
(
"del_vertex"
)
try
:
vs
=
numpy
.
array
([
int
(
vertex
)],
dtype
=
"int64"
)
except
TypeError
:
...
...
@@ -1862,7 +1851,6 @@ class Graph(object):
in the graph if they don't yet exist.
"""
self
.
__check_perms
(
"add_edge"
)
e
=
libcore
.
add_edge
(
self
.
__graph
,
self
.
vertex
(
int
(
source
),
add_missing
=
add_missing
),
self
.
vertex
(
int
(
target
),
add_missing
=
add_missing
))
...
...
@@ -1887,7 +1875,6 @@ class Graph(object):
unchanged, unless :meth:`~Graph.set_fast_edge_removal` is set to
`True`, in which case it can change.
"""
self
.
__check_perms
(
"del_edge"
)
return
libcore
.
remove_edge
(
self
.
__graph
,
edge
)
def
add_edge_list
(
self
,
edge_list
,
hashed
=
False
,
string_vals
=
False
,
...
...
@@ -1911,7 +1898,6 @@ class Graph(object):
If given, ``eprops`` specifies edge property maps that will be filled
with the remaining values at each row, if there are more than two.
"""
self
.
__check_perms
(
"add_edge"
)
if
eprops
is
None
:
eprops
=
()
else
:
...
...
@@ -1954,13 +1940,10 @@ class Graph(object):
def
clear
(
self
):
"""Remove all vertices and edges from the graph."""
self
.
__check_perms
(
"del_vertex"
)
self
.
__check_perms
(
"del_edge"
)
self
.
__graph
.
Clear
()
def
clear_edges
(
self
):
"""Remove all edges from the graph."""
self
.
__check_perms
(
"del_edge"
)
self
.
__graph
.
ClearEdges
()
# Internal property maps
...
...
src/graph_tool/search/__init__.py
View file @
fa6816e0
...
...
@@ -97,36 +97,6 @@ __all__ = ["bfs_search", "BFSVisitor", "dfs_search", "DFSVisitor",
"StopSearch"
]
class
VisitorWrapper
(
object
):
def
__init__
(
self
,
g
,
visitor
,
edge_members
,
vertex_members
):
self
.
visitor
=
visitor
self
.
g
=
g
self
.
edge_members
=
set
(
edge_members
)
self
.
vertex_members
=
set
(
vertex_members
)
def
__getattr__
(
self
,
attr
):
try
:
orig_attr
=
self
.
visitor
.
__getattribute__
(
attr
)
except
AttributeError
:
return
object
.
__getattribute__
(
self
,
attr
)
if
callable
(
orig_attr
):
def
wrapped_visitor_member
(
*
args
,
**
kwargs
):
old_perms
=
dict
(
self
.
g
.
_Graph__perms
)
perms
=
{
"del_vertex"
:
False
,
"del_edge"
:
False
,
"add_edge"
:
False
}
if
attr
in
self
.
edge_members
:
perms
.
update
({
"del_edge"
:
True
,
"add_edge"
:
True
})
elif
attr
in
self
.
vertex_members
:
perms
.
update
({
"add_vertex"
:
False
})
self
.
g
.
_Graph__perms
.
update
(
perms
)
try
:
ret
=
orig_attr
(
*
args
,
**
kwargs
)
finally
:
self
.
g
.
_Graph__perms
.
update
(
old_perms
)
return
ret
return
wrapped_visitor_member
else
:
return
orig_attr
class
BFSVisitor
(
object
):
r
"""A visitor object that is invoked at the event-points inside the
:func:`~graph_tool.search.bfs_search` algorithm. By default, it performs no
...
...
@@ -308,10 +278,6 @@ def bfs_search(g, source, visitor=BFSVisitor()):
.. [bfs-wikipedia] http://en.wikipedia.org/wiki/Breadth-first_search
"""
visitor
=
VisitorWrapper
(
g
,
visitor
,
[
"initialize_vertex"
,
"examine_vertex"
,
"finish_vertex"
],
[
"initialize_vertex"
])
try
:
libgraph_tool_search
.
bfs_search
(
g
.
_Graph__graph
,
int
(
source
),
visitor
)
...
...
@@ -539,10 +505,6 @@ def dfs_search(g, source, visitor=DFSVisitor()):
.. [dfs-wikipedia] http://en.wikipedia.org/wiki/Depth-first_search
"""
visitor
=
VisitorWrapper
(
g
,
visitor
,
[
"initialize_vertex"
,
"discover_vertex"
,
"finish_vertex"
,
"start_vertex"
],
[
"initialize_vertex"
])
try
:
libgraph_tool_search
.
dfs_search
(
g
.
_Graph__graph
,
int
(
source
),
visitor
)
...
...
@@ -811,10 +773,6 @@ def dijkstra_search(g, source, weight, visitor=DijkstraVisitor(), dist_map=None,
.. [dijkstra-wikipedia] http://en.wikipedia.org/wiki/Dijkstra's_algorithm
"""
visitor
=
VisitorWrapper
(
g
,
visitor
,
[
"initialize_vertex"
,
"examine_vertex"
,
"finish_vertex"
],
[
"initialize_vertex"
])
if
visitor
is
None
:
visitor
=
DijkstraVisitor
()
if
dist_map
is
None
:
...
...
@@ -1078,8 +1036,6 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(),
.. [bellman-ford-wikipedia] http://en.wikipedia.org/wiki/Bellman-Ford_algorithm
"""
visitor
=
VisitorWrapper
(
g
,
visitor
,
[],
[])
if
dist_map
is
None
:
dist_map
=
g
.
new_vertex_property
(
weight
.
value_type
())
if
pred_map
is
None
:
...
...
@@ -1537,10 +1493,6 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
.. [astar-wikipedia] http://en.wikipedia.org/wiki/A*_search_algorithm
"""
visitor
=
VisitorWrapper
(
g
,
visitor
,
[
"initialize_vertex"
,
"examine_vertex"
,
"finish_vertex"
],
[
"initialize_vertex"
])
if
dist_map
is
None
:
dist_map
=
g
.
new_vertex_property
(
weight
.
value_type
())
if
pred_map
is
None
:
...
...
@@ -1572,9 +1524,6 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
try
:
if
not
implicit
:
g
.
_Graph__perms
.
update
({
"del_vertex"
:
False
,
"del_edge"
:
False
,
"add_edge"
:
False
})
libgraph_tool_search
.
astar_search
(
g
.
_Graph__graph
,
int
(
source
),
_prop
(
"v"
,
g
,
dist_map
),
_prop
(
"v"
,
g
,
pred_map
),
...
...
@@ -1587,19 +1536,13 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
elif
cost_map
.
value_type
()
!=
dist_map
.
value_type
():
raise
ValueError
(
"The cost_map value type must be the same as"
+
" dist_map."
)
g
.
_Graph__perms
.
update
({
"del_vertex"
:
False
})
libgraph_tool_search
.
astar_search_implicit
\
(
g
.
_Graph__graph
,
int
(
source
),
_prop
(
"v"
,
g
,
dist_map
),
_prop
(
"v"
,
g
,
pred_map
),
_prop
(
"v"
,
g
,
cost_map
),
_prop
(
"e"
,
g
,
weight
),
visitor
,
compare
,
combine
,
zero
,
infinity
,
h
)
except
StopSearch
:
g
.
_Graph__perms
.
update
({
"del_vertex"
:
True
,
"del_edge"
:
True
,
"add_edge"
:
True
})
finally
:
g
.
_Graph__perms
.
update
({
"del_vertex"
:
True
,
"del_edge"
:
True
,
"add_edge"
:
True
})
pass
return
dist_map
,
pred_map
...
...
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