Sockem is a simple, low-overhead, easy-to-use Scala DSL/library that provides mechanisms to create and manipulate network graphs. The library is intended to provide an API to generate vertices, edges, and the graph itself based on a simple language notation, as well as allow for multiple types of graph algorithm calculations (i.e. shortest-path first, traveling salesman problems, path finding, etc).
The library is also intended to be small, compact, and succinct, without the overhead of needless abstraction and confusing references (ala scala-graph).
-
Add these lines to your build.sbt.
resolvers += "kndl" at "http://mvn.kndl.org/maven2"
libraryDependencies ++= Seq(
"org.kndl" %% "sockem" % "0.4"
)
-
Example usage below:
// create a graph
val g = G("graph")
// create 3 vertices and add 2 edges between vertex1 and vertex2 and vertex1 and vertex3 with weights 5
g ++ V("vertex1") ++ V("vertex2") ++ V("vertex3") +| ("vertex1", "vertex2", 5) +| ("vertex1","vertex3",5)
// visits all vertices in the graph and applies "value" to "key"
g.visitAll(g) { vertex => vertex.set("key","value") }
// traverses the shortest path of nodes from start to end
val (distance,path) = g.traverseShortestPath(V("vertex1"),V("vertex2"))