-
Notifications
You must be signed in to change notification settings - Fork 65
ExecuteDFS (generic depth first search) #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 60 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
55b4760
Update year in README
james-d-mitchell 972aa22
Fix bug in CHANGELOG.md
james-d-mitchell cb26213
added the Book Graph
LRacine c7376d9
works
LRacine c3a1b25
adding more parameters
LRacine 976f5db
changed variable parent
LRacine a4a4be7
all good
LRacine 5b44346
Working after JDM broke everything
james-d-mitchell e478973
Not Working after JDM broke everything
james-d-mitchell 67ce8d2
updated version that passes all but the large test case
LRacine a92aa88
Another approach doesn't work
james-d-mitchell 80864f0
Working
james-d-mitchell f76b728
Fix linting
james-d-mitchell 6755e84
Replace part of DominatorTree + VerticesReachableFrom
james-d-mitchell 054050f
Prelim C version
james-d-mitchell 4ced3e8
Prelim C version x 2
james-d-mitchell 51b6aa0
testing new things
LRacine 197e24a
Merge https://github.com/james-d-mitchell/Digraphs into new-dfs
LRacine 4df9bfe
Merge branch 'new-dfs' of https://github.com/james-d-mitchell/Digraph…
LRacine d4b5a6b
Add the files
james-d-mitchell 27cd4c9
Merge branch 'new-dfs' of https://github.com/james-d-mitchell/Digraph…
LRacine a95f5d2
so far what we have replaced
LRacine 4fdec16
changed isAcyclicDigraph
LRacine 1df8f45
removed the random files
LRacine 163ec48
changed IsAntisymmetricDigraph
LRacine 176e61f
changed DigraphLongestDistanceFromVertex
LRacine 29dc997
changed DigraphTopologicalSort
LRacine 718aab3
changed DigraphPath
LRacine fc14567
Changed the _C Digraph version
LRacine a0b5b18
fix gaplint
LRacine d4cdc50
removed whitespace
LRacine 68f58d6
Merge branch 'master' of https://github.com/digraphs/Digraphs into ne…
LRacine 3ea0590
replaced the undirected spanning tree and changed the reachable verte…
LRacine 2626b0a
improved the rec placement
LRacine 9383335
updated the psuedo
LRacine 00afd60
added in the stoppers and coverted some methods
LRacine 804da96
Merge branch 'master' of https://github.com/digraphs/Digraphs into Fi…
LRacine 5bcbf23
added the tests, documentation, checks in C, declared the functions a…
LRacine 7656429
passes the linter
LRacine e78bcdc
added an additional test
LRacine 96006cd
fixed the documentation
LRacine 4b6b7b9
Set IsSymmetricDigraph for Graph6/Sparse6 digraphs
wilfwilson 2baf42c
Stop using obsolete autoconf macros
fingolfin 201a2e2
fixed a test issue (set equality)
LRacine 48c169e
fixed linting
LRacine 2f76d58
Merge branch 'master' into new-dfs-adapted
LRacine bd027ce
fixed coverage
LRacine 7ae7123
Merge branch 'new-dfs-adapted' of https://github.com/LRacine/Digraphs…
LRacine 5bcdae4
removed a bit of comment accidently
LRacine 3fef2a8
Merge branch 'master' into new-dfs-adapted
wilfwilson a519cc0
Merge branch 'master' into new-dfs-adapted
wilfwilson 2a2c866
Merge branch 'master' into new-dfs-adapted
wilfwilson 2310751
Merge branch 'master' into new-dfs-adapted
wilfwilson 2408daf
Merge branch 'master' of https://github.com/digraphs/Digraphs into ne…
LRacine fcc53af
fixed the C coverage and the bug that was causing a gasman error
LRacine c084a8e
Merge branch 'new-dfs-adapted' of https://github.com/LRacine/Digraphs…
LRacine da0a9aa
added back the assert for the C function and fixed the IsAntisymmetri…
LRacine c64d54f
fixed c linting
LRacine 653376d
changed documentation with suggestions by marina
LRacine 2103189
changed the documentation
LRacine 7704cd4
changed the doc tags
LRacine a784b93
resolved the issues that James mentioned
LRacine 3e6dacd
Merge branch 'master' into new-dfs-adapted
LRacine 31393b8
Merge branch 'master' of https://github.com/digraphs/Digraphs into ne…
LRacine 383c8db
Merge branch 'new-dfs-adapted' of https://github.com/LRacine/Digraphs…
LRacine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1321,7 +1321,7 @@ gap> D := CompleteDigraph(5); | |||||
| gap> VerticesReachableFrom(D, 1); | ||||||
| [ 2, 1, 3, 4, 5 ] | ||||||
| gap> VerticesReachableFrom(D, 3); | ||||||
| [ 1, 2, 3, 4, 5 ] | ||||||
| [ 1, 3, 2, 4, 5 ] | ||||||
| gap> D := EmptyDigraph(5); | ||||||
| <immutable empty digraph with 5 vertices> | ||||||
| gap> VerticesReachableFrom(D, 1); | ||||||
|
|
@@ -1964,3 +1964,156 @@ gap> ModularProduct(NullDigraph(0), CompleteDigraph(10)); | |||||
| </Description> | ||||||
| </ManSection> | ||||||
| <#/GAPDoc> | ||||||
|
|
||||||
| <#GAPDoc Label="NewDFSRecord"> | ||||||
| <ManSection> | ||||||
| <Oper Name="NewDFSRecord" Arg="digraph"/> | ||||||
| <Returns>A record.</Returns> | ||||||
| <Description> | ||||||
| This record contains three lists (parent, preorder and postorder) with their length | ||||||
| equal to the number of verticies in the <A>digraph</A>. Each index of the lists maps to the | ||||||
| vertex within the <A>digraph</A> equating to the vertex number. These lists store | ||||||
| the following: | ||||||
| <List> | ||||||
| <Item><E>parent</E>: at each index, the parent of the vertex is stored</Item> | ||||||
| <Item><E>preorder</E>: at each index, the preorder number (order in which the vertex is visited) | ||||||
| is stored</Item> | ||||||
| <Item><E>postorder</E>: at each index, the postorder number (order in which the vertex is backtracked on) | ||||||
| is stored</Item> | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| </List> | ||||||
|
|
||||||
| The record also stores a further 4 attributes. | ||||||
| <List> | ||||||
| <Item><E>current</E>: the current vertex that is being visited</Item> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use mark here too? |
||||||
| <Item><E>child</E>: the child of the current vertex</Item> | ||||||
| <Item><E>graph</E>: the <A>digraph</A></Item> | ||||||
| <Item><E>stop</E>: whether to stop the depth first search</Item> | ||||||
| </List> | ||||||
|
|
||||||
| Initially, the current and child attributes will have -1 values and the lists (parent, | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| preorder and postorder) will have -1 values at all of their indicies as no vertex has | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| been visited. The stop attribute will initially be false. | ||||||
| <E>This record should be passed into the ExecuteDFS function.</E> | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| See <Ref Func="ExecuteDFS" Label="for a record, object, integer and 4 functions"/>. | ||||||
| <Example><![CDATA[ | ||||||
| gap> record := NewDFSRecord(CompleteDigraph(2)); | ||||||
| rec( child := -1, current := -1, | ||||||
| graph := <immutable complete digraph with 2 vertices>, | ||||||
| parent := [ -1, -1 ], postorder := [ -1, -1 ], | ||||||
| preorder := [ -1, -1 ], stop := false ) | ||||||
| gap> record.preorder; | ||||||
| [ -1, -1 ] | ||||||
| gap> record.postorder; | ||||||
| [ -1, -1 ] | ||||||
| gap> record.stop; | ||||||
| false | ||||||
| gap> record.parent; | ||||||
| [ -1, -1 ] | ||||||
| gap> record.child; | ||||||
| -1 | ||||||
| gap> record.current; | ||||||
| -1 | ||||||
| gap> record.graph; | ||||||
| <immutable complete digraph with 2 vertices> | ||||||
| ]]></Example> | ||||||
| </Description> | ||||||
| </ManSection> | ||||||
| <#/GAPDoc> | ||||||
|
|
||||||
| <#GAPDoc Label="DFSDefault"> | ||||||
| <ManSection> | ||||||
| <Oper Name="DFSDefault" Arg="record, data"/> | ||||||
| <Description> | ||||||
| This is a default function to be passed into the ExecuteDFS function. | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| This does nothing and can be used in place of the PreOrderFunc, PostOrderFunc, | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| AncestorFunc and/or CrossFunc of the ExecuteDFS function. | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| See <Ref Func="ExecuteDFS" Label="for a record, object, integer and 4 functions"/>. | ||||||
| <Example><![CDATA[ | ||||||
| gap> PreOrderFunc := function(record, data) | ||||||
| > data.num_vertices := data.num_vertices + 1; | ||||||
| > end;; | ||||||
| gap> record := NewDFSRecord(CompleteDigraph(2));; | ||||||
| gap> data := rec(num_vertices := 0);; | ||||||
| gap> ExecuteDFS(record, data, 1, PreOrderFunc, | ||||||
| > DFSDefault, DFSDefault, DFSDefault); | ||||||
| gap> data; | ||||||
| rec( num_vertices := 2 ) | ||||||
| gap> record := NewDFSRecord(CompleteDigraph(2));; | ||||||
| gap> ExecuteDFS(record, [], 1, DFSDefault, | ||||||
| > DFSDefault, DFSDefault, DFSDefault); | ||||||
| gap> record; | ||||||
| rec( child := 1, current := 1, | ||||||
| graph := <immutable complete digraph with 2 vertices>, | ||||||
| parent := [ 1, 1 ], postorder := [ 2, 1 ], preorder := [ 1, 2 ], | ||||||
| stop := false ) | ||||||
| ]]></Example> | ||||||
| </Description> | ||||||
| </ManSection> | ||||||
| <#/GAPDoc> | ||||||
|
|
||||||
| <#GAPDoc Label="ExecuteDFS"> | ||||||
| <ManSection> | ||||||
| <Oper Name="ExecuteDFS" Arg="record, data, start, PreOrderFunc, PostOrderFunc, AncestorFunc, | ||||||
| CrossFunc"/> | ||||||
| <Description> | ||||||
| This performs a full depth first search from the <A>start</A> vertex (where <A>start</A> is a vertex within the graph). | ||||||
| The depth first search can be terminated by changing the <A>record</A>.stop attribute to true in the | ||||||
| <A>PreOrderFunc</A>, <A>PostOrderFunc</A>, <A>AncestorFunc</A> or <A>CrossFunc</A> functions. | ||||||
| ExecuteDFS takes 7 arguments: | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| <List> | ||||||
| <Item><A>record</A>: the depth first search record (created using NewDFSRecord)</Item> | ||||||
| <Item><A>data</A>: an object that you want to manipulate in the functions passed.</Item> | ||||||
| <Item><A>start</A>: the vertex where we begin the depth first search.</Item> | ||||||
| <Item><A>PreOrderFunc</A>: this function is called when a vertex is first visited. This vertex | ||||||
| is stored in <A>record</A>.current</Item> | ||||||
| <Item><A>PostOrderFunc</A>: this function is called when a vertex has no more unvisited children | ||||||
| causing us to backtrack. This vertex is stored in <A>record</A>.child and its parent is stored | ||||||
| in <A>record</A>.current</Item> | ||||||
| <Item><A>AncestorFunc</A>: this function is called when (<C><A>record</A>.current</C>, | ||||||
| <C><A>record</A>.child</C>) is an edge and <C><A>record</A>.child</C> is an ancestor of <C><A>record</A>.current</C>. An ancestor here means that | ||||||
| <C><A>record</A>.child</C> is on the same branch as <C><A>record</A>.current</C> but was visited prior to <C><A>record</A>.current</C></Item> | ||||||
| <Item><A>CrossFunc</A>: this function is called when (<C><A>record</A>.current</C>, | ||||||
| <C><A>record</A>.child</C>) is an edge and <C><A>record</A>.child</C> has been visited before <C><A>record</A>.current</C> | ||||||
| and it is not an ancestor of <C><A>record</A>.current</C></Item> | ||||||
| </List> | ||||||
| Note that this function only performs a depth first search on the vertices reachable from <A>start</A>. | ||||||
| It is also important to note that all functions passed need to accept 2 arguments | ||||||
| (<A>record</A>, <A>data</A>). Finally, for the <A>start</A> vertex, its parent is itself and the <A>PreOrderFunc</A> | ||||||
|
LRacine marked this conversation as resolved.
Outdated
|
||||||
| will be called on it. | ||||||
| See <Ref Oper="NewDFSRecord"/>. | ||||||
| <Example><![CDATA[ | ||||||
| gap> record := NewDFSRecord(CycleDigraph(10));; | ||||||
| gap> ExecuteDFS(record, [], 1, DFSDefault, | ||||||
| > DFSDefault, DFSDefault, DFSDefault); | ||||||
| gap> record.preorder; | ||||||
| [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] | ||||||
| gap> record := NewDFSRecord(CompleteDigraph(10));; | ||||||
| gap> data := rec(cycle_vertex := 0);; | ||||||
| gap> AncestorFunc := function(record, data) | ||||||
| > record.stop := true; | ||||||
| > data.cycle_vertex := record.child; | ||||||
| > end;; | ||||||
| gap> ExecuteDFS(record, data, 1, DFSDefault, | ||||||
| > DFSDefault, AncestorFunc, DFSDefault); | ||||||
| gap> record.stop; | ||||||
| true | ||||||
| gap> data.cycle_vertex; | ||||||
| 1 | ||||||
| gap> record.preorder; | ||||||
| [ 1, 2, 3, -1, -1, -1, -1, -1, -1, -1 ] | ||||||
| gap> record := NewDFSRecord(Digraph([[2, 3], [4], [5], [], [4]]));; | ||||||
| gap> CrossFunc := function(record, data) | ||||||
| > record.stop := true; | ||||||
| > Add(data, record.child); | ||||||
| > end;; | ||||||
| gap> data := [];; | ||||||
| gap> ExecuteDFS(record, data, 1, DFSDefault, | ||||||
| > DFSDefault, DFSDefault, CrossFunc); | ||||||
| gap> record.stop; | ||||||
| true | ||||||
| gap> data; | ||||||
| [ 4 ] | ||||||
| ]]></Example> | ||||||
| </Description> | ||||||
| </ManSection> | ||||||
| <#/GAPDoc> | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.