from_plantri_notation#

from_plantri_notation(graph_string: str) PlanarDiagram#

Convert a plantri notation string into a PlanarDiagram.

A plantri notation string represents a graph using either numerical or alphabetical notation. This function automatically detects the notation type and parses the graph accordingly.

Supported Notation Formats:
  • Numerical notation: Example: "7: 1[2  3  4  5] 2[1  5  6  3] 3[1  2  6  4] 4[1  3  6  5] 5[1  4  6  2] 6[2  5  4  3]"

  • Alphabetical notation: Example: "5 bcde,aedc,abd,acbe,adb"

Parameters:

graph_string (str) – A string representing a planar graph in plantri notation.

Returns:

A PlanarDiagram object representing the parsed graph.

Return type:

PlanarDiagram

Raises:

ValueError – If the number of vertices exceeds the supported limit.

Parsing Logic:
  1. Detect whether the input is in alphabetical or numerical notation.

  2. Extract connections:
    • Alphabetical notation: Extracts sequences separated by commas and spaces.

    • Numerical notation: Extracts vertex connections enclosed in square brackets [ ].

  3. Convert numerical indices to alphabetical labels (1 → ‘a’, 2 → ‘b’, …).

  4. Construct a PlanarDiagram with vertices labeled “a”, “b”, “c”, ….

  5. Add arcs:
    • Reverses connections to match counterclockwise (CCW) order, since plantri uses clockwise (CW) order.