Microsoft GraphEngine LIKQ query

576 Views Asked by At

Description

I have a simple directed graph which has two end nodes C,E (sinks) and one starting node A. The Framework i am using is Microsoft's GraphEngine.

GraphGeneration

My TSL File looks like this: A graph node consists of an NodeItem which is just an container with a property Id and Name. The node has OutEdges for outgoing relations and InEdges for incoming releations.

TSL File

I know that there are several graph algorithms like A*, Dijkstra, Floyd Warshall, Bellman–Ford, etc. ... Each of them solves very specific traversal problems. So far so good. But now i am want to learn how to traverse this graph with LIKQ. LIKQ is a Language-Integrated Knowledge Query language. It allows users to query, search, and consume knowledge via graph traversal and lambda expressions in real-time.

Question

What i want to do: Find all the shortest paths between node A and C and node A and E. Is this possible with LIKQ?

This is what i got so far:

 List<PathDescriptor> paths = KnowledgeGraph.StartFrom(start)
            .FollowEdge("OutEdges")
            .VisitNode(_ => Action.Continue)
            .FollowEdge("OutEdges")
            .VisitNode(_ => Action.Continue)
            .FollowEdge("OutEdges")
            .VisitNode(_ => Action.Return)
            .ToList();

I can traverse from A - B - D - E. But this is somehow an manual step to do. Is there any chance to let LIKQ decide how to start from node A and get two paths (to C and E) as a return?

Furthermore i would like to know if a BFS or a DFS could be translated to LIKQ?

VSDebug

Hope someone can bring some light into the dark (: Thank you very much in advance!

Best regards, Phil

1

There are 1 best solutions below

0
On

Currently this is a bit tricky, the fanout search algorithm does not guarantee the order of emitted traversal steps, but shorter paths do get scheduled earlier practically. So if you put Action.Continue & Action.Return in every step, and make a global flag variable so when you hit the target, toggle that bit so every other path reading it could stop, then you will likely get the shortest path.