Skip to content
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

Should Graph / AdjacencyMap have StarSemiring instances #169

Open
dalaing opened this issue Feb 14, 2019 · 4 comments
Open

Should Graph / AdjacencyMap have StarSemiring instances #169

dalaing opened this issue Feb 14, 2019 · 4 comments

Comments

@dalaing
Copy link
Contributor

dalaing commented Feb 14, 2019

I was reading this before I got a chance to properly look at alga, and was pretty happy to see the StarSemiring class in Algebra.Graph.Label.

Would there be interest in adding instances of that for Algebra.Graph.Labelled and Algebra.Graph.Labelled.AdjacencyMap? I might be able to squirrel some time away to work on that.

(I'm also staring at the hint at the end of that post about using eliminants to speed up shortest path calculations between two points, and am keen to play around with that at some point).

@dalaing
Copy link
Contributor Author

dalaing commented Feb 14, 2019

Hmm. I've looked at this a little, and it seems like the post I linked is able to implement one because of the representation that they have chosen for matrices, and that is quite different.

I can see that there might be the ability to do something like storing a value to add to the self loops:

data AdjacencyMap e a = AM {
    -- | The /adjacency map/ of an edge-labelled graph: each vertex is
    -- associated with a map from its direct successors to the corresponding
    -- edge labels.
    adjacencyMap :: Map a (Map a e)
  , selfLoopAddition :: e  
  }

so that you can define:

one = AdjacencyMap mempty one

but I don't know how much that would complicate everything else.

I'll ponder some more.

@snowleopard
Copy link
Owner

Could you clarify how you plan to make use of the StarSemiring Graph instance? If it is just for computing the closure, then you can simply use the closure function. Or are you planning to label edges of some other graph with graphs? :)

@dalaing
Copy link
Contributor Author

dalaing commented Feb 14, 2019

Hmm, on reflection I think I just like the idea of expressing graphs using the Semigroup / Monoid / Semiring / StarSemiring / Dioid heirarchy, where everything is lawful.

It might be too much of a breaking change to shift away from the not-quite-a-ring Num instance though. Maybe I should shift all of my pondering over to the eliminant stuff :)

@snowleopard
Copy link
Owner

snowleopard commented Feb 15, 2019

We could probably have an instance like this:

  • zero = empty
  • <+> = overlay
  • <.> = compose
  • one = identity -- where identity :: Graph a contains all vertices of the type a, each with a self-loop

I agree that such an instance is nice, because it makes the whole star semiring story complete, but I just don't see any practical use for it yet. But maybe there is! :)

@snowleopard snowleopard changed the title Should Graph / AdjacencyMatrix have StarSemiring instanes Should Graph / AdjacencyMap have StarSemiring instances May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants