scala-graph weighted DiEdge based graph json serializer

40 views
Skip to first unread message

Anirudh Vyas

unread,
Jun 4, 2018, 9:14:10 PM6/4/18
to scala-graph
I am trying to do as follows - 
private val e1 = (a ~%> b) (1.0)
private val e2 = (b ~%> c) (2.0)
private val cyclicalEdge = (c ~%> a) (3.0)
.
g.add(e1)
g.add(e2)
g.add(cyclicalEdge)
private val mainDesc = new Descriptor[SomeNodeType](
  defaultNodeDescriptor
= taskNodeDescriptor,
  defaultEdgeDescriptor
= WDi.descriptor[SomeNodeType]()
)
private val stringified = g.toJson(mainDesc)
import net.liftweb.json._

val pretty = prettyRender(JsonParser.parse(stringified))
println(s"################# \n $pretty \n ################## \n")
import scalax.collection.io.json._

val tasks: Graph[SavedQueryTaskNode, WDiEdge] = Graph.fromJson[SomeNodeType, WDiEdge](stringified, mainDesc)
println(s"\n###############################################\n TASKS \n ############################################### \n $tasks")
println("traversing graph now ... ")

// you can find if there's a cycle
//println(s"is there a cycle in the graph ?? ${tasks.findCycle}")
def edgeOrdering = tasks.EdgeOrdering(tasks.Edge.WeightOrdering.reverse.compare)

val traverser = (tasks get createSavedQueryTaskNode).innerNodeTraverser.withOrdering(edgeOrdering)
println(s"traverser.toList ### = ${traverser.toList}")


My objective in the end is to traverse graph on ordering of weights of edges. I have one problem - I cannot serialize a weighted graph and I cannot find an example to do so - can someone help? perhaps Peter?

Thanks
Anirudh

Anirudh Vyas

unread,
Jun 4, 2018, 9:15:02 PM6/4/18
to scala-graph
BTW - ignore terminology of this - tasks get createSavedQueryTaskNode <-- assume that createSavedQueryTaskNode is root Node.

Anirudh Vyas

unread,
Jun 7, 2018, 10:35:03 AM6/7/18
to scala-graph
Anyone? I need to be able to traverse the graph in topological order and execute each node, one at a time.

Peter Empen

unread,
Jun 9, 2018, 5:51:00 AM6/9/18
to scala-graph
Hi Anirudh,

concerning JSON serialization of weighted edges, did you check out TJson.scala?
Did you get traversing order right, if not, what are you missing?

Peter
Reply all
Reply to author
Forward
0 new messages