scala的图形库 [英] graph library for scala

查看:141
本文介绍了scala的图形库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有一个好的库(或者Java库的封装) code.google.com/p/scala-graphs/rel =noreferrer>这个似乎已经死了。 这是在斯卡拉的Dijkstra算法的例子,但我正在寻找library a-la JGraphT

解决方案

我们为设备项目开发了一个小型图库。你可以看看它这里。它不是纯粹的功能,也不是拉链图,但对我们来说做得很好。您还可以获得可变和不可变的图形。



以下是创建图形的一个简单示例:

 隐式val factory = DefaultEdge [String](_,_)
val G =图表(
Entry - >A,
A - >B,
B - >C,
B - >D,
D - >F,
F - >E,
E - >F,
E - >C,
C - > A,
C - >退出)
G.dotExport给Console.out

查找SCC和子组件

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

$ (x <-Gtopsort)println(x)

遍历

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



目前的缺点是该库仅支持不变类型,并且对于整个g不具有完整性raph库。

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.

解决方案

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.

这篇关于scala的图形库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆