Package sage :: Package combinat :: Module graph_path
[hide private]
[frames] | no frames]

Module graph_path

source code


Paths in Directed Acyclic Graphs



Classes [hide private]
  GraphPaths_common
  GraphPaths_all
EXAMPLES:...
  GraphPaths_t
  GraphPaths_s
  GraphPaths_st
EXAMPLES:...
Functions [hide private]
 
GraphPaths(g, source=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., target=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Returns the combinatorial class of paths in the directed acyclic graph g.
source code
Function Details [hide private]

GraphPaths(g, source=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., target=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Returns the combinatorial class of paths in the
directed acyclic graph g.

EXAMPLES:
    sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)

  If source and target are not given, then the returned class contains all
  paths (including trivial paths containing only one vertex).
  
    sage: p = GraphPaths(G); p
    Paths in Multi-digraph on 5 vertices
    sage: p.count()
    37
    sage: p.random_element()
    [1, 2, 3, 4, 5]
    
    
  If the source is specified, then the returned class contains all of the paths
  starting at the vertex source (including the trivial path).

     sage: p = GraphPaths(G, source=3); p
     Paths in Multi-digraph on 5 vertices starting at 3
     sage: p.list()
     [[3], [3, 4], [3, 4, 5], [3, 4, 5]]


  If the target is specified, then the returned class contains all of the paths
  ending at the vertex target (including the trivial path).

    sage: p = GraphPaths(G, target=3); p
    Paths in Multi-digraph on 5 vertices ending at 3
    sage: p.count()
    5
    sage: p.list()
    [[3], [1, 3], [2, 3], [1, 2, 3], [1, 2, 3]]


  If both the target and source are specified, then the returned class
  contains all of the paths from source to target.

    sage: p = GraphPaths(G, source=1, target=3); p
    Paths in Multi-digraph on 5 vertices starting at 1 and ending at 3
    sage: p.count()
    3
    sage: p.list()
    [[1, 2, 3], [1, 2, 3], [1, 3]]

  Note that G must be a directed acyclic graph.

    sage: G = DiGraph({1:[2,2,3,5], 2:[3,4], 3:[4], 4:[2,5,7], 5:[6]}, multiedges=True)
    sage: GraphPaths(G)
    Traceback (most recent call last):
    ...
    TypeError: g must be a directed acyclic graph