-
Notifications
You must be signed in to change notification settings - Fork 1
/
dm_english.h
116 lines (86 loc) · 4.31 KB
/
dm_english.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
/******************************************************
Copyright 2004, 2010 Fabien de Montgolfier
fm@liafa.jussieu.fr
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**********************************************************/
/********************************************************
MODULAR DECOMPOSITION OF UNDIRECTED GRAPHS
by Fabien de Montgolfier
The program dm.c offer a single function,
decomposition_modulaire().
The input is a graph, its output is its modular decomposition tree.
Input graph is stored using adjacency lists, and trees using a pointers representation (see below)
********************************************************/
#include <stdio.h>
#include <stdlib.h>
/**********************************
Definition of graphs (for the input)
The graph has n vertices. Each vertex is numbered from 0 to n-1.
A graph is a structure (not an object-oriented program !).
If you declare "graphe Gr", Gr.n is the numer of vertices of Gr.
Gr.G is an array of size n. Gr.G[i] points the first element
of adjaceny list of vertex i (NULL if i is isolated)
An adjency list is an usual linked list (vertex;pointer to next).
Adjacency lists may be unsorted.
WARNING : the input graph *MUST* be symmetric : if j belongs to adjacency list of i then i belongs to adjacency list of j. Graphs that do not respect this produce unpredictible and false results.
**********************************/
#ifdef __cplusplus
extern "C" {
#endif
/* structure for creating an adjacency list */
typedef struct Adj {
int s; // number of the vertex
struct Adj *suiv; // adress of next pair in the list, NULL if last
} adj;
typedef struct {
int n; //number of vertices of the graph
adj **G; // array of size n. G[i] points the first pair of the adjaceny list of vertex i
} graphe;
/********************************
Output : definition of modular decomposition tree.
Each internal node is labelled SERIE (for series), PARALLELE (for parallel) or PREMIER (for prime) depending of the quotient's type.
Each leaf is labelled FEUILLE and also contains the vertex number of the leaf.
As the tree is an inclusion tree, the vertex-set corresponding to an internal node correspond to the vertices numbers of the leaves that descend from that tree. The function decomposition_modulaire() return a pointer to the root of the tree.
*/
/* define the type of nodes. UNKN,MODULE,ARTEFACT are for internal use*/
#define FEUILLE 0 // the node is a leaf
#define UNKN 1
#define MODULE 2
#define ARTEFACT 3
#define SERIE 4 // series composition
#define PARALLELE 5 // parallel composition
#define PREMIER 6 // prime composition
/* defines a node of the tree */
typedef struct Noeud {
int type; // is FEUILLE, SERIE, PARALLELE or PREMIER
struct Noeud *pere; // adress of parent node, NULL if root
struct Fils *fpere; // points the head of the linked list of sons (if type is not FEUILLE, else is NULL)
int nom; // if type=FEUILLE, number of the corresponding vertex of the graph
struct Fils *fils; // points the head of the linked list of sons
struct Fils *lastfils; // internal use (points the last item in the listed list of sons)
int id; // internal use (node unique ID)
int fv; // internal use (first vertex in factorizing permutation)
int lv; // internal use (last vertex in factorizing permutation)
} noeud;
/* linked list that strore the sons of an internal node (in any order) */
typedef struct Fils {
struct Noeud *pointe; // adress of the node in the tree
struct Fils *suiv; // adress of the next pair in the list, NULL if last
} fils;
/* prototype of the function.
Input is a graph, output the root of the modular decomposition tree */
noeud *decomposition_modulaire(graphe G);
void printarbre(noeud * N);
#ifdef __cplusplus
}
#endif