• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

A.61 library(ugraphs): Graph manipulation library
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(ugraphs): Graph manipulation library
          • vertices/2
          • vertices_edges_to_ugraph/3
          • add_vertices/3
          • del_vertices/3
          • add_edges/3
          • ugraph_union/3
          • del_edges/3
          • edges/2
          • transitive_closure/2
          • transpose_ugraph/2
          • compose/3
          • ugraph_layers/2
          • top_sort/2
          • neighbors/3
          • neighbours/3
          • connect_ugraph/3
          • complement/2
          • reachable/3
    • Packages
Availability::- use_module(library(ugraphs)).(can be autoloaded)
Source[semidet]ugraph_layers(Graph, -Layers)
[semidet]top_sort(+Graph, -Sorted)
Sort vertices topologically. Layers is a list of lists of vertices where there are no edges from a layer to an earlier layer. The predicate top_sort/2 flattens the layers using append/2.

These predicates fail if Graph is cyclic. If Graph is not connected, the sub-graphs are individually sorted, where the root of each subgraph is in the first layer, the nodes connected to the roots in the second, etc.

?- top_sort([1-[2], 2-[3], 3-[]], L).
L = [1, 2, 3]
Compatibility
- The original version of this library provided top_sort/3 as a difference list version of top_sort/2. We removed this because the argument order was non-standard. Fixing causes hard to debug compatibility issues while we expect top_sort/3 was rarely used. A backward compatible top_sort/3 can be defined as
top_sort(Graph, Tail, Sorted) :-
    top_sort(Graph, Sorted0),
    append(Sorted0, Tail, Sorted).

The original version returned all vertices in a layer in reverse order. The current one returns them in standard order of terms, i.e., each layer is an ordered set.
- ugraph_layers/2 is a SWI-Prolog specific addition to this library.

ClioPatria (version V3.1.1-51-ga0b30a5)