-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhgraph.h
289 lines (243 loc) · 8.07 KB
/
hgraph.h
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#ifndef _HGRAPH_H /* INCLUDE GUARD */
#include <stddef.h>
/**
* Include guard
*/
#define _HGRAPH_H
#ifndef VERTEX_WEIGHT_DATATYPE
/**
* Definition that defines the data type of
* the weight on vertices. Default: <b>unsigned int</b>.
*/
#define VERTEX_WEIGHT_DATATYPE unsigned int
#endif
#ifndef HEDGE_WEIGHT_DATATYPE
/**
* Definition that defines the data type of
* the weight on hyper-edges. Default: <b>unsigned int</b>.
*/
#define HEDGE_WEIGHT_DATATYPE unsigned int
#endif
typedef VERTEX_WEIGHT_DATATYPE wvertex_t;
typedef HEDGE_WEIGHT_DATATYPE whedge_t;
/**
* Structure that holds information of a hyper-graph.
*/
typedef struct hgraph_s{
// TODO reorder data from highest size to lowest size in order to optimize memory alloc
/**
* Number of vertices in this graph;
*/
size_t numVertices;
/**
* Number of hyper-edges of this graph;
*/
size_t numHedges;
/**
* Max of vertices currently supported.
* Updated manually when TODO "put name" and
* TODO "put name" is called. Should NOT be changed manually.
*/
size_t maxVertices;
/**
* Max of hyper-edges currently supported.
* Updated manually when TODO "put name" and
* TODO "put name" is called. Should NOT be changed manually.
*/
size_t maxHedges;
/**
* Identifier of any kind. Can be {@code NULL}.
*/
char *tag;
/**
* Array of edges, holding the weight of the i-th edge.
*/
whedge_t *whedges;
/**
* Array holding the weight of the i-th vertex of the graph.
*/
wvertex_t *wvertices;
/**
* <p>Boolean array representing the relationship among vertices.
* links[i][j] = 0 says that the vertex j does not belong to the hyper-edge i.</p>
* <p>Self linking is not possible.</p>
*/
unsigned char **links;
}hgraph_t;
/**
* Creates a new graph with default values.
* @param tag Name of the graph. Can be {@code NULL}
*/
hgraph_t* newhgraph(char *tag);
/**
* Releases all the resources allocated to the given hyper-graph.
* The {@code *g} param should not be used after the call of this this function.
* @param g Hyper-graph to be freed. Cannot be {@code NULL}
* @param isToReleaseTag {@code 0} if the {@code tag} field of the
* hypergraph should <b>not</b> be freed.
*/
void freehgraph(hgraph_t *g, char isToReleaseTag);
/**
*
* Adds a new vertex to the given graph, increasing the capacity if necessary.
*
* @param g Hyper-graph in which the vertex will be added. Cannot be {@code NULL}.
* @param w Weight of the vertex.
*
* @return Index of the vertex that has been just created.
*
*/
size_t addVertex(hgraph_t *g, wvertex_t w);
/**
*
* Javadoc
*
* @param param1 Doc of param1
* @param param2 Doc of param2
*
* @return Return doc if needed
*
*/
char groupVertex(hgraph_t *g, size_t i, size_t j);
/**
*
* Updates the weight of the given vertex.
*
* @param g Hyper-graph to be updated. Cannot be NULL.
* @param i Index of the vertex. Must be in {@code [0, g -> numVertices)}.
* @param w Weight of the vertex.
*
*/
void setVertexWeight(hgraph_t *g, size_t i, wvertex_t w);
/**
*
* Updates the weight of the given hyper-edge.
*
* @param g Hyper-graph to be updated. Cannot be NULL.
* @param i Index of the hyper-edge. Must be in {@code [0, g -> numHedges)}.
* @param w Weight of the hyper-edge.
*
*/
void setHedgeWeight(hgraph_t *g, size_t i, whedge_t w);
/**
*
* Link the vertices from the given pointer.
*
* @param g Hyper-graph holding the vertices to be linked
* @param v Array containing the indexes of each vertex that will be linked to the same edge.
* @param s Size of the array
* @param w Weight of the hyper-edge that will connect all the given vertices.
*
* @return Index of the edge that connects all the given vertices.
*
* @see TODO link other link methods
*/
size_t linkVertices(hgraph_t *g, size_t *v, size_t s, whedge_t w);
/**
*
* Link vertex to the given hyper-edge.
*
* @param i Index of the vertex to be linked. Must be in {@code [0, g -> numVertices).
* @param j Index of the hyper-edge to be linked. Must be in {@code [0, g -> numHedges).
*
* @see TODO link other link methods
*/
void linkVertex(hgraph_t *g, size_t i, size_t j);
/**
*
* <p>Creates a file with the DOT sintax for the given hyper-graph.
* The following will be done: each hyper-edge will be outputted as an vertex prefixed by E,
* each vertex will be outputted as an vertex prefixed by V.</p>
* <p>Vertex format: V%zu_%u</p>
* <p>Hyper-edge format: E%zu_%u</p>
* <p>Where: %zu = index, %u = given weight, assuming it is an {@code unsigned int} value./p>
*
* <p>NOTE: If the data type of the vertex and edge has not been manually changed, use this
* function to print the given hyper-graph, otherwise, check the related functions at <b>see</b>
* section.</p>
*
* @param param1 Doc of param1
* @param param2 Doc of param2
*
* @return Return doc if needed
*
* @see #printHgraphu(hgraph_t *)
* @see #printHgraphf(hgraph_t *)
* @see #printHgrapht(hgraph_t *, void (*)(char *, wvertex_t), void (*)(char *, whedge_t)))
*/
void printHgraphu(hgraph_t *g);
/**
*
* <p>Creates a file with the DOT sintax for the given hyper-graph.
* The following will be done: each hyper-edge will be outputted as an vertex prefixed by E,
* each vertex will be outputted as an vertex prefixed by V.</p>
* <p>Vertex format: V%zu_%f</p>
* <p>Hyper-edge format: E%zu_%f</p>
* <p>Where: %zu = index, %f = given weight, assuming it is a {@code float} value./p>
*
* <p>NOTE: If the data type of the vertex and edge has not been manually changed, use {@link #printHgraphu(hgraph_t *)}
* function to print the given hyper-graph, otherwise, check the related functions at <b>see</b>
* section.</p>
*
* @param param1 Doc of param1
* @param param2 Doc of param2
*
* @return Return doc if needed
*
* @see #printHgraphu(hgraph_t *)
* @see #printHgraphlf(hgraph_t *)
* @see #printHgrapht(hgraph_t *, void (*)(char *, wvertex_t), void (*)(char *, whedge_t)))
*/
void printHgraphf(hgraph_t *g);
/**
*
* <p>Creates a file with the DOT sintax for the given hyper-graph.
* The following will be done: each hyper-edge will be outputted as an vertex prefixed by E,
* each vertex will be outputted as an vertex prefixed by V.</p>
* <p>Vertex format: V%zu_%lf</p>
* <p>Hyper-edge format: E%zu_%lf</p>
* <p>Where: %zu = index, %lf = given weight, assuming it is a {@code double} value./p>
*
* <p>NOTE: If the data type of the vertex and edge has not been manually changed, use {@link #printHgraphu(hgraph_t *)}
* function to print the given hyper-graph, otherwise, check the related functions at <b>see</b>
* section.</p>
*
* @param param1 Doc of param1
* @param param2 Doc of param2
*
* @return Return doc if needed
*
* @see #printHgraphu(hgraph_t *)
* @see #printHgraphf(hgraph_t *)
* @see #printHgrapht(hgraph_t *, void (*)(char *, wvertex_t), void (*)(char *, whedge_t)))
*
*/
void printHgraphlf(hgraph_t *g);
/**
*
* <p>Creates a file with the DOT sintax for the given hyper-graph.
* The following will be done: each hyper-edge will be outputted as an vertex prefixed by E,
* each vertex will be outputted as an vertex prefixed by V.</p>
* <p>Vertex format: V%zu_%s</p>
* <p>Hyper-edge format: E%zu_%s</p>
* <p>Where: %zu = index, %s = given weight (arbitrary data)./p>
*
* <p>NOTE: If the data type of the vertex and edge has not been manually changed, use {@link #printHgraphu(hgraph_t *)}
* function to print the given hyper-graph, otherwise, check the related functions at <b>see</b>
* section.</p>
*
* @param g Hyper-graph to be printed
* @param transwv Pointer to a function that will receive the given vertex weight
* and will translate its value for a string representation, writing the translation at {@code buffer}.
* @param transhew Pointer to a function that will receive the given hyper-edge weight
* and will translate its value for a string representation, writing the translation at {@code buffer}.
*
* @return Return doc if needed
*
* @see #printHgraphu(hgraph_t *g)
* @see #printHgraphf(hgraph_t *g)
* @see #printHgraphlf(hgraph_t *g)
*
*/
void printHgrapht(hgraph_t *g, void (*transvw)(char *buffer, wvertex_t w), void (*transhew)(char *buffer, whedge_t w));
#endif