-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_embedding.c
More file actions
142 lines (99 loc) · 2.66 KB
/
is_embedding.c
File metadata and controls
142 lines (99 loc) · 2.66 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "b_stack.h"
#include "ugraph.def"
/*****************************************************************************/
UGRAPH_PROTO(G)
#define _LEFT(e,v,Left,Right) ((G_source(e)==v) ? Left[e] : Right[e])
#define _RIGHT(e,v,Left,Right) ((G_source(e)==v) ? Right[e] : Left[e])
#define _LEFT_(e,v,Left,Right) ((G_source(e)==v) ? &Left[e] : &Right[e])
#define _RIGHT_(e,v,Left,Right) ((G_source(e)==v) ? &Right[e] : &Left[e])
/*****************************************************************************/
void CONNECTED_COMPONENTS_recursive(vertex v, vertex_array compnum, num no)
{
vertex w;
compnum[v] = no;
forall_adjacent_vertices(w,v,G)
if (compnum[w]==0)
CONNECTED_COMPONENTS_recursive(w,compnum,no);
}
num CONNECTED_COMPONENTS(vertex_array compnum)
{
vertex v;
num count = 0;
G_init_vertex_array(compnum,0);
if (! getenv("NONRECURSIVE"))
{
forall_vertices(v,G)
if (compnum[v]==0)
CONNECTED_COMPONENTS_recursive(v,compnum,++count);
}
else
{
vertex w;
b_stack S=new_b_stack(2*G_number_of_edges());
forall_vertices(v,G)
if (compnum[v]==0)
{
++count;
push(v,S);
while (! empty_b_stack(S))
{
v = pop(S);
if (compnum[v]==0)
{
compnum[v]=count;
forall_adjacent_vertices(w,v,G)
if (compnum[w]==0)
push(w,S);
}
}
}
delete_b_stack(S);
}
return count;
}
void trace_left_pseudo_face(edge e, vertex v,
edge_array Left, edge_array Right, num no)
{
edge f = e;
do
{
*_LEFT_(f,v,Left,Right)=no;
v = G_opposite(v,f);
f = G_cyclic_incident_pred(f,v);
}
while (_LEFT(f,v,Left,Right)==0);
}
#define for_both_adjacent_vertices(v,e,G,Block)\
{ vertex v=G_source(e); { Block } v=G_target(e); { Block } }
bool is_embedding(void)
{
int n,m,f,c;
edge_array Left,Right;
vertex_array compnum;
n = G_number_of_vertices();
m = G_number_of_edges();
if (m+6>3*n)
{
return (n<3);
}
Left = G_new_edge_array();
Right = G_new_edge_array();
f = 0;
G_init_edge_array(Left,0);
G_init_edge_array(Right,0);
Apply_forall_edges
(e,G,
for_both_adjacent_vertices
(v,e,G,
if (_LEFT(e,v,Left,Right)==0)
trace_left_pseudo_face(e,v,Left,Right,++f);
)
)
Apply_forall_vertices(v,G, if (G_degree(v)==0) f++; )
G_delete_edge_array(Left);
G_delete_edge_array(Right);
compnum = G_new_vertex_array();
c = CONNECTED_COMPONENTS(compnum);
G_delete_vertex_array(compnum);
return ((n+f)==(m+2*c));
}