Path: blob/master/sage/graphs/modular_decomposition/src/dm_english.h
4045 views
/******************************************************12Copyright 2004, 2010 Fabien de Montgolfier3[email protected]45This program is free software; you can redistribute it and/or6modify it under the terms of the GNU General Public License7as published by the Free Software Foundation; either version 28of the License, or (at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.1819**********************************************************/2021/********************************************************2223MODULAR DECOMPOSITION OF UNDIRECTED GRAPHS24by Fabien de Montgolfier2526The program dm.c offer a single function,27decomposition_modulaire().2829The input is a graph, its output is its modular decomposition tree.3031Input graph is stored using adjacency lists, and trees using a pointers representation (see below)32********************************************************/3334#include <stdio.h>35#include <stdlib.h>3637/**********************************38Definition of graphs (for the input)39The graph has n vertices. Each vertex is numbered from 0 to n-1.40A graph is a structure (not an object-oriented program !).41If you declare "graphe Gr", Gr.n is the numer of vertices of Gr.42Gr.G is an array of size n. Gr.G[i] points the first element43of adjaceny list of vertex i (NULL if i is isolated)44An adjency list is an usual linked list (vertex;pointer to next).45Adjacency lists may be unsorted.4647WARNING : 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.48**********************************/495051/* structure for creating an adjacency list */52typedef struct Adj {53int s; // number of the vertex54struct Adj *suiv; // adress of next pair in the list, NULL if last55} adj;5657typedef struct {58int n; //number of vertices of the graph59adj **G; // array of size n. G[i] points the first pair of the adjaceny list of vertex i6061} graphe;6263/********************************64Output : definition of modular decomposition tree.65Each internal node is labelled SERIE (for series), PARALLELE (for parallel) or PREMIER (for prime) depending of the quotient's type.66Each leaf is labelled FEUILLE and also contains the vertex number of the leaf.67As 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.68697071/* define the type of nodes. UNKN,MODULE,ARTEFACT are for internal use*/7273#define FEUILLE 0 // the node is a leaf74#define UNKN 175#define MODULE 276#define ARTEFACT 377#define SERIE 4 // series composition78#define PARALLELE 5 // parallel composition79#define PREMIER 6 // prime composition8081/* defines a node of the tree */8283typedef struct Noeud {84int type; // is FEUILLE, SERIE, PARALLELE or PREMIER85struct Noeud *pere; // adress of parent node, NULL if root86struct Fils *fpere; // points the head of the linked list of sons (if type is not FEUILLE, else is NULL)87int ps; // internal use88int bg; // internal use89int ds; // internal use90int bd; // internal use91int sommet; // internal use92int nom; // if type=FEUILLE, number of the corresponding vertex of the graph93struct Fils *fils; // points the head of the linked list of sons94struct Fils *lastfils; // internal use (points the last item in the listed list of sons)95int id; // internal use (node unique ID)96} noeud;9798/* linked list that strore the sons of an internal node (in any order) */99100typedef struct Fils {101struct Noeud *pointe; // adress of the node in the tree102struct Fils *suiv; // adress of the next pair in the list, NULL if last103} fils;104105/* prototype of the function.106Input is a graph, output the root of the modular decomposition tree */107108noeud *decomposition_modulaire(graphe G);109110111112113114115116117118119