views:

401

answers:

2

Is there a good library (or wrapper to Java library) for graphs, and/or graph algorithms in scala?

This one seems to be quite dead. This is an example for the Dijkstra algorithm in scala, but I'm looking for a library a-la JGraphT.

+3  A: 

Why not Jung ? and also Piccolo2D for graphics? (both JVM based).

sw
@sw: Jung doesn't have special Scala bindings does it? One can of course use any Java graph library.
Rex Kerr
@Rex_Kerr you can import every Java class, why do you need a special binding?
sw
@sw because those bindings can interact better with scala's structures, such as lambda expressions (for instance g.nodes.forall(_.weight > 10))
Elazar Leibovich
+4  A: 

We have developed a small graph library for the apparat project. You can take a look at it here. It is not purely functional and not a zipper graph but does a good job for us. You get also mutable and immutable graphs.

Here is a simple example for graph creation:

implicit val factory = DefaultEdge[String](_, _)
val G = Graph(
  "Entry" -> "A",
  "A" -> "B",
  "B" -> "C",
  "B" -> "D",
  "D" -> "F",
  "F" -> "E",
  "E" -> "F",
  "E" -> "C",
  "C" -> "A",
  "C" -> "Exit")
G.dotExport to Console.out

Finding SCCs and subcomponents

G.sccs foreach println
G.sccs map { _.entry } foreach println
G.sccs filter { _.canSearch } map { _.subcomponents } foreach { _ foreach println }

Traversal

for(x <- G.topsort) println(x)
for(x <- G.dft(y)) println(x)

The current drawback is that the library is supporting only invariant types and not feature complete for a whole graph library.

Joa Ebert