Documente Academic
Documente Profesional
Documente Cultură
descompunerea modulara
Cristian Frasinaru
acf@infoiasi.ro
Facultatea de Informatica
Universitatea Al. I. Cuza Iasi
Cuprins
1 Descompunerea modular
a
1.1 Definitii . . . . . . . . . .
1.2 Algoritmul brut . . . . . .
1.3 Algoritmi liniari . . . . . .
1.4 Recunoasterea cografurilor
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 Colorarea cografurilor
2.1 Ideea algoritmului . . . . . . . . . . .
2.2 Algoritmul de colorare a cografurilor
2.3 Corectitudinea . . . . . . . . . . . . .
2.4 Complexitatea . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
4
9
9
.
.
.
.
11
11
11
14
14
Descompunerea modular
a
1.1
Definitii
1.2
Algoritmul brut
Pentru fiecare pereche de varfuri x, y se poate gasi usor, n O(n + m), modulul minimal M care le contine. Descompunem apoi graful (G M ) x si
nlocuim pe x cu descompunerea recursiva a lui M .
Analizand complexitatea algoritmului observam ca, n cazul 2, avem nevoie
de O(n2 m) operatii pentru a descompune graful. Complexitatea totala a algoritmului este deci O(n3 m).
Listing 1: Algoritmul brut de descompunere modulara
import
import
import
import
graph .*;
graph . algorithms .*;
graph . layout .*;
java . util .*;
return node ;
}
public void decompose ( Graph g , Node parent ) {
// Descompune V ( G ) si adauga arborele rezultat
// ca subarbore al lui parent
if ( isStopped () )
return ;
Node node = null ;
if ( g . N () == 1) {
Node v = g . node (0) ;
node = addNode ( parent ) ;
node . setLabel ( v . getLabel () ) ;
node . setData ( new Integer ( v . getId () ) ) ;
node . setFillColor ( v . getFillColor () ) ;
return ;
}
ConnectedComponents alg = new C on n e ct e d Co m po n e nt s () ;
alg . setGraph ( g ) ;
if (! alg . isConnected () ) {
node = addNode ( parent ) ;
if ( root == null )
root = node ;
node . setLabel ( " Paralel " ) ;
node . setData ( " Paralel " ) ;
node . setWidth (60) ;
Set blocks = alg . components () ;
for ( Iterator it = blocks . iterator () ; it . hasNext () ;) {
NodeSet cc = ( NodeSet ) it . next () ;
decompose ( g . subgraph ( cc ) , node ) ;
}
return ;
}
alg . setGraph ( g . complement () ) ;
if (! alg . isConnected () ) {
node = addNode ( parent ) ;
if ( root == null )
root = node ;
Node xleaf
= tree . nodes () . find ( new Integer ( x . getId () )
);
Node xparent = xleaf . neighbors () . node (0) ;
tree . remove ( xleaf ) ;
decompose ( g . subgraph ( M ) , xparent ) ;
}
else {
node = addNode ( parent ) ;
if ( root == null )
root = node ;
node . setLabel ( " Prim " ) ;
node . setData ( " Prim " ) ;
}
return M ;
}
}
1.3
Algoritmi liniari
1.4
Recunoasterea cografurilor
graph .*;
graph . algorithms .*;
graph . layout .*;
java . util .*;
10
Colorarea cografurilor
2.1
Ideea algoritmului
2.2
graph .*;
graph . algorithms .*;
java . util .*;
java . awt .*;
12
int nc = 0;
NodeSet kids = node . children () ;
// Nod paralel
if ( node . getData () . equals ( " Paralel " ) ) {
int max = 0;
for ( int i =0; i < kids . size () ; i ++) {
nc = color ( kids . node ( i ) , k ) ;
if ( nc > max )
max = nc ;
}
return max ;
}
// Nod serie
if ( node . getData () . equals ( " Serie " ) ) {
int suma = 0;
for ( int i =0; i < kids . size () ; i ++) {
Node kid = kids . node ( i ) ;
nc = color ( kid , k + suma ) ;
suma += nc ;
}
return suma ;
}
// Frunza
// Aflam nodul corespondent din graful g
Node gnode = g . node ((( Integer ) node . getData () ) . intValue () )
;
// Coloram efectiv nodul
gnode . setFillColor ( colors [ k ]) ;
return 1;
}
}
13
2.3
Corectitudinea
2.4
Complexitatea
14
References
[1] M.C.Golumbic, Algorithmic Graph Theory and Perfect Graphs
[2] J. Spinrad, Efficient Graph Representation
[3] M.Habib, C.Paul, L.Viennot, Partiton refinment techniques: an interesting algorithmic toolkit
[4] M.Habib, C.Paul A new vertex splitting algorithm for cograph recognition
[5] R. McConnel, Jeremy Spinrad, Modular Decomposition and Transitive
Orientation
[6] R.McConnel, J. Spinrad Linear time transitive orientation
[7] R. McConnel, F.Montgolfier, PQ Trees and Modular Decomposition
[8] A.Counier, M.Habib, A new linear algorithm for modular decomposition
[9] M.Habib. F.Montgolfier, C.Paul, A simple linear-time modular decomposition algorithm for graphs, using order extending
[10] C.Capelle, Decomposition de graphes et permutations factorisantes, PhD
thesis, Univ. Montpellier, 1997
[11] F.Montgolfier, Trouver larbre de decomposition modulaire dun graphe
a partir dune permutation factorisante, 2000
[12] E. Dahlhaust, J. Gusted, R. McConnell Efficient and Practical Modular
Decomposition
15