-
Notifications
You must be signed in to change notification settings - Fork 69
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
Explore alternative implementations for AdjacencyMap #141
Comments
Perhaps more generally, it would be nice to be able to provide a bijective map between the "real" node type and a "key" type which is cheaper to store, or has a cheaper (or existent) |
Note that this can be a blocker for moving from |
I will create a prototype |
@snowleopard I finally found some time to start working on this and I'm wondering about operations that combine graphs, e.g. If we define I guess we could combine This is of course if I'm understanding the issue correctly which is to check if this representation of |
Yes.
Actually, I'm not entirely sure my draft above is correct. What we really need to represent here is an isomorphism between vertices
That's right. We know that |
Re-reading what I wrote, I think this goal sounds a bit naive: if it were possible, then we could similarly implement |
No clue but I will try to figure something out. Do you have anything else that I could help with in the meantime? |
Brainstorming a few ideas:
|
@michaelpj Thanks for the ideas! Most likely, we don't really need to make operations like
@Avasil I think it would be great to prototype the most straightforward implementation of this idea that you can come up with and see how well it performs in benchmarks. (As a completely separate issue, you might look into #90 which came up in your recent PR #222.) |
Yes, I agree that querying performance is usually much more relevant. So the relabeling approach might be fine in practice. |
@snowleopard I will try validating @michaelpj ideas first, maybe it can lead us somewhere. :D
It's not clear to me how to modify a It feels like each |
@Avasil Why don't you start with something naive but very simple: just renumber everything (always keeping the indices starting at 0) whenever you do something like |
@snowleopard I managed to implement and benchmark few functions. I plan to add tests now so I can get rid of bugs and then keep trying to optimize. Though any suggestions would be very helpful, currently it's very slow I changed representation a bit: data AdjacencyMapPoc a = AM
{ graph :: AIM.AdjacencyIntMap
, valueMap :: IntMap a
, indexMap :: Map a Int } deriving (Generic)
value :: AdjacencyMapPoc a -> Int -> Maybe a
value g i = IntMap.lookup i (valueMap g)
index :: Ord a => AdjacencyMapPoc a -> a -> Maybe Int
index g a = Map.lookup a (indexMap g) I didn't know how to create Comparison to AdjacencyMap: (with a = Int)
Here's my branch https://github.com/Avasil/alga/blob/adjMap-alternative-impl/src/Algebra/Graph/AdjacencyMapPoc.hs |
I added implementations for
I don't really understand why removing is so fast and BTW which functions are the most interesting to us in this experiment? I could focus on implementing those next |
@Avasil Thanks for the experiment! I don't have time to look at your implementation in detail at the moment, but it's indeed strange that
I think your current selection is great. Perhaps you could also add |
I think the issue with
which doesn't leverage I also tried to compare underlying |
@Avasil Is there a chance to bring the overhead in |
@snowleopard Current implementation of I haven't looked into it yet |
We currently store vertices of type
a
directly in anAdjacencyMap a
, which may lead to poor performance if the correspondingOrd a
instance is slow. One example, which motivated me to record this issue, is the SCC algorithm developed in #128 that producesAdjacencyMap (NonEmpty.AdjacencyMap a)
, i.e. graphs whose vertices are graphs (and graphs are expensive to compare, see #126).An alternative would be to define something like
This is similar to
Data.Graph.graphFromEdges
:http://hackage.haskell.org/package/containers-0.6.0.1/docs/Data-Graph.html#v:graphFromEdges
In this way, we can benefit from the high performance of the underlying
AdjacencyIntMap
yet provide a typed high-level interfaceAdjacencyMap a
to the user.The text was updated successfully, but these errors were encountered: