Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
3927ddf7
Commit
3927ddf7
authored
Jul 13, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of /cygdrive/c/Users/BRAM/Documents/Documenten/Projecten/todo.py.bundle
parents
e393029a
8c47b843
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
Graph.py
Graph.py
+18
-0
test/GraphTest.py
test/GraphTest.py
+7
-0
No files found.
Graph.py
View file @
3927ddf7
...
...
@@ -149,3 +149,21 @@ class DirectedGraph(object):
if
self
.
is_isolated
(
p_to
):
self
.
remove_node
(
p_to
)
def
transitively_reduce
(
self
):
"""
Performs a transitive reduction on the graph.
"""
removals
=
set
()
for
from_node
,
neighbors
in
self
.
_edges
.
iteritems
():
childpairs
=
\
[(
c1
,
c2
)
for
c1
in
neighbors
for
c2
in
neighbors
if
c1
!=
c2
]
for
pair
in
childpairs
:
if
self
.
has_path
(
pair
[
0
],
pair
[
1
])
\
and
not
self
.
has_path
(
pair
[
0
],
from_node
):
removals
.
add
((
from_node
,
pair
[
1
]))
for
edge
in
removals
:
self
.
remove_edge
(
edge
[
0
],
edge
[
1
])
test/GraphTest.py
View file @
3927ddf7
...
...
@@ -113,3 +113,10 @@ class GraphTest(unittest.TestCase):
self
.
assertFalse
(
self
.
graph
.
has_edge
(
1
,
3
))
self
.
assertFalse
(
self
.
graph
.
has_edge
(
3
,
5
))
self
.
assertFalse
(
self
.
graph
.
has_path
(
1
,
5
))
def
test_transitive_reduce1
(
self
):
self
.
graph
.
transitively_reduce
()
self
.
assertTrue
(
self
.
graph
.
has_edge
(
4
,
3
))
self
.
assertFalse
(
self
.
graph
.
has_edge
(
1
,
3
))
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