FindPath

FindPath[g,s,t]

finds a path between vertex s and vertex t in the graph g.

FindPath[g,s,t,k]

finds a path of length at most k between vertex s and vertex t in the graph g.

FindPath[g,s,t,{k}]

finds a path of length exactly k.

FindPath[g,s,t,{kmin,kmax}]

finds a path of length between kmin and kmax.

FindPath[g,s,t,kspec,n]

finds at most n paths.

FindPath[{vw,},]

uses rules vw to specify the graph g.

Details

  • FindPath returns a list of paths from s to t. Each path is given as a list of vertices.
  • FindPath[g,s,t,kspec,All] finds all the paths.
  • For weighted graphs, FindPath[g,s,t,k] gives all paths with total weights at most k.
  • FindPath works with undirected graphs, directed graphs, weighted graphs, multigraphs, and mixed graphs.

Examples

open allclose all

Basic Examples  (2)

Find a path between two individual vertices in a graph:

Highlight the path:

Find all paths between two individual vertices in a graph:

Scope  (12)

Specification  (7)

FindPath works with undirected graphs:

Directed graphs:

Multigraphs:

Mixed graphs:

Weighted graphs:

Use rules to specify the graph:

FindPath works with large graphs:

Enumeration  (5)

A path of length exactly 7:

A path of length at most 6:

A path of length between 5 and 7:

Find all paths between two individual vertices:

FindPath gives an empty list if there is no path:

Applications  (2)

Find paths of length at most 5 along the seams of a soccer ball:

Highlight the paths:

Plan a trip in the London Underground:

Find a trip from Arsenal to Alperton with at most 16 stops:

Properties & Relations  (2)

Find all shortest paths:

Highlight results:

FindPath only returns simple paths:

Wolfram Research (2014), FindPath, Wolfram Language function, https://reference.wolfram.com/language/ref/FindPath.html (updated 2015).

Text

Wolfram Research (2014), FindPath, Wolfram Language function, https://reference.wolfram.com/language/ref/FindPath.html (updated 2015).

CMS

Wolfram Language. 2014. "FindPath." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/FindPath.html.

APA

Wolfram Language. (2014). FindPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindPath.html

BibTeX

@misc{reference.wolfram_2024_findpath, author="Wolfram Research", title="{FindPath}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FindPath.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_findpath, organization={Wolfram Research}, title={FindPath}, year={2015}, url={https://reference.wolfram.com/language/ref/FindPath.html}, note=[Accessed: 21-December-2024 ]}