-
Notifications
You must be signed in to change notification settings - Fork 0
/
bliss_C.cc
205 lines (178 loc) · 4.79 KB
/
bliss_C.cc
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "graph.hh"
extern "C" {
#include "bliss_C.h"
}
/*
Copyright (c) 2003-2015 Tommi Junttila
Released under the GNU Lesser General Public License version 3.
This file is part of bliss.
bliss is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, version 3 of the License.
bliss is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with bliss. If not, see <http://www.gnu.org/licenses/>.
*/
struct bliss_digraphs_graph_struct {
bliss_digraphs::Graph* g;
};
extern "C"
BlissGraph *bliss_digraphs_new(const unsigned int n)
{
BlissGraph *graph = new bliss_digraphs_graph_struct;
assert(graph);
graph->g = new bliss_digraphs::Graph(n);
assert(graph->g);
return graph;
}
extern "C"
BlissGraph *bliss_digraphs_read_dimacs(FILE *fp)
{
bliss_digraphs::Graph *g = bliss_digraphs::Graph::read_dimacs(fp);
if(!g)
return 0;
BlissGraph *graph = new bliss_digraphs_graph_struct;
assert(graph);
graph->g = g;
return graph;
}
extern "C"
void bliss_digraphs_write_dimacs(BlissGraph *graph, FILE *fp)
{
assert(graph);
assert(graph->g);
graph->g->write_dimacs(fp);
}
extern "C"
void bliss_digraphs_clear(BlissGraph *graph)
{
assert(graph);
assert(graph->g);
graph->g->clear();
}
extern "C"
void bliss_digraphs_change_color(BlissGraph* graph, const unsigned int vertex, const unsigned int color)
{
assert(graph);
assert(graph->g);
graph->g->change_color(vertex, color);
}
extern "C"
void bliss_digraphs_release(BlissGraph *graph)
{
assert(graph);
assert(graph->g);
delete graph->g; graph->g = 0;
delete graph;
}
extern "C"
void bliss_digraphs_write_dot(BlissGraph *graph, FILE *fp)
{
assert(graph);
assert(graph->g);
graph->g->write_dot(fp);
}
extern "C"
unsigned int bliss_digraphs_get_nof_vertices(BlissGraph *graph)
{
assert(graph);
assert(graph->g);
return graph->g->get_nof_vertices();
}
extern "C"
unsigned int bliss_digraphs_add_vertex(BlissGraph *graph, unsigned int l)
{
assert(graph);
assert(graph->g);
return graph->g->add_vertex(l);
}
extern "C"
void bliss_digraphs_add_edge(BlissGraph *graph, unsigned int v1, unsigned int v2)
{
assert(graph);
assert(graph->g);
graph->g->add_edge(v1, v2);
}
extern "C"
int bliss_digraphs_cmp(BlissGraph *graph1, BlissGraph *graph2)
{
assert(graph1);
assert(graph1->g);
assert(graph2);
assert(graph2->g);
return (*graph1->g).cmp(*graph2->g);
}
extern "C"
unsigned int bliss_digraphs_hash(BlissGraph *graph)
{
assert(graph);
assert(graph->g);
return graph->g->get_hash();
}
extern "C"
BlissGraph *bliss_digraphs_permute(BlissGraph *graph, const unsigned int *perm)
{
assert(graph);
assert(graph->g);
assert(graph->g->get_nof_vertices() == 0 || perm);
BlissGraph *permuted_graph = new bliss_digraphs_graph_struct;
assert(permuted_graph);
permuted_graph->g = graph->g->permute(perm);
return permuted_graph;
}
extern "C"
void
bliss_digraphs_find_automorphisms(BlissGraph *graph,
void (*hook)(void *user_param,
unsigned int n,
const unsigned int *aut),
void *hook_user_param,
BlissStats *stats)
{
bliss_digraphs::Stats s;
assert(graph);
assert(graph->g);
graph->g->find_automorphisms(s, hook, hook_user_param);
if(stats)
{
stats->group_size_approx = s.get_group_size_approx();
stats->nof_nodes = s.get_nof_nodes();
stats->nof_leaf_nodes = s.get_nof_leaf_nodes();
stats->nof_bad_nodes = s.get_nof_bad_nodes();
stats->nof_canupdates = s.get_nof_canupdates();
stats->nof_generators = s.get_nof_generators();
stats->max_level = s.get_max_level();
}
}
extern "C"
const unsigned int *
bliss_digraphs_find_canonical_labeling(BlissGraph *graph,
void (*hook)(void *user_param,
unsigned int n,
const unsigned int *aut),
void *hook_user_param,
BlissStats *stats)
{
bliss_digraphs::Stats s;
const unsigned int *canonical_labeling = 0;
assert(graph);
assert(graph->g);
canonical_labeling = &(*graph->g->canonical_form(s, hook, hook_user_param));
if(stats)
{
stats->group_size_approx = s.get_group_size_approx();
stats->nof_nodes = s.get_nof_nodes();
stats->nof_leaf_nodes = s.get_nof_leaf_nodes();
stats->nof_bad_nodes = s.get_nof_bad_nodes();
stats->nof_canupdates = s.get_nof_canupdates();
stats->nof_generators = s.get_nof_generators();
stats->max_level = s.get_max_level();
}
return canonical_labeling;
}