Node Labeling

37 views
Skip to first unread message

Sergey Kokorin

unread,
Aug 15, 2018, 10:23:29 AM8/15/18
to scala-graph
Hi, 

I'm trying to mess up with the library somehow but I'm a bit lost. I'm not sure how it should be done properly. I need implement some thing like

def filter(g: Graph[N, E]): Graph[N, E] = {
val labeled: Graph[Labeled[N], E[?]] = label(g)
val filtered = filter(labeled)
val result: Graph[N, E] = removeLabel(filtered)
result
}


So I would like to label nodes do some filtration on edges based on the labels and return subgraph without labels with initial type N. How it could be done in a proper way if possible?

Best Regards,
Sergey

Peter Empen

unread,
Aug 16, 2018, 6:44:33 AM8/16/18
to scala-graph
 Sergey,

to discard labeled edges with a label type of String, you can do for instance:

import scalax.collection.GraphPredef._
import scalax.collection.edge.LDiEdge
import scalax.collection.edge.Implicits._
import scalax.collection.Graph

val g = Graph(1 ~> 2, 1 ~> 3 + "A", 2 ~> 3 + 7)

g -- g.edges.toOuter.collect {
case e @ LDiEdge(s, t, label: String) => e
}
Reply all
Reply to author
Forward
0 new messages