plantri#

Functions

from_plantri_notation(graph_string)

Parse a plantri notation string into a PlanarDiagram.

to_plantri_notation(g)

Convert a planar diagram to plantri notation (alphabetical form).

from_plantri_notation(graph_string)#

Parse a plantri notation string into a PlanarDiagram.

Supports:
  • Alphabetical: "5 bcde,aedc,abd,acbe,adb"

  • Numeric: "7: 1[2 3 4 5] 2[1 5 6 3] ..."

The plantri order is CW; this function reverses each adjacency string to obtain CCW before building the diagram.

Parameters:

graph_string (str) – Plantri string (alphabetical or numeric).

Returns:

PlanarDiagram – New diagram with vertices 'a','b','c',... and arcs set.

Raises:

ValueError – If vertex count exceeds 52 (a–zA–Z) or parsing fails.

Return type:

PlanarDiagram

Examples

>>> s = "5 bcde,aedc,abd,acbe,adb"
>>> d = from_plantri_notation(s)
>>> isinstance(d, PlanarDiagram)
True
>>> d.number_of_nodes == 5
True
to_plantri_notation(g)#

Convert a planar diagram to plantri notation (alphabetical form).

Plantri’s alphabetical notation lists each node’s neighbors in CW order. Our diagrams store endpoints CCW, so we iterate the diagram’s stored order directly and rely on the fact that the notation consumer understands CW. (If your internal storage differs, you may need to reverse per node.)

The output looks like: "5 bcde,aedc,abd,acbe,adb" (node count + space + CSV).

Parameters:

g (PlanarDiagram) – Planar diagram to serialize.

Returns:

str – Plantri alphabetical notation.

Raises:

ValueError – If the diagram has more than 52 nodes (a–zA–Z).

Return type:

str

Examples

>>> from knotpy.classes.planardiagram import PlanarDiagram
>>> d = PlanarDiagram()
>>> d.add_vertices_from(["a", "b", "c"])
>>> d.set_arc((("a", 0), ("b", 0)))
>>> d.set_arc((("b", 1), ("c", 0)))
>>> to_plantri_notation(d).split()[0].isdigit()
True