EdgeRules
Details
- EdgeRules[g] returns the list of edge rules in the order used by the graph g.
- Undirected edges uv and directed edges uv are both represented as the rule u->v.
Examples
open all close allBasic Examples (2)
Scope (4)
EdgeRules works with undirected graphs:
EdgeRules[[image]]EdgeRules[[image]]Use rules to specify the graph:
EdgeRules[{1 -> 3, 2 -> 1, 3 -> 6, 4 -> 6, 1 -> 5, 5 -> 4, 6 -> 1}]EdgeRules works with large graphs:
g = GridGraph[{10, 10, 10, 10}];Timing[EdgeRules[g]//Length]Properties & Relations (8)
EdgeRules gives rules for undirected graphs:
Graph[{12, 23}]//EdgeRulesReconstruct the undirected graph:
Graph[%, DirectedEdges -> False]EdgeRules gives rules for directed graphs:
Graph[{12, 23}]//EdgeRulesReconstruct the directed graph:
Graph[%]Rules cannot represent isolated vertices:
SeedRandom[1234];
g = RandomGraph[{10, 5}]Reconstructing the graph from EdgeRules excludes isolated vertices:
Graph[EdgeRules[g], DirectedEdges -> False]Including the vertex list reconstructs the full graph:
Graph[VertexList[g], EdgeRules[g], DirectedEdges -> False]EdgeRules can be found using EdgeList:
g = PetersenGraph[5, 2]Rule@@@EdgeList[g]EdgeRules[g]EdgeCount can be found using EdgeRules:
g = CompleteGraph[5]EdgeCount[g]Length[EdgeRules[g]]Rules are given in the same order they are entered for Graph:
g = Graph[{23, 12, 31, 41}]EdgeRules[%]Edge rules can be explicitly specified in Graph:
Graph[{a -> b, b -> c, c -> a}]EdgeRules[%]TreeGraph[{a -> b, a -> c, a -> d}]EdgeList[%]PathGraph[{a -> b, b -> c, c -> d}]EdgeList[%]Use EdgeRules to extract the AnnotationValue of edges:
g = Graph[{ab, bc, ca}, EdgeLabels -> {ab -> One, bc -> Two, ca -> Three}]AnnotationValue[{g, #}, EdgeLabels] & /@ EdgeRules[g]Related Guides
Text
Wolfram Research (2010), EdgeRules, Wolfram Language function, https://reference.wolfram.com/language/ref/EdgeRules.html (updated 2015).
CMS
Wolfram Language. 2010. "EdgeRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/EdgeRules.html.
APA
Wolfram Language. (2010). EdgeRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EdgeRules.html
BibTeX
@misc{reference.wolfram_2026_edgerules, author="Wolfram Research", title="{EdgeRules}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/EdgeRules.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_edgerules, organization={Wolfram Research}, title={EdgeRules}, year={2015}, url={https://reference.wolfram.com/language/ref/EdgeRules.html}, note=[Accessed: 12-June-2026]}