1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
Author: Ximin Luo <infinity0@debian.org>
Bug: https://trac.sagemath.org/ticket/21774
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/sage/src/sage/graphs/planarity.pyx
+++ b/sage/src/sage/graphs/planarity.pyx
@@ -3,13 +3,19 @@
"""
cdef extern from "planarity/graph.h":
- ctypedef struct graphNode:
- int v
+ ctypedef struct vertexRec:
int link[2]
- ctypedef graphNode * graphNodeP
+ int index
+ ctypedef vertexRec * vertexRecP
+
+ ctypedef struct edgeRec:
+ int link[2]
+ int neighbor
+ ctypedef edgeRec * edgeRecP
ctypedef struct BM_graph:
- graphNodeP G
+ vertexRecP V
+ edgeRecP E
int N
ctypedef BM_graph * graphP
@@ -93,15 +99,16 @@
g._pos = { u: [0,0], v: [0,1] }
return (True, None) if kuratowski else True
- # create to and from mappings to relabel vertices to the set {0,...,n-1}
+ # create to and from mappings to relabel vertices to the set {1,...,n}
+ # (planarity 3 uses 1-based array indexing, with 0 representing NIL)
cdef int i
listto = g.vertices()
ffrom = {}
for vvv in listto:
- ffrom[vvv] = listto.index(vvv)
+ ffrom[vvv] = listto.index(vvv) + 1
to = {}
for i from 0 <= i < len(listto):
- to[i] = listto[i]
+ to[i + 1] = listto[i]
g.relabel(ffrom)
cdef graphP theGraph
@@ -125,7 +132,7 @@
status = gp_Embed(theGraph, EMBEDFLAGS_PLANAR)
gp_SortVertices(theGraph)
- # use to and from mappings to relabel vertices back from the set {0,...,n-1}
+ # use to and from mappings to relabel vertices back from the set {1,...,n}
g.relabel(to)
if status == NOTOK:
@@ -134,12 +141,12 @@
# Kuratowski subgraph isolator
g_dict = {}
from sage.graphs.graph import Graph
- for i from 0 <= i < theGraph.N:
+ for i from 0 < i <= theGraph.N:
linked_list = []
- j = theGraph.G[i].link[1]
- while j >= theGraph.N:
- linked_list.append(to[theGraph.G[j].v])
- j = theGraph.G[j].link[1]
+ j = theGraph.V[i].link[1]
+ while j:
+ linked_list.append(to[theGraph.E[j].neighbor])
+ j = theGraph.E[j].link[1]
if len(linked_list) > 0:
g_dict[to[i]] = linked_list
G = Graph(g_dict)
@@ -153,12 +160,12 @@
if set_embedding:
emb_dict = {}
#for i in range(theGraph.N):
- for i from 0 <= i < theGraph.N:
+ for i from 0 < i <= theGraph.N:
linked_list = []
- j = theGraph.G[i].link[1]
- while j >= theGraph.N:
- linked_list.append(to[theGraph.G[j].v])
- j = theGraph.G[j].link[1]
+ j = theGraph.V[i].link[1]
+ while j:
+ linked_list.append(to[theGraph.E[j].neighbor])
+ j = theGraph.E[j].link[1]
emb_dict[to[i]] = linked_list
g._embedding = emb_dict
if set_pos:
@@ -174,12 +181,12 @@
emb_dict = {}
#for i in range(theGraph.N):
- for i from 0 <= i < theGraph.N:
+ for i from 0 < i <= theGraph.N:
linked_list = []
- j = theGraph.G[i].link[0]
- while j >= theGraph.N:
- linked_list.append(to[theGraph.G[j].v])
- j = theGraph.G[j].link[0]
+ j = theGraph.V[i].link[0]
+ while j:
+ linked_list.append(to[theGraph.E[j].neighbor])
+ j = theGraph.E[j].link[0]
emb_dict[to[i]] = linked_list
g._embedding = emb_dict
gp_Free(&theGraph)
|