One option is to generate these planar graphs using the plantri
program and ask for Graph6 output, which Mathematica can read (and IGraph/M can read faster). However, Graph6 does not encode the combinatorial embedding like the pc format does. The following is a small function that decodes this format to combinatorial embeddings:
decode[data_] :=
Module[{d = data, head, vc, g},
(* skip header if it exists *)
head = ToCharacterCode[">>planar_code<<"];
If[Take[d, Min[Length[d], Length[head]]] === head,
d = Drop[d, Length[head]];
];
(* split data at zero separators *)
d = Most /@ Split[d, #1 =!= 0 &];
First@Last@Reap@While[Length[d] > 0,
vc = d[[1, 1]]; (* vertex count *)
(* get as many neighbour lists as the vertex count *)
{g, d} = TakeDrop[d, vc];
(* drop vertex count from first neighbour list *)
g = MapAt[Rest, g, {1}];
(* build association for combinatorial embedding *)
Sow@AssociationThread[Range[vc], Reverse /@ g (* reverse from clockwise to counterclockwise *)]
]
]
Note that there is no error checking! If you are interested in a robust version, feel free to open a feature request for IGraph/M, and I will consider including it in the next version.
The expected input is the contents of a valid PC file, as a list of bytes (values between 0..255).
Example:
data = Import[
"http://users.cecs.anu.edu.au/%7Ebdm/data/5reg_20-32.pc", "Byte"]
decode[data]
This returns a list of associations, each representing a graph and its combinatorial embedding. The format is the same that IGraph/M uses, which I think you are familiar with: vertices are associated with a list of their counter-clockwise neighbours.
You can use IGAdjacencyGraph
to convert this format to a graph or IGEmbeddingToCoordinates
to get planar coordinates for them.
In the following example I chose to use a Tutte layout instead, as it is visually more appealing:
IGLayoutTutte@IGAdjacencyGraph[#] & /@ decode[data]
