to_plantri_notation#

to_plantri_notation(g)#

Convert a PlanarGraph into plantri notation.

Plantri notation represents a planar graph using a compact, human-readable format. The output follows the form: "5 bcde,aedc,abd,acbe,adb".

Format Details:
  • Each node is represented by a letter (e.g., a, b, c).

  • The adjacency list for each node is a sequence of letters representing its neighbors in clockwise (CW) order.

  • Nodes are sorted and mapped to alphabetical labels.

Parameters:

g (PlanarGraph) – The planar graph to be converted.

Returns:

The plantri notation string representing the graph.

Return type:

str

Raises:

ValueError – If the graph contains more than 52 nodes.

Note

  • The function assumes nodes are uniquely labeled and do not exceed 52 (a-z, A-Z).

  • If g has parallel edges, an error is raised (currently unimplemented).

  • Plantri’s default orientation is clockwise (CW).

Example:

g = PlanarGraph()
g.add_vertices_from(["a", "b", "c", "d", "e"])
g.set_arcs_from([ [("a", 0), ("b", 0)], [("b", 1), ("c", 0)], [("c", 1), ("d", 0)], [("d", 1), ("e", 0)] ])
notation = to_plantri_notation(g)
print(notation)  # Output: "bcde,aedc,abd,acbe,adb"