weighted graph to json

45 views
Skip to first unread message

Sebastian Törnqvist

unread,
Oct 10, 2018, 5:50:32 AM10/10/18
to scala-graph
Hello,

I have a graph which I define as follows.
val smallSimGraph: Graph[Int, WUnDiEdge] = Graph(
  WUnDiEdge(1,2)(0.9), WUnDiEdge(1,3)(0.7), WUnDiEdge(1,4)(0.2), WUnDiEdge(1,5)(0.05),
  WUnDiEdge(2,3)(0.85), WUnDiEdge(2,4)(0.05), WUnDiEdge(2,5)(0.2),
  WUnDiEdge(3,4)(0.05), WUnDiEdge(3,5)(0.15),
  WUnDiEdge(4,5)(0.9)
)

From this I want to output it in a json format and define the following descriptor.
val channelDescriptor = new NodeDescriptor(typeId = "Channels") {
  def id(node: Any) = node.toString
}
val quickJson = new Descriptor[Int] (
  channelDescriptor,
  WUnDi.descriptor[Int](Some(new WEdgeSerializer))
)
However, once I try to format the graph via this descriptor I get the error displayed below. I find myself a bit lost here (not too surprising since I started using this library about two days ago), shouldn't the WEdgeSerializer be sufficient for this use case? 

java.lang.NoSuchMethodError: scalax.collection.GraphEdge$UnDiEdge.weight()J
at scalax
.collection.io.json.descriptor.WEdgeDescriptor.toParameters(EdgeDescriptor.scala:126)
...

Thanks in advance,

Best Regards,
Sebastian

Peter Empen

unread,
Oct 12, 2018, 3:04:00 AM10/12/18
to scala-graph
After copying your code and calling

println(smallSimGraph.toJson(quickJson))
I get
{"nodes":[4,1,3,5,2],"edges":[["3","5",0.15],["1","2",0.9],["4","5",0.9],["1","4",0.2],["1","5",0.05],["3","4",0.05],["1","3",0.7],["2","4",0.05],["2","5",0.2],["2","3",0.85]]}

Please check your library dependencies.
Reply all
Reply to author
Forward
0 new messages