Mescal
Loading...
Searching...
No Matches
graphs.h
Go to the documentation of this file.
1
10
11#ifndef GRAPHS_H
12#define GRAPHS_H
13
14 /* ____ _ */
15 /* / ___|_ __ __ _ _ __ | |__ ___ */
16 /* | | _| '__/ _` | '_ \| '_ \/ __| */
17 /* | |_| | | | (_| | |_) | | | \__ \ */
18 /* \____|_| \__,_| .__/|_| |_|___/ */
19 /* |_| */
20
21#include "type_abr.h"
22#include "type_basic.h"
23#include "type_binheap.h"
24#include "type_dequeue.h"
25#include "type_partitions.h"
26#include <stdarg.h>
27#include <stdbool.h>
28#include <stdio.h>
29#include <stdlib.h>
30
42typedef struct {
43 uint size;
45} graph;
46
57typedef struct {
61} lgraph;
62
63
73typedef struct {
76 uint** edges;
77 uint* storage;
78} dgraph;
79
80
81/**************/
82/* Allocation */
83/**************/
84
93);
94
103);
104
109void delete_graph(graph* //<! The graph that needs to be freed.
110);
111
120);
121
130 uint
131);
132
137void delete_lgraph(lgraph* //<! The graph that needs to be freed.
138);
139
148);
149
158 uint
159);
160
165void delete_dgraph(dgraph* //<! The graph that needs to be freed.
166);
167
168
177);
178
179/*******************/
180/* Basic functions */
181/*******************/
182
189int graph_nb_edges(graph* //<! The graph.
190);
191
198int lgraph_nb_edges(lgraph* //<! The graph.
199);
200
207int dgraph_nb_edges(dgraph* //<! The graph.
208);
209
210/**************/
211/*+ Products +*/
212/**************/
213
232 dgraph* g2
233);
234
235
236/***********/
237/* Mirrors */
238/***********/
239
247graph* graph_mirror(graph* //<! The graph.
248);
249
257lgraph* lgraph_mirror(lgraph* //<! The graph.
258);
259
267lgraph* dgraph_mirror(dgraph* //<! The graph.
268);
269
270
271/************/
272/* Searches */
273/************/
274
279typedef enum {
280 DFS,
281 BFS,
283
293 graph*,
294 dequeue*,
295 bool*
296);
297
315 graph*,
316 dequeue*,
317 bool*
318);
319
334 lgraph*,
335 dequeue*,
336 bool*,
337 bool*
338);
339
359 lgraph*,
360 dequeue*,
361 bool*,
362 bool*
363);
364
379 dgraph*,
380 dequeue*,
381 bool*,
382 bool*
383);
384
404 dgraph*,
405 dequeue*,
406 bool*,
407 bool*
408);
409
410
411
426 dgraph*,
427 dgraph*,
428 dequeue*,
429 bool*,
430 bool*
431);
432
452 dgraph*,
453 dgraph*,
454 dequeue*,
455 bool*,
456 bool*
457);
458
459
474 uint start
475);
476
477
478
479/********************************/
480/*+ Disjoint merging of graphs +*/
481/********************************/
482
494graph* merge_graphs(uint*,
495 uint,
496 ...
497);
498
513lgraph* merge_lgraphs(uint*,
514 uint,
515 ...
516);
517
518/**************************************************/
519/*+ Merging graphs with the same set of vertices +*/
520/**************************************************/
521
537 uint,
538 uint,
539 uint,
540 ...
541);
542
558 uint,
559 uint,
560 ...
561);
562
571);
572
581);
582
596 bool*
597);
598
599
608);
609
623 bool*
624);
625
626
627/***************************************/
628/*+ Computation of adjacents vertices +*/
629/***************************************/
630
641 dequeue*,
642 uint
643);
644
645
646
647
648
649#endif
dgraph * copy_dgraph(dgraph *g)
Makes a copy of a complete deterministic directed graph.
Definition graphs.c:148
lgraph * dgraph_to_lgraph(dgraph *)
Conversion of a complete deterministic labeled graph into a standard labeled graph.
Definition graphs.c:759
lgraph * lgraph_mirror(lgraph *)
Computes the mirror of a directed labeled graph.
Definition graphs.c:233
graph * dgraph_to_graph(dgraph *)
Conversion of a deterministic labeled graph into a unlabeled graph.
Definition graphs.c:811
void lgraph_search_update(graph_stype, lgraph *, dequeue *, bool *, bool *)
Search in a labeled graph. A set of already visited vertices is taken as input. This set is updated b...
Definition graphs.c:306
void delete_lgraph(lgraph *)
Releases a directed graph.
Definition graphs.c:89
dgraph * create_dgraph_noedges(uint, uint)
Creates a complete deterministic directed graph without edges.
Definition graphs.c:117
lgraph * dgraph_mirror(dgraph *)
Computes the mirror of a complete deterministic directed labeled graph.
Definition graphs.c:248
graph * lgraph_to_graph_alpha(lgraph *, bool *)
Conversion of a standard labeled graph into a unlabeled graph. Restricted version.
Definition graphs.c:781
void dgraph_search_update(graph_stype, dgraph *, dequeue *, bool *, bool *)
Search in a desterministic complete labeled graph. A set of already visited vertices is taken as inpu...
Definition graphs.c:367
lgraph * ldgraphs_to_lgraph(uint, uint, uint,...)
Merging an arbitrary number of labeled graphs using the same set of vertices into a single labeled gr...
Definition graphs.c:698
graph * create_graph_noedges(uint)
Creates a directed unlabeled graph without edges.
Definition graphs.c:14
void delete_dgraph(dgraph *)
Release of a complete deterministic directed graph.
Definition graphs.c:139
graph * create_graph_selfloops(uint)
Creates a directed unlabeled graph whose only edges are self-loops.
lgraph * create_lgraph_noedges(uint, uint)
Creates a directed graph without edges.
Definition graphs.c:66
graph * lgraph_to_graph(lgraph *)
Conversion of a standard labeled graph into a unlabeled graph.
Definition graphs.c:770
dequeue * lgraph_search(graph_stype, lgraph *, dequeue *, bool *, bool *)
Search in a labeled graph. Reachable vertices are returned inside a dequeue sorted in increasing orde...
Definition graphs.c:347
dequeue * lgraph_reachable(lgraph *, dequeue *, uint)
Given a labeled graph, a list of vertices in this graph and a label, computes the list of all vertice...
Definition graphs.c:840
graph * graph_mirror(graph *)
Computes the mirror of a directed unlabeled graph.
Definition graphs.c:219
lgraph * copy_lgraph(lgraph *g)
Makes a copy of a labeled graph.
Definition graphs.c:104
dequeue * twin_dgraph_search(graph_stype, dgraph *, dgraph *, dequeue *, bool *, bool *)
Search in two deterministic complete labeled graphs (same set of vertices, same alphabet)....
Definition graphs.c:471
void delete_graph(graph *)
Releases a directed unlabeled graph.
Definition graphs.c:41
void twin_dgraph_search_update(graph_stype, dgraph *, dgraph *, dequeue *, bool *, bool *)
Search in two deterministic complete labeled graphs (same set of vertices, same alphabet)....
Definition graphs.c:426
dequeue * dgraph_search(graph_stype, dgraph *, dequeue *, bool *, bool *)
Search in a desterministic complete labeled graph. Reachable vertices are returned inside a dequeue s...
Definition graphs.c:403
int dgraph_nb_edges(dgraph *)
Computes the number of edges in a complete deterministic directed labeled graph.
Definition graphs.c:183
dgraph * dgraph_paths(dgraph *G, uint start)
Computes a path from a given strating vertex to all other reachable vertices in a directed unlabeled ...
Definition graphs.c:495
dgraph * dgraph_direct_product(dgraph *g1, dgraph *g2)
Computes the direct product of two deterministic directed labeled graphs.
Definition graphs.c:190
graph * copy_graph(graph *g)
Makes a copy of a directed graph.
Definition graphs.c:53
lgraph * merge_lgraphs(uint *, uint,...)
Disjoint merge of an arbitrary number of labeled graphs.
Definition graphs.c:563
graph * ldgraphs_to_graph(uint, uint, uint, uint,...)
Merging an arbitrary number of graphs using the same set of vertices into a single unlabeled graph.
Definition graphs.c:620
graph * merge_graphs(uint *, uint,...)
Disjoint merge of an arbitrary number of unlabeled graphs.
Definition graphs.c:528
void graph_search_update(graph_stype, graph *, dequeue *, bool *)
Searches in an unlabeled graph. A set of already visited vertices is taken as input....
Definition graphs.c:265
int graph_nb_edges(graph *)
Computes the number of edges in a directed unlabeled graph.
Definition graphs.c:165
graph * dgraph_to_graph_alpha(dgraph *, bool *)
Conversion of a deterministic labeled graph into a unlabeled graph. Restricted version.
Definition graphs.c:822
int lgraph_nb_edges(lgraph *)
Computes the number of edges in a directed labeled graph.
Definition graphs.c:173
graph_stype
Names for the two available algorithms for searches.
Definition graphs.h:279
dequeue * graph_search(graph_stype, graph *, dequeue *, bool *)
Searches in an unlabeled graph. Reachable vertices are returned inside a dequeue sorted in increasing...
Definition graphs.c:286
Type used to represent a dequeue of unsigned integers.
Definition type_dequeue.h:26
Type used to represent a complete deterministic directed labeled graph.
Definition graphs.h:73
uint size_graph
Number of vertices.
Definition graphs.h:74
uint ** edges
The edges: two dimensions array of size "size_graph * size_alpha" (actually contains pointers to the ...
Definition graphs.h:76
uint size_alpha
Number of labels.
Definition graphs.h:75
uint * storage
The storage of the edges (one dimension array of size size_graph * size_alpha).
Definition graphs.h:77
Type used to represent a directed unlabeled graph.
Definition graphs.h:42
dequeue ** edges
The edges: an array of size "size".
Definition graphs.h:44
uint size
Number of vertices.
Definition graphs.h:43
Type used to represent a directed labeled graph.
Definition graphs.h:57
uint size_alpha
Number of labels.
Definition graphs.h:59
uint size_graph
Number of vertices.
Definition graphs.h:58
dequeue *** edges
The edges: an array of arrays of size size_graph * size_alpha.
Definition graphs.h:60
Implementation of AVLs for representing sets of objects.
Basic types.
Implementation of generic binary heaps.
Implementation of dequeues of unsigned integers.
Types used to represent partitions. Includes the union-find algorithm.