OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to use _read_planar_code to read the corresponding graph file

  • Thread starter Thread starter licheng
  • Start date Start date
L

licheng

Guest
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 7-vertex).

Code:
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 graph

AttributeError: '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.

Code:
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
<p>Planar code is for storing planar graphs. See <a href="https://houseofgraphs.org/help#format_pc" rel="nofollow noreferrer">https://houseofgraphs.org/help#format_pc</a>.</p>
<p>I see that SageMath has a function called <code>_read_planar_code</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, <a href="https://houseofgraphs.org/data/planar/triangulations/triangulations_10.pl" rel="nofollow noreferrer">all 3-connected planar triangulations with 7-vertex</a>).</p>
<pre><code>s=graphs._read_planar_code("triangulations_10.pl")
s
next(s)
</code></pre>
<p><generator object GraphGenerators._read_planar_code at 0x7f4ed1b099c0></p>
<blockquote>
<p>AttributeError Traceback (most recent call
last) Cell In<a href="https://github.com/sagemath/sage/bl...95d/src/sage/graphs/graph_generators.py#L1436" rel="nofollow noreferrer">1</a>, line 3
1 s=graphs._read_planar_code("triangulations_10.pl")
2 s
----> 3 next(s)</p>
<p>File
/usr/lib/python3.12/site-packages/sage/graphs/graph_generators.py:1488,
in GraphGenerators.<em>read_planar_code(self, code_input) 1433 r"""<br />
1434 Returns a generator for the plane graphs in planar code format in
1435 the file code_input (see [BM2016]</em>). (...) 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 graph</p>
<p>AttributeError: 'str' object has no attribute 'read'</p>
</blockquote>
<p>When I read the manual in <a href="https://github.com/sagemath/sage/bl...95d/src/sage/graphs/graph_generators.py#L1436" rel="nofollow noreferrer">_read_planar_code</a>, I was also confused. Can't <code>_read_planar_code</code> be used to read files?</p>
<p>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.</p>
<pre><code>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

</code></pre>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top