Dear all,
I have to model the following problem. I have N nodes, which are connected according to a Boolean expression.
I need to implement the following for all node of type != T and without predecessors, ensure that there is one and only one path to a node of type T. I could model this by using a DiEdge and that worked correctly, my problem is that the the pathUntil returns a single optional path and not a collection. In a later stage , I need to walk over the path in reverse order (from the end to the beginning)
Is there a simple way to do this?
Best Regards
def findAllPathFrom[N, E[X] <: EdgeLikeIn[X]](graph:Graph[N,E])(node:graph.NodeT, exitCondition: graph.NodeT => Boolean):Seq[graph.Path] = {@tailrecdef findAllPathFrom(node:graph.NodeT, exitCondition: graph.NodeT => Boolean, previousFoundPath:Seq[graph.Path]):Seq[graph.Path] = {val newPath = node pathUntil( node => exitCondition(node), node => ! previousFoundPath.exists(_.endNode == node))newPath match{case Some(path) => findAllPathFrom(node, exitCondition, previousFoundPath:+path)case None => previousFoundPath}}findAllPathFrom(node,exitCondition,Seq.empty[graph.Path])}And now the game is simple, because I can simply filter the initial nodes and run my function. However, the following questions stay open for me:- Would it not make sense to have a pathUntilS in the standard library?- I need , later, to follow the path inversely, from end to beginning. Is this feasible with minimum performance cost? Or should I make a unidrected graph?Thank you for your helpBest RegardsEdmondo