10
$\begingroup$

We can download files about some special planar graphs at the following website, but their files are suffixed with pc.

I don't know how to read them. When I tried to open the file, the contents were garbled.

enter image description here

It feels like they're binaries. Mathematica does a great job of reading the Graph6 format. But is there any hope of reading against this format in this web.


Here's what I tried. For eample, I tried to read a 12-vertex 5-regular planar graph. But I don't understand what output means.

BinaryReadList["D:/5reg_12-20.pc"]

enter image description here

$\endgroup$
2
  • $\begingroup$ It seems you need a plantri program for that users.cecs.anu.edu.au/~bdm/plantri $\endgroup$
    – yarchik
    Jun 15, 2022 at 10:21
  • $\begingroup$ Thanks. I know the plantri program. But some sepcail planar graphs in above web are not easily to be obtained by plantri, as stated on the web page. So I thought it would be easier to just read it $\endgroup$
    – licheng
    Jun 15, 2022 at 11:09

1 Answer 1

15
$\begingroup$

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]

enter image description here

$\endgroup$
1
  • $\begingroup$ That's great, although I don't know why your code works, right. but it deserves to be a new function in the next version of IGraph/M. $\endgroup$
    – licheng
    Jun 15, 2022 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.