segfault by is_planar() function on graph view
Bug reports:
I was trying to analyze certain graph instances, in particular their connected components isolated. However, in one case while checking planarity I encounter segfault.
System info:
- macOS Monterey 12.5
- Python 3.11.3
I attach a graph instance itself for the production: heuristic_014.gr
Here is minimal code for reproducing:
import sys
import graph_tool as gt
import graph_tool.topology as topology
def read_graph(file_path):
with open(file_path, 'r') as f:
lines = f.readlines()
vertices, edges = map(int, lines[0].split()[2:])
adj_list = {i: [] for i in range(1, vertices + 1)}
for line in lines[1:]:
if line.strip() and line[0] != 'p':
u, v = map(int, line.split())
adj_list[u].append(v)
adj_list[v].append(u)
return vertices, edges, adj_list
def build_graph_tool_graph(vertices, edges, adj_list):
g = gt.Graph(directed=False)
g.add_vertex(vertices)
edge_list = [(u - 1, v - 1) for u, neighbors in adj_list.items() for v in neighbors if u < v]
g.add_edge_list(edge_list)
return g
def analyze_component(graph, component_filter, component_idx=None):
filtered_graph = gt.GraphView(graph, vfilt=component_filter)
is_planar = topology.is_planar(filtered_graph)
return {
'component': component_idx if component_idx else 'original',
'planarity': is_planar,
}
if __name__ == "__main__":
graph_file = sys.argv[1]
vertices, edges, adj_list = read_graph(graph_file)
graph_tool_graph = build_graph_tool_graph(vertices, edges, adj_list)
comp, hist = topology.label_components(graph_tool_graph)
if len(hist) > 1: # multiple components
results = []
for idx, component in enumerate(hist):
component_filter = comp.a == idx
results.append(analyze_component(graph_tool_graph, component_filter, idx))
else:
results = [analyze_component(graph_tool_graph, None)]