The main predicate, that is called "topoSort/2", reads a graph info as the first input parameter and return the sorted nodes as the second parameter.
The graph info is represented by adjacency list.
Implement the topological sort algorithm with Prolog and return the sorted vertices' IDs as a list as the following example shows.
Example:
The given graph represented as adjacency list:
[[1, 2, 3, 4], [2, 4, 5], [3, 6], [4, 3, 6, 7], [5, 4, 7], [6], [7, 6]]
Query:
?- topoSort ([[1, 2, 3, 4], [2, 4, 5], [3, 6], [4, 3, 6, 7], [5, 4, 7], [6], [7, 6]], X).
Output:
X = [1, 2, 5, 4, 3, 7, 6] ;
X = [1, 2, 5, 4, 7, 3, 6].
Ready to do this job fast. So far I have only some closed projects. Maybe your project will be the next?
From the Prolog & Swi-Prolog, of course, familiar.