ChainGraph.addArc
- ChainGraph.addArc(tail, head)
Add an arc from tail to head.
- Parameters:
tail (
int) – the id of the tail nodehead (
int) – the id of the head node
- Raises:
pyagrum.InvalidNode – If head or tail does not belong to the graph nodes.
pyagrum.InvalidArc – If an edge already connects tail and head.
pyagrum.InvalidDirectedCycle – If the arc would create a directed cycle.
pyagrum.InvalidPartiallyDirectedCycle – If the arc would create a partially directed cycle, i.e. if there is a path from head to tail following the arcs in their direction and the edges in either direction.
- Return type:
None
Example
import pyagrum as gum
cg = gum.ChainGraph()
cg.addNodes(3)
# {0, 1, 2}
cg.addArc(0, 1)
cg.addEdge(1, 2)
try:
cg.addArc(2, 0) # C->A would close A->B-C into a partially directed cycle
except gum.InvalidPartiallyDirectedCycle:
print("refused")
cg.arcs()
# {(0, 1)}
Class