-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add isAcyclic, topSort, dfs and other graph analysis functions to ToGraph #105
Comments
@fosskers Thanks! I agree, this is a useful function to add. If you don't necessarily need a polymorphic function, the implementation is quite simple: isDag :: Ord a => AdjacencyMap a -> Bool
isDag = isJust . topSort You'll just need to convert your graph data type to With the new |
Ah ha! So it was just a simple thing. And luckily for me, I'm already using From the Haddocks:
Perhaps I should have used my eyes to read 😢 |
No problem :) I'll keep the issue open, to remember to add a few methods to |
isDag :: Graph g => g -> Bool
So |
@fosskers To find the cycle, you can use the Here is one possible way to use is: cycles :: Ord a => AdjacencyMap a -> [AdjacencyMap a]
cycles x = [ induce (`Set.member` c) x | c <- cs ]
where
cs = filter (\c -> Set.size c > 1) $ vertexList (scc x) We obtain the list For example: > cycles $ path [1, 2, 3]
[]
> cycles $ circuit [1, 2, 3]
[edges [(1,2),(2,3),(3,1)]]
> cycles $ circuit [1, 2, 3] + path [3, 4, 5] + circuit [5, 6, 7]
[edges [(1,2),(2,3),(3,1)],edges [(5,6),(6,7),(7,5)]] |
Holy crap that's fantastic. I'm going to try that out right away. |
Alright, looking good! Thanks a lot, once again. |
@fosskers Great! I'll keep this issue open -- |
Woops, my bad. |
* Add comments * Add conversion to adjacency map data types * Minor revision * Extend ToGraph, add isAcyclic See #105 * Fix Haddock warnings * Minor revision * Update the testsuite * Update change log * Add reachability analysis * Fix typo * Fix another typo * Update change log * Optimise edgeCount, drop unnecessary redefinitions in ToGraph Graph instance * Switch to naming consistent with ToGraph * Simplify edgeSet, fix GHC 7.8.4 compile error * Minor revision * Use stars
Or likewise,
isCircular
. Basically, a top-level function to determine if someGraph
type is a DAG or not.As last time (thanks again), I suspect there's some composition of the exposed primitives that "just works", but nothing jumped out at me after a brief scan of the API.
Thoughts?
The text was updated successfully, but these errors were encountered: