Reputation: 157
Planar code is for storing planar graphs. See https://houseofgraphs.org/help#format_pc.
I see that SageMath has a function called _read_planar_code
, but I still don't understand how to use it to read a graph file encoded with planar_code (this file may contain multiple graphs, for example, all 3-connected planar triangulations with 10 vertices).
s=graphs._read_planar_code("triangulations_10.pl")
s
next(s)
<generator object GraphGenerators._read_planar_code at 0x7f4ed1b099c0>
AttributeError Traceback (most recent call last) Cell In1, line 3 1 s=graphs._read_planar_code("triangulations_10.pl") 2 s ----> 3 next(s)
File /usr/lib/python3.12/site-packages/sage/graphs/graph_generators.py:1488, in GraphGenerators.read_planar_code(self, code_input) 1433 r"""
1434 Returns a generator for the plane graphs in planar code format in 1435 the file code_input (see [BM2016]). (...) 1485 4: [1, 3, 2]} 1486 """ 1487 # start of code to read planar code -> 1488 header = code_input.read(15) 1489 assert header == '>>planar_code<<', 'Not a valid planar code header' 1491 # read graph per graphAttributeError: 'str' object has no attribute 'read'
When I read the manual in _read_planar_code, I was also confused. Can't _read_planar_code
be used to read files?
Actually, I want to iteratively read them and then filter out some graphs that satisfy certain properties, such as filtering out perfect graphs. The following is an example of how we read files in another graph format, graph6 format.
with open('planar_conn.7.g6', 'r') as file:
for line in file:
# Remove any leading/trailing whitespace
graph6_string = line.strip()
# Decode the graph6 string to a graph object
graph = Graph(graph6_string)
# Check if the graph meets the desired property (e.g., perfect graph)
if graph.is_perfect():
graph.show()
break # Stop reading further as the desired graph is found
Upvotes: 1
Views: 62