Beruflich Dokumente
Kultur Dokumente
Maximiliano Illbele
16 de agosto de 2012
ndice
1. Coloreo y repaso de grafos
1.0.1. BFS-DFS . . . . . . . .
1.1. Coloreo . . . . . . . . . . . . .
1.1.1. Nmero Cromtico . . .
1.1.2. Algoritmo Greedy para
1.1.3. Propiedades de Greedy .
1.1.4. Heursticas . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
. 5
. 6
. 6
. 7
. 8
. 10
2. Flujos en networks
2.1. Algoritmo de Greedy para hallar Flujo . . .
2.1.1. Ejemplos de Greedy . . . . . . . . .
2.1.2. Complejidad de Greedy . . . . . . . .
2.2. Algoritmo de Ford y Fulkerson . . . . . . . .
2.2.1. Lema del Camino Aumentante . . . .
2.3. Teorema: Max-Flow Min-Cut . . . . . . . .
2.3.1. Complejidad de Ford Fulkerson . . .
2.4. Algoritmo de Edmonds Karp . . . . . . . . .
2.4.1. Complejidad de Edmonds-Karp . . .
2.4.2. Ejemplo de Edmonds Karp . . . . . .
2.4.3. Pseudo-Cdigo de Edmonds Karp . .
2.5. Algoritmos Tipo Dinic . . . . . . . . . . . .
2.5.1. Esquema general Tipo Dinic . . . . .
2.5.2. Ejemplo de Dinic . . . . . . . . . . .
2.5.3. Pseudo Cdigo algoritmos Tipo Dinic
2.5.4. Complejidad de Dinic . . . . . . . . .
2.6. Algoritmo Wave de Tarjan . . . . . . . . . .
2.6.1. Pseudo Cdigo de Wave . . . . . . .
2.6.2. Complejidad de Wave . . . . . . . . .
2.6.3. Ejemplos de Wave . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . .
. . . . .
. . . . .
coloreo
. . . . .
. . . . .
.
.
.
.
.
.
12
14
14
15
15
16
20
21
23
24
27
28
29
30
32
33
35
36
36
38
39
3. MST
3.1. Kruskal . . . . . . . . . . . . . . . . . . .
3.1.1. Pseudo Cdigo de Kruskal . . . . .
3.1.2. Teorema: Kruskal devuelve un MST
3.1.3. Complejidad de Kruskal . . . . . .
3.1.4. Kruskal Delete . . . . . . . . . . .
3.1.5. Complejidad Kruskal Delete . . . .
3.1.6. Ejemplo de Kruskal . . . . . . . . .
3.2. PRIM . . . . . . . . . . . . . . . . . . . .
3.2.1. Pseudo Cdigo de Prim . . . . . .
3.2.2. Correctitud de Prim . . . . . . . .
3.2.3. Ejemplo de Prim . . . . . . . . . .
3.3. Implementaciones de Union Find . . . . .
3.3.1. Union Find con listas enlazadas . .
3.3.2. Union Find con Representantes . .
3.3.3. Union Find con ranking . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
41
42
43
43
44
44
44
45
46
46
46
47
48
48
48
49
4. Matchings
4.1. Transformacin del problema de Matching a uno de flujo maximal
4.2. Teorema de Hall . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3. Complejidad del Algoritmo de Matching . . . . . . . . . . . . . .
4.4. Grafos con Peso . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.1. Algoritmo de Gross . . . . . . . . . . . . . . . . . . . . .
4.4.2. Ejemplo del algoritmo de Gross . . . . . . . . . . . . . .
4.5. Prueba del teorema de HALL . . . . . . . . . . . . . . . . . . . .
4.6. Teorema del Matrimonio . . . . . . . . . . . . . . . . . . . . . . .
4.7. Minimizar la Suma . . . . . . . . . . . . . . . . . . . . . . . . . .
4.7.1. Ejemplo de Matching que minimiza la Suma (A ojo) . . .
4.7.2. Algoritmo Hngaro . . . . . . . . . . . . . . . . . . . . . .
4.7.3. Ejemplo del algoritmo Hngaro . . . . . . . . . . . . . . .
4.7.4. Complejidad de algoritmo Hungaro . . . . . . . . . . . . .
4.7.5. EJEMPLO DEL MEJORADO (FALTA) . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
51
51
53
53
53
54
55
60
61
62
62
63
63
65
67
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
68
71
74
75
80
80
87
.
.
.
.
90
90
90
91
91
6. P-NP
6.1. La clase P .
6.2. La Clase NP
6.3. Co-NP . . .
6.4. SAT . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Trapping
.
.
.
.
2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
92
92
94
94
96
97
100
101
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
102
102
102
102
102
103
103
104
104
104
104
105
105
107
107
108
109
110
110
111
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1.
1<
<<
<<
<<
<
Notacin usual
{x, y} xy
Vecinos de un nodo x: (x) = {y V : xy E}
Grado2 o Valencia de un vrtice: d(x) = (x)
Menor valencia de G: = mn{d(x) : x V }
Mayor valencia de G: = max{d(x) : x V }
Definiciones
Un grafo es regular si = , a veces llamados k-regular.
Un camino es una sucesin de vrtices x1 , x2 , . . . , xt todos distintos tales que
xi xi+1 E.
Un grafo es conexo si par de vrtices un camino entre ellos.
Conexo
1 ==
4
==
==
==
_3
Disconexo
_5
1 ==
==
==
==
_3
4 ==
==
==
==
2
En general definimos x y camino entre x e y.
Edges.
Degree.
n(n1)
2
Si G es conexo n 1 m
1.0.1.
BFS-DFS
DFS(x)-Depth First Search3
A
z ???
zz
??
z
??
zz
z
?
zz
_
_
D
C
B
y @@ mmm
yy mmmmm@@@
y
y m
@@
yyymymmmm
@
m
m
E
DF S(A)
N ivel 0
N ivel 1
N ivel 2
D@
N ivel 3
@@
@@
@@
@
N ivel 4
N ivel 5
A?
??
zz
z
??
z
z
??
zz
?
z
z
_D
_
B
C
y @@ mmm
yy mmmmm@@@
y
y m
@@
yyymymmmm
@
mm
E
1.1.
A
ss ???
s
s
??
ss
??
sss
s
?
s
ss
C
N ivel 0
N ivel 1
N ivel 2
N ivel 3
Coloreo
FF
x
FF
xx
FF
x
FF
xx
x
F
x
x
_ D(2)
_ C(3)
B(2)
FF kkk
x
xx kkkkkFkFF
x
FF
x kk
FF
xxxkxkkkkk
k
E(1)
G(1)
F (2)
1.1.1.
Nmero Cromtico
1.1.2.
Orden alfabtico
Vrtices A B C D E
Color
1 2 1 2 1
F
3
G
4
Orden alternativo
G C D F B A
1 2 3 2 1 2
E
1
Este paso es slo ilustrativo no forma parte de una demostracin formal ya que no sabemos si n > 3
n = 3.
(G) 3
Y est claro que con 3 colores alcanza definimos:
C cuando i = 2r + 1
Corolario: si C2r+1 G (G) 3
Definicin: un grafo G es bipartito si: (G) = 2
Teorema: G es bipartito @C2r+1 G
Ms an existe un algoritmo de complejidad polinomial para determinar si G es bipartito o no.
Prueba: el algoritmo que daremos da un coloreo (propio) con dos colores, si (G) = 2,
y si el algoritmo colorea con ms de 2 colores entonces veremos que existe C2r+1 G
(G) 3
En realidad esto lo haremos para cada componente conexa de G.
Vamos a suponer G conexo.
Sea x V , y corramos BF S(x) y tomemos el siguiente coloreo que puede no ser
propio:
0 Nivel BF S(x), z es Par
C(z) =
1 Nivel BF S(x), z es Impar
Si ese coloreo es propio ya est.
Supongamos que no v, w : vw E : C(v) = C(w)
Como vw E y estamos usando BFS, Si v fue puesto antes que w en el rbol entonces
debe ser:
nivel(w) = nivel(v + 1) Absurdo pues nivel(v) nivel(w) (2)
O bien nivel(v) = nivel(w) Hay un ciclo impar (G) 3
1.1.3.
Propiedades de Greedy
Analizando a Greedy, podemos decir que en ciertos casos puede andar muy mal
Ejemplo:
i es Impar
Sea G : V = {1, . . . , 2r} y con E = ij
y j 6= i + 1
j es P ar
Para simplificar veamos el grafo correspondiente a r = 4
x1 BUQQUUU x3 BQQ mmx5 B iiimimx7
BBQQ|QU|Q|UUUU BmBmQmQ|Q|Q|iiiiBimBmm|||
B| QmQmmUUBiU|ii QmQmm B|
|m|BmBmiBmBimiiQiQi|Q|iQm|QBmUBmBUmBUmUUQUQ|UQ|Q|QBBBB
|
| mii
| m QQ | UUUQUQ
x2 imi x4 m
x6
x8
8
1
x1
x2
2
x3
x4
3
x5
x6
4
x7
x8
1 i es impar
nos queda que (G) = 2
2 i es par
Conclusin:
Greedy(G) devuelve un coloreo que usa r colores, pero vimos que (G) = 2.
Sin embargo . . .
Propiedad: G un ordenamiento {x1 , . . . , xn } de los vrtices de G en el cual Greedy()
obtiene: (G)
Prueba: sea t = (G)
Induccin en t:
Si t = 1 obvio.
Supongamos que vale para t 1
Orden de los vrtices:
Los de V1 < los de V2 < . . . < los de Vt , en Vi los ordeno como quiero.
Por hiptesis inductiva hasta Vt1 lo coloreamos con t 1 colores.
Los de Vt no estn unidos entre si Greedy en cada uno de sus vrtices usar uno
de los primeros t 1 colores o el color t, nunca hay conflicto entre ellos que demande un
color t + 1.
Propiedad: (G) + 1
Prueba: usar Greedy en cualquier orden.
Cuando vayamos a colorear xi lo peor que puede pasar es que todos los vecinos ya
estn coloreados y con colores distintos, esto forzara a Greedy() a usar un color distinto
a esos d(xi ) de esos colores.
Pero d(xi ) Greedy con + 1 colores se las arregla.
Heursticas
1. Welsh-Powell
Greedy en el orden: d(x1 ) d(x2 ) . . . d(xn )
2. Matul-Marble-Isaacson
xn : d(xn ) =
Sea Gn1 = Gn xn
Tomo xn1 : Gn1 (xn1 ) = (Gn1 ) y as seguimos . . .
1 >MMM 3 ; qqqqq5
>> MMM qqq;qq;qq;q
>> qqMqqMqqM ;
q>qq MM ;
q
qqqq >> MMM;M;
qqqqq
2
4
6
2
6
7
3
qqq
qqqqqqqqq
q
qqqqq
qqqqqqqqq
qqq
3 > qqq5
q>q>qq>qqqqq
qqqq >>>
qqqqqqqqq
>
qq
qqqqq
4
pp5
ppppp
p
p
p
p
ppppp
ppppp
p
p
p
p
pp
ppppp
3
2
O lo mismo DF S(x).
O DF S(x).
10
4. D-Satur
d5 (x) = #de colores de los vecinos coloreados de x .
Corre Greedy con un orden dinmico eligiendo como prximo vrtice el que tenga
d5 ms grande.
11
2.
Flujos en networks
+ (x) = {y V : xy E}.
(x) = {y V : yx E}.
(x) = + (x) (x).
Definicin: dado un network N = (V, E, C) y vrtices distinguidos s, t V , un flujo
en N , de s a t es una funcin f : E R tal que:
2. Conservacin:
f (xy) =
f (yx) x 6= s, t
y+ (x)
y (x)
3. s Productor:
X
f (sy)
f (ys)
y (s)
y+ (s)
10
Como s produce se llama la fuente9 y t se llamar
.
P resumidero
y (x)
Viabilidad.
Source.
10
Sink.
9
12
0
x 6= s, t
V (f ) x = s
D x = t
P
xV
f (xy)
xA
yB
xy E
X
Outf (x) =
X X
f (xy)
(1)
xV y+ (x)
xV
f (xy)
x, y V
xy E
= f (V, V )
(2)
Inf (x) =
f (yx)
xV y (x)
xV
f (yx)
x, y V
yx E
= f (V, V )
( 3) Por definicin de Inf (x).
? Nos queda: f (V, V ) f (V, V ) = V (f ) D
{z
}
|
=0
V (f ) = D
13
(3)
G( xy)
Si no
2.1.
Ejemplos de Greedy
?A
C@
@
@@
@@
@
s>
>>
>>
>>
>
E
~>
~
~
~~
~~
> G >>
>>
~~
~
>>
~
~
>>
~~
?t
@@
@@
@@
@
da: f (EF ) = 15
Ejemplo: todas las capacidades son 1000 excepto: C(CD) = 1 y C(CB) = 900
/B
A
G >>
? 00
>>
00
>>
0
>>
00
0
s?
?t
??
000
??
00
??
0
?
/
D
C
14
Complejidad de Greedy
Greedy
En Greedy una vez que un lado se satura, es decir f (xy) = C(xy), no se vuelve a
usar, ya que no se devuelve flujo.
Adems sabemos que por cada aumento se satura al menos un lado.
Hay a lo sumo m aumentos.
Complejidad(Greedy) = m O(m) = O(m2 )
2.2.
O bien: xi xi+1 E : f (xi xi+1 ) < C xi xi+1 estos son los lados Forward.
O bien: xi+1 xi E : f (xi+1 xi ) > 0 i.e. que haya mandado flujo, lados Backward.
Hasta que no se pueda ms buscar caminos aumentantes y mandar flujo por ellos.
12
Augmenting path.
15
2.2.1.
f (xi+1 xi )
para los lados backward
Elijo = mn{i }
Aumentar f es tomar
f (xy) =
f (xi+1 xi ) Si xy = xi+1 xi backward
f (xy)
en caso contrario
Queremos ver que f es flujo y que V (f ) = V (f ) +
Feasability: Obvio por definicin de i , .
Conservacin: x 6= s, t x = xi : 0 < i < r.
Hay que analizar 4 casos:
+
+
+
16
1. s x1
Outf (s) = Outf (s) +
Inf (s) = Inf (s)
V (f ) = V (f ) +
2. s x1
Outf (s) = Outf (s)
Inf (s) = Inf (s)
V (f ) = V (f ) ()
= V (f ) +
=
C(xy)
xS
yS
xy E
17
V (f ) Si x = s
0
Si x 6= s pues t 6 S
X
Outf (x) Inf (x) = 0 + . . . + 0 + V (f )
xS
= V (f )
X
X
V (f ) =
Outf (x)
Inf (x)
xS
xS
X
X
=
f {x}, V
f V, {x}
xS
(4)
xS
= f (S, V ) f (V, S)
= f (S, S S) f (S S, S)
(5)
S)
S)
=
f (S,
+ f (S, S) f (S, S)
f (S,
(6)
= f (S, S) f (S, S)
( 4) Por la observacin.
( 5) V = S S.
( 6) Disjuntos.
18
2. V (f ) = f (S, S) f (S, S)
| {z }
0
| {z }
<0
Hip(3)
Cap(T ) V (g) g
En particular elijo como flujo a f y me queda:
2
Hip
19
2.3.
En todo network el valor de todo flujo maximal es igual a la capacidad de todo corte
minimal, es decir si f es maximal S corte : V (f ) = Cap(S).
Demostracin: dado f maximal13 construyamos S recursivamente as:
s S por definicin.
Def
xy E
f (S, S) = C(S, S) = Cap(S)
xS
f (yx) = 0 f S, S = 0
Si y 6 S
yx E
V (f ) = f (S, S) f (S, S)
= Cap(S) 0
= Cap(S)
20
x1
~?
~
~~
~~
~
~
/ x2
s@
@@
@@
@@
@
/ y3
x3
Capacidades: todas
2 salvo: st : 1000 x1 y1 : 1 x2 y2 : r x3 y3 : r2
1+ 5
Donde: r = 2 es raz de: P (r) = r2 + r 1
Observacin:
1 r = r2
r r2 = r3
Satisface: 1 > r > r2 > . . . > rk > rk+1
Corramos < F F >
1. s, x1 , y1 , t : 1
2. s, x3 , y3 , y1 , x1 , x2 , y2 , t : r2
3. s, x2 , y2 , y3 , x3 , x1 , y1 , t : r3
4. s, x1 , y1 , y2 , x2 , x3 , y3 , t : r4
Luego < F F > repite (2) (3) (4) con r5 r6 r7 . . .
15
16
21
ri r
i=0
1
r
1r
1 r(1 r)
=
=2
1r
=
>>
>>
>>
>
?t
2. s, B, A, t : 1
Luego repetimos los pasos: (1 2) 2 106 veces, pero vamos a terminar en algn
momento.
Anexo: recordemos la notacin (u, v) que referencia la longitud del menor camino
entre u y v.
22
Lema: sea G un grafo conexo, dirigido o no, sea T = BF S(x) para algn x V ,
entonces:
z V (z, x) = N ivelT (z)
Prueba:
?
xk z E
T =BF S(x)
N ivelT (z) = j
|j k| 1
N ivelT (xk ) = k
Ya que como son vecinos la diferencia de nivel es 0 1.
|j k| 1
P ero
Absurdo.
j >k+1
2.4.
23
2.4.1.
Complejidad de Edmonds-Karp
17
24
dk+1 (x) + 1
(3)
= dk+1 (q)
Contradice (2) Absurdo!
dk (x) + 1
(5)
= dk (q) + 1 + 1
= dk (q) + 2
(2)
dk (z) = dk (x) + 1 ?
Pues estoy en < E K > entonces
d (x) = d (z) + 1
L
L
dL (t) = dL (x) + bL (x)
= dL (z) + 1 + bL (x)
dk (z) + 1 + bk (x)
= dk (x) + 1 + 1 + bk (x)
= dk (t) + 2
25
(7)
(8)
(9)
dL (t) dk (t) + 2
( 7) Por
( 8) Por el Lema Interno
( 9) Por ?
Por lo tanto cuando un lado se vuelve crtico recin puede volver a usarse cuando la
distancia a t haya aumentado en por lo menos 2.
# Veces que un lado puede volverse crtico = O(n)
Exactamente sera: n1
2
Complejidad de cada bsqueda BF S + Aumento = O(m) + O(n) = O(m)
En cada aumento al menos un lado se vuelve crtico.
Hay m lados y cada uno se vuelve crtico O(n) veces.
Complejidad(< E K >) = O(m) O(m) O(n) = O(nm2 )
26
2.4.2.
Capacidades
sA:20
Caminos
Primer Camino: s, A, B, t : 10
A C B E F I D K
s
s A A A A C C
20 20 20 3 10 3 10 10
s
sC:20
AB:20
s
A
s
10
A C
s s
7 10
AE:3
C
s
20
AF:10
AI:3
Bt:10
s
BI:10
BJ:10
CD:10
s
CK:10
Segundo
B E
A A
10 3
Camino: s, A, I, t : 3
F I D K J
A A C C B
10 3 10 10 10
t
B
10
G
E
3
Tercer Camino: s, C, D, t : 10
B E F D K I J G
A A A C C B B E
7 3 7 10 10 7 7 3
Cuarto
A C B
s s A
7 10 7
Camino: s, A, B, I, t : 7
E F K I J G
A A C B B E
3 7 10 7 7 3
H
E
3
t
I
3
H t
E D
3 10
H t
E I
3 7
Quinto Camino: s, C, K, I, B, D, t : 2
C K I A B E F J G H t
s C K I I A A B E E J
10 10 10 3
7 3 3 7 3 3 2
Dt:22
EG:10
s
EH:10
Sexto
C K
s C
8 8
Camino: s, C, K, I, A, E, G, D, t : 3
I A B E F J G H D
K I I A A B E E G
8 3
5 3 3 5 3 3 3
t
D
3
FG:10
GD:3
HD:10
It:10
Jt:2
s
KI:10
Sptimo Camino: s, C, K, I, B , A, F, G, E, H, D, t : 3
s C K I B J A F G E H D t
s C K I B B A F G E H D
5 5 5 5 5
5
5 5
3
3 3 3
Octavo
C K
s C
2 2
Camino?: No llega
I B J A
K I B B
2 2 2
2
27
at
F G
A F
2 2
z }| {
V (f ) = Outf (s) Inf (s)
= f ( sa) + f ( sc )
= 20 + 18 = 38
2.4.3.
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
EK( Network N)
{
F = 0 ; // F l u j o
v = 0 ; // Valor d e l F l u j o
S = V; // Corte
while ( t S ) { // m i e n t r a s e l v e r t i c e t e s t e en e l c o r t e
// b u s c a r camino y aumentar
Q = new_queue ( S ) ; // Crear c o l a
E [ x ] = x V ;
S = { s } ; // c o r t e
while ( head ( q ) 6= t ) {
x = head ( q ) ;
Forward_search ( x ) ;
Backward_search ( x ) ;
dequeue ( q ) ; // s a c o x de l a c o l a
}
i f (t S ) {
Aumentar_flujo ( ) ;
}
}
return (F , v , S ) // f l u j o , v a l o r , c o r t e
}
Forward_search ( v e r t i c e x )
{
f o r ( q + (x) && q 6 S ) {
i f ( f ( xq ) < C( xq ) ) {
enqueue (Q, q ) ; // Agregar q a Q
S = S {q } ;
A[ q ] = x ; // An c e s t r o
E [ q ] = min{E( x ) ,C( xq ) F( xq ) } ;
b [ q ] = 1 ; // f o r w a r d
}
}
}
28
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
Backward_search ( v e r t i c e x )
{
f o r ( q (x) && ( q 6 S ) ) {
i f ( f ( qx ) >0) {
enqueue (Q, q ) ; // Agregar q a Q
S = S {q } ;
A[ q ] = x ; // An c e s t r o
b [ q ] = 1; // Backward
E [ q ] = min{E( x ) ,F( qx ) } ;
}
}
}
Aumentar_Flujo ( )
{
p = t ; // p i v o t e
= E( t ) ;
v = v + ;
while ( p 6= s ) {
q = a[p];
i f ( b [ p ] == 1 ) { //FORWARD
f ( qp ) = f ( qp ) + ;
} else {
f ( pq ) = f ( pq ) ;
}
p = q;
}
}
2.5.
q + (p) con f (pq) < C(pq) q (p) : f (qp) > 0, pero que q ya est en el network
auxiliar, entonces agregamos un lado pq al network auxiliar si el N ivel(q) = N ivel(p) + 1.
Definicin: un flujo G se dice bloqueante o saturante si para todo camino:
29
2.5.1.
1 Dinic ()
2 {
3
f = 0;
4
Stop = NO;
5
while ( Stop == NO) {
6
NA = New_Na( f ) ; // c o n s t r u i r Network a u x i l i a r a p a r t i r de f
7
i f ( t NA) {
8
g = H a l l a r _ b l o q u e a n t e (NA) ; // b u s c o un f l u j o b l o q u e a n t e en NA
9
f = f g;
10
} else {
11
Stop = S ;
12
}
13
}
14
return f ;
15 }
Teorema
La distancia en NA18 sucesivos aumenta, por lo tanto hay a lo sumo n, NAs.
Demostracin:
Sea A un NA y A0 el siguiente NA, denotamos con la distancia en A y 0 la distancia
en A0 .
Como A y A0 se construyen con BFS 0
Queremos ver que vale el <.
Sea s = x0 , x1 , . . . , xr = t un camino en A0 .
Caso 1: i {1, . . . , r 1} : xi 6 A
(t) (xi )
0 (xi )
= i < r = 0 (t)
(10)
(11)
30
(12)
(13)
( 12) Por ?
( 13) Por < E K >
Caso 2-b: (xi+1 ) = i + 1
Observacin: es por < E K > no hace falta ver >.
31
2.5.2.
Ejemplo de Dinic
Primera Modificacin
Caminos (6)
sA:8
sA:0
caminos (4)
sAFt:4
sA:0
sD F AIt : 1
sC:7
sC:0
sAGt:3
sC:0
sD GAIt : 2
sD:10
sD:7
sAIt:1
sD:4
sE F AIt : 3
sE:12
AF:4
AG:3
sE:11
AF:0
AG:0
sCGt:2
sCHt:3
sCJt:2
sE:1
AF:4
AG:3
sE GAIt : 1
sEGBIt : 1
SEGBJt : 2
AI:8
AI:7
sDFt:3
AI:0
SE GCJt : 1
BI:2
BJ:2
CG:2
CH:3
CJ:5
DF:4
DG:2
EF:3
EG:5
EH:4
Ft:7
Gt:5
GB:4
Ht:4
It:9
Jt:15
BI:2
BJ:2
CG:0
CH:0
CJ:3
DF:1
DG:2
EF:3
EG:5
EH:3
Ft:0
Gt:0
GB:4
Ht:0
It:8
Jt:13
sEHt:1
BI:1
BJ:2
CG:1
CH:2
CJ:0
DF:0
DG:0
EF:0
EG:0
EH:1
Ft:0
Gt:0
GB:1
Ht:0
It:0
Jt:8
sE HCJt : 2
==
==
==
==
@ t
s?
D
??
??
??
?
E
()
()
4+ 5+ 5+ 2 + 9+ 7 = 32
ht+ cj+ gt+ bj + it+ f t
32
33
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
// Pre p t i e n e v e c i n o
Avanzar ( p i v o t e p ) {
Tomar q + (p)
A( q ) = p ; // a n c e s t r o de q e s p
G( pq ) = G( pq ) + ;
i f (G( pq ) == C ( pq ) ) {
B o r r a r q de + (p)
}
}
q = p;
}
34
2.5.4.
Complejidad de Dinic
Como cada Avanzar() mueve el pivote un nivel ms cerca de t entonces hay a lo sumo
n Avanzar() antes de un R o un I r n.
Complejidad(A . . . AX) = O(n) + O(n) = O(n)
(1) + (2) Complejidad(Paso Bloqueante de Dinic) = m O(n) = O(n m)
35
2.6.
Wave ( ) {
i n i c i a l i z a r () ;
olaForward ( ) ;
olaBackward ( ) ;
while (N != 2 ) {
olaForward ( ) ;
olaBackward ( ) ;
}
return g ;
}
i n i c i a l i z a r () {
g = 0;
(x 6= s){
B( x ) = 0 ; //No b l o q u e a d o
D( x ) = 0 // D e s b a l a n c e o
A( x ) = // s u b c o n j u n t o de a q u e l l o s que l e mandaron f l u j o a x
}
D( s ) = 0 ;
N = 1 ; // #V e r t i c e s b a l a n c e a d o s
(x + (s)){
G( sx ) = C( sx ) ;
D( s ) = D( s ) C( sx ) ;
D( x ) = C( sx ) ;
N++;
A( x ) = { s } ;
}
}
olaForward ( )
{
f o r ( x = s +1; To ; t 1){ // Orden BFS( )
i f (D( x ) >0)
ForwardBalance ( x ) ;
}
}
19
36
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
olaBackward ( )
{
f o r ( x = t 1 DownTo s +1){ // Orden BFS( )
i f (D( x )>0 && B( x ) == 1 )
BackwardBalance ( x ) ;
}
}
BackwardBalance ( v e r t i c e x ) {
while (D( x ) >0){
Tomar y A( x ) ;
m = min{D( x ) ,G( yx ) } ;
g ( yx )= g ( yx ) m;
D( x ) = D( x ) m;
i f (D( y ) == 0 ) {
N++;
}
D( y ) = D( y ) + m;
i f (G( yx ) == 0 ) {
A( x ) = A( x ) {y } ;
}
}
N;
}
ForwardBalance ( v e r t i c e x ) {
while (D( x )>0 && (+ (x) 6= ) ) {
Tomar y + (x) ;
i f (B( y ) == 1 ) {
+ (x) = + (x) {y}
} else {
m = min{D( x ) ,C( xy ) G( xy ) }
G( xy ) = G( xy ) + m ;
D( x ) = D( x ) m;
i f (D( y ) == 0 ) {
N++;
}
D( y ) = D( y ) + m;
A( y ) = A( y ) {x } ;
i f (G( xy ) == C( xy ) ) {
+ (x) = + (x) {y}
}
}
}
i f (D( x ) >0)
B( x ) = 1 ; // Bloqueamos x
else
N;
}
37
2.6.2.
Complejidad de Wave
(14)
O(1)
= O(n)
( 14) Pues en cada F B(x) a slo un lado le mandamos flujo parcial.
Compl(ola F orward)p = O(n) (2)
Luego:
(2) y ? ? Compl(W ave_bloqueante)p = O(n2 )
Ahora analicemos Compl(W ave_bloqueante)t .
Cada vez que un lado se satura completamente no puede volver a saturarse, pues si
Similarmente, un lado xy slo se puede vaciar totalmente una vez porque slo puede
hacerlo si y est bloqueado.
#Saturamientos + #V aciamientos 2m
Compl(W ave_bloqueante)t = O(m)
38
2.6.3.
Ejemplos de Wave
Aplicar Wave al siguiente Network Auxiliar
sA:8
0
sC:7
0
sD:10 7
sE:7
0
AF:4
0
AG:3 0
AI:8
7
CG:2 0
CH:3 0
CJ:5
3
DF:4
1
DG:2 2
EF:3
EG:5
EH:4
Ft:7
3
Gt:5
0
Ht:4
0
It:9
8
Jt:15 13
Nivel 0
s
-32
-25
A
8
4
1
0
C
7
5
2
0
Nivel 1
D
10
6
4
6
7
E
7
4
60
4
7
Nivel 2
F
G
4
3
8
5
11
7
11
4
6
1
2
0
0
I
1
0
H
3
60
3
-19
4
3
0
J
2
0
Nivel 3
t
7
12
13
16
18
19
39
0
0
5
0
0
1
0
1
0
1
0
0
0
1
11
Nivel 0
s
-32
-27
Nivel 1
A C
D
6 8 7
10
64 65
66
61 62
4
0 0
3
7
0
2
0
5
Nivel 2
E F
G
67 64
63
6 4 8
5
0
11
7
11
4
6
0
3
1
0
I H J
61 63 62
0 0 0
7
0
40
2
0
Nivel 3
t
7
12
13
16
18
25
27
3.
MST
Propiedad:
(1) T rbol T conexo y m = n 1
T no tiene ciclos y m = n 1
(2)
(3)
Prueba:
(1) (2) y (3) ya est.
?
41
(15)
= |V (T )| 1
= |E(T )|
(16)
( 15) Tb es rbol
( 16) Por HIP.(3)
Absurdo pues T {x, y} Tb E Tb |E(T )| + 1
?
Notacin
P
xyE(T 0 )
W (xy) = W (T ).
xyE(T )
3.1.
Kruskal
Repetir hasta tener n 1 lados, agregar el lado de menor peso que no forme ciclo.
Se necesita una estructura de datos de conjuntos disjuntos.
1. M akeset(x): construye un conjunto {x}.
2. F ind(x): devuelve el conjunto al cual pertenece x.
3. U nion(A, B): devuelve la unin de A y B.
20
42
3.1.1.
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
Kruskal ( )
{
//
(x V ){
Makeset ( x ) ;
}
//
Edges_Sort ( ) ; // Ordenar l o s l a d o s : W(E [ i ] ) W(E [ i +1])
m = 0 ; // c a n t i d a d de l a d o s
i = 1 ; // i n d i c e
//
while (M < N1){
A = find (x [ i ]) ;
B = find (y [ i ]) ;
i f (A 6= B) {
t r e e . add ( e [ i ] ) ; // a g r e g a r a l a r b o l e [ i ]
m++;
Union (A, B) ;
}
i ++;
}
3.1.2.
Ya que Kj Tj y f Tj
Complejidad de Kruskal
Volviendo al pseudocdigo:
= O(n)
= O(m log(m)) = O(m log(n2 )) = O(2m log(n)) = O(m log(n))
= n (2 Compl(F ind) + Compl(U nion))
Como en general >
Compl(Kruskal) = O(m log(n))
3.1.4.
Kruskal Delete
No demostraremos el orden pero diremos que la complejidad es: O m log(n) (log (log(n)))3
44
3.1.6.
Ejemplo de Kruskal
A
B
C
D
E
F
(0)
3
1
3
B
5
1
4
C D E F
3 1 3
1 4
7
7 4 2
4 3
2 3
(3)
A
1
(1)
B
A
E
A
(4)
A
3
D
B
F
D
F
(5)
F
B
(2)
D
C
A
3
F
F
~ 00@@@
00 @@3
002 @@
~~
~
00 @
~
1
00 _ E
A PPPP
00
PPP
PPP
0 4
5
P
PPP 00
3
P
_D
B@
4
@@
~
~
@@
~~
@
~~ 7
1 @@
~
~
C
45
_E
_D
_E
C
B
~~
~
~
1
~~
~~
4
F
3 ~~~
_D
3.2.
PRIM
Prim(x) = agregar el lado de menor peso que conecte x con otro vrtice, creando una
regin R luego ir agregando el lado de menor peso que conecte R con V R.
Generalmente se implementa con un heap.
3.2.1.
1 Prim ( v e r t i c e x )
2 {
3
(p V ){
4
Costo [ p ] = ;
5
Vecino [ p ] = NULL;
6
}
7
8
Costo ( x ) = 0 ;
9
M = 0;
10
Aux = V;
11
12
//FALTA CASO BASE
13
14
while (m < n1){
15
// p r e : c o s t o ( p )< c o s t o ( q )
16
(q (p)){
17
i f ( c o s t o ( q )> V( pq ) ) {
18
c o s t o ( q ) = W( pq ) ;
19
vecino (q) = p ;
20
}
21
}
22
Add( p , v e c i n o ( p ) ) ;
23
m++;
24
}
25
26
27 }
3.2.2.
q Aux
Correctitud de Prim
3.2.3.
Ejemplo de Prim
A
B
C
D
E
F
3
1
3
B
5
1
4
C D E F
3 1 3
1 4
7
7 4 2
4 3
2 3
(1) A
_E
(2) A
3
_E
(3) A
3
D
(4) A
3
_E
D
(5) A
3
_F
_E
_F
_C
_E
_F
1)
B
(5, A)
C
(, )
D
(3, A)
E
(1,A)
F
(3, A)
2)
(5, A)
(, )
(3,A)
(3, A)
3) (4, D)
(7, D)
(2,D)
4)
(4,D)
(7, D)
5)
(1,B)
3.3.
Union es O(1)
Find es O(n)
Recordemos que Kruskal hace: 2m Finds() y n 1 Unions().
O(mn) + O(n) = O(nm)
Como mn >
3.3.2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
m log(n)
no sirve.
| {z }
Ordenar los lados
Makeset ( x ) { //O( 1 )
R( x ) = x ;
}
Find ( x ) { // O( 1 )
return R( x ) ;
}
Union ( R1 , R2 ) { // O( n )
(x V ){
i f (R( x ) == R2 ) {
R( x ) = R1 ;
}
}
}
Compl(Kruskal) =
48
3.3.3.
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
Makeset ( v e r t i c e x ) {
(x) = x ;
Rk( x ) = 0 ; // Ranking
}
Find ( v e r t i c e x ) { // r e c u r s i v o a l a c o l a
i f ( (x) == x )
return x ;
e l s e return f i n d ( (x) )
}
Find ( v e r t i c e x ) { // i t e r a t i v o
y = x;
while ( y 6= (y) )
y = (y) ;
return y ;
}
/ Pre : F1 = Find ( x [ 1 ] ) ; F2 = Find ( x [ 2 ] ) ; F1 6= F2 /
Union ( F1 , F2 ) {
k1 = Rank ( F1 ) ;
k2 = Rank ( F2 ) ;
i f ( K1 > K2 ) {
(F2 ) = F1 ; // c a b e z a d e l 2 do apunta a l primero
} else {
(F1 ) = F2 ; // c a b e z a d e l primero apunta a l segundo
i f ( k1 == k2 ) {
Rank ( F2 ) = k2 +1;
}
}
}
49
n
2k
n
2k
2k n
k log2 (n).
21
1
0
2
1
{3,4}
2
{5,. . . ,16}
3
Bucket sort.
50
{17,. . . ,216 }
4
4.
Matchings
4.1.
DadoG = (X Y, E) creamos
el siguiente network.
N = X Y {s, t}, E, C
S no
no
S
E = sx
xy : y Y
yt
xX
yY
xy E
La capacidad de todos los lados es : 1.
Ejemplo
X
B
C
;;
;;
;;
;
;
A;
} AAA
AA
}}
}
AA
}}
A
}
}
B
A@
~C
@@
~~
@@
~
@@ ~~
@ ~~
1 @@
2
3
@@
~~
@@
~~
~
@@
~
@ ~~~
Teorema
Flujos maximales en N corresponden con matchings maximales en G y V (fmax ) = #lados.
Dicho de otra manera: existe una correspondencia entre matchings maximales en G
(bipartito) y flujos maximales enteros en N.
Prueba: dado un flujo entero f construimos un matching Mf y dado un Matching M
construimos un flujo entero fM .
S
Vf =
{x, y}
xyEf
Dado f sea Mf = (Vf , Ef ) :
Ef = {xy E : f ( xy) = 1}
Hay que ver que Mf es matching.
51
y1 6= y2
zy1 , zy2 Ef
x1 6= x2
x1 z, x2 z Ef
Absurdo
fM ( xy) =
1 Si xy E(M )
0 Si no
1 Si x V (M ) X
0 Si no
1 Si y V (M ) Y
0 Si no
fM ( sx) =
fM ( yt ) =
Como M es matching, est claro que:
Mf (z) = Outf (z) =
1 Si z V (M )
0 Si z 6 V (M )
52
z }| {
V (f ) = Outf (s) Inf (s)
X
=
f ( sx)
xX
= #{x : f ( sx) = 1}
= #{x : Inf (x) = 1}
= #{x : Outf (x) = 1} por ser f un flujo
= |Vf X|
= |EMf |
Por lo tanto flujos maximales enteros corresponden a matchings maximales.
(z) = {w V : z S : wz E}
zS
4.2.
Teorema de Hall
4.3.
Asumiendo |X| = |Y | = n
Matching inical: O(n2 ).
Extender el matching en un lado: O(n2 ).
Extenderlo O(n) veces.
Nos queda: O(n3 )
4.4.
53
2. Mimizar la suma.
El problema 1 a veces es llamado el: bottleneck problem23 , se resuelve con el algoritmo
de Gross y es bastante simple.
4.4.1.
Algoritmo de Gross
Dado C:
1. Ordenar los Ci,j como : b1 < b2 < . . . < bk (k n2 )
2. Tomar, para r= 1, . . . , k:
(Ar )i,j =
1 Si Ci,j br
0 Si no
(r es el umbral)
3. Hallar r: Ar tenga Matching perfecto y Ar1 no, eso da un matching M tal que:
f)} M
f
max{Ci,j : {i, j} E(M )} max{Ci,j : {i, j} E(M
23
54
4.4.2.
I
1
1
0
0
0
1
0
I
1
1
0
0
0
1
0
II
1
1
1
1
0
1
1
II
1
1
1
1
0
1
1
G
III
0
0
1
1
1
1
0
III
0
0
1
1
1
1
0
E
IV
1
1
0
0
0
1
0
IV
1
1
0
0
0
1
0
A
B
C
D
E
F
G
V
1
0
0
1
1
1
1
V
1
0
0
1
1
1
1
E
I
1
1
0
0
0
1
0
B
VI
1
1
0
0
0
1
0
VI
1
1
0
0
0
1
0
VII
1
1
0
0
0
1
0
VII
1
1
0
0
0
1
0
?
?
II
III
V
?
?
Extiendo el
II III IV
1
0
1
0
1
1
1
1
0
1
1
0
0
1
0
1
1
1
1
0
0
G E B
55
A
B
C
D
E
F
G
A
B
C
D
E
F
G
Matching
V VI
1
1
0
1
0
0
1
0
1
0
1
1
1
0
E B
I
1
1
0
0
0
1
0
I
1
1
0
0
0
1
0
B
Intento extenderlo
II III IV V VI
1
0
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
0
1
0
0
1
0
1
0
1
1
1
1
1
1
0
0
1
0
G E
E
II III IV V VI
1
0
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
0
1
0
0
1
0
1
0
1
1
1
1
1
1
0
0
1
0
G E B E B
VII
1
I
1
II
0
III
0
V
0
?
1
IV
0
?
B
VII
1
1
0
0
0
1
0
?
?
VII
1
1
II
0
III
0
V
0
?
1
0
?
B
A
B
C
D
E
F
G
A
B
C
D
E
F
G
I
1
1
0
0
0
1
0
B
I
1
1
0
0
0
1
0
B
II
1
1
1
1
0
1
1
G
II
1
1
1
1
0
1
1
G
III
0
0
1
1
1
1
0
E
III
0
0
1
1
1
1
0
E
E
IV
1
1
0
0
0
1
0
B
IV
1
1
0
0
0
1
0
B
A
B
C
D
E
F
G
V
1
0
0
1
1
1
1
E
VI
1
1
0
0
0
1
0
B
VII
1
1
0
0
0
1
0
B
V
1
0
0
1
1
1
1
E
E
VI
1
1
0
0
0
1
0
B
VII
1
1
0
0
0
1
0
B
I
1
1
0
0
0
1
0
B
II
1
1
1
1
0
1
1
G
C
III
0
0
1
1
1
1
0
E
E
I
II
III
V
?
IV
?
I
II
III
V
?
IV
?
IV
1
1
0
0
0
1
0
B
A
B
C
D
E
F
G
A
B
C
D
E
F
G
III
V
?
V
1
0
0
1
1
1
1
E
E
VI
1
1
0
0
0
1
0
B
I
1
1
0
0
0
1
0
B
I
1
1
0
0
0
1
0
B
II
1
1
1
1
0
1
1
G
II
1
1
1
1
0
1
1
G
C
VII
1
I
1
II
0
III
III
0
V
V
0
?
?
1
IV
0
?
II
B
Obtengo:
S = {C, D, E, G} = Filas etiqueteadas.
(S) = {II, III, V } = Columnas etiqueteadas.
Luego |(S)| = 3 < 4 = |S| @ Matching Perfecto.
Entonces tengo que subir el umbral.
56
III IV V VI VII
I
0
1
1
1
1
II
0
1
0
1
1
1
0
0
0
0
III
1
0
1
0
0
V
1
0
1
0
0
?
?
1
1
1
1
1
IV
0
0
1
0
0
?
E
B
E
B
B
E
E
III IV V VI VII
0
1
1
1
1
I
II
0
1
0
1
1
1
0
0
0
0
III
III
1
0
1
0
0
V
V
1
0
1
0
0
?
?
IV
1
1
1
1
1
?
0
0
1
0
0
E
B
E
B
B
E
E
Umbral 9
I II
1 1
1 1
1 1
1 1
0 1
1 1
1 1
A
B
C
D
E
F
G
III
0
1
1
1
1
1
1
IV
1
1
0
0
1
1
0
V
1
1
1
1
1
1
1
VI
1
1
0
0
1
1
0
VII
1
1
1
0
0
1
0
Busco Matching
A
B
C
D
E
F
G
A
B
C
D
E
F
G
I
1
1
1
1
0
1
1
I
1
1
1
1
0
1
1
G
II
1
1
1
1
1
1
1
II
1
1
1
1
1
1
1
G
III
0
1
1
1
1
1
1
III
0
1
1
1
1
1
1
G
IV
1
1
0
0
1
1
0
IV
1
1
0
0
1
1
0
V
1
1
1
1
1
1
1
V
1
1
1
1
1
1
1
G
VI
1
1
0
0
1
1
0
VI
1
1
0
0
1
1
0
VII
1
1
1
0
0
1
0
VII
1
1
1
0
0
1
0
A
B
C
D
E
F
G
?
I
II
III
V
A
B
C
D
E
F
G
?
I
1
1
1
1
0
1
1
G
I
1
1
1
1
0
1
1
G
II III IV V VI VII
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
0
1
0
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
0
0
?
G
G
G
II III IV V VI VII
1
0
1
1
1
1
I
1
1
1
1
1
1
II
1
1
0
1
0
1
III
V
1
1
0
1
0
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
0
0
?
G
G
A
G
A
A
Extiendo el Matching
A
B
C
D
E
F
G
I
1
1
1
1
0
1
1
G
II
1
1
1
1
1
1
1
G
III
0
1
1
1
1
1
1
G
IV
1
1
0
0
1
1
0
A
V
1
1
1
1
1
1
1
G
VI
1
1
0
0
1
1
0
A
VII
1
I
1
II
1
III
0
V
0
1
0
?
A
Umbral de e2
I II
1 1
1 1
0 1
1 1
0 0
1 1
0 1
A
B
C
D
E
F
G
III IV
0
1
1
1
1
0
1
0
1
0
1
1
0
0
V
1
0
0
1
1
1
1
VI VII
1
1
1
1
0
0
0
0
0
0
1
1
0
0
Busco Matching
A
B
C
D
E
F
G
A
B
C
D
E
F
G
I
1
1
0
1
0
1
0
I
1
1
0
1
0
1
0
II
1
1
1
1
0
1
1
II
1
1
1
1
0
1
1
G
III
0
1
1
1
1
1
0
III
0
1
1
1
1
1
0
E
IV
1
1
0
0
0
1
0
IV
1
1
0
0
0
1
0
A
B
C
D
E
F
G
V
1
0
0
1
1
1
1
V
1
0
0
1
1
1
1
E
I
1
1
0
1
0
1
0
B
VI
1
1
0
0
0
1
0
VI
1
1
0
0
0
1
0
VII
1
1
0
0
0
1
0
VII
1
1
0
0
0
1
0
?
?
II
III
V
?
?
Extiendo el
II III IV
1
0
1
1
1
1
1
1
0
1
1
0
0
1
0
1
1
1
1
0
0
G E B
58
I
1
1
0
1
0
1
0
A
B
C
D
E
F
G
A
B
C
D
E
F
G
I
1
1
0
1
0
1
0
B
Matching
V VI
1
1
0
1
0
0
1
0
1
0
1
1
1
0
E B
II III IV V VI VII
1
0
1
1
1
1
1
1
1
0
1
1
1
1
0
0
0
0
1
1
0
1
0
0
0
1
0
1
0
0
?
1
1
1
1
1
1
1
0
0
1
0
0
?
G
E
E
II III IV V VI VII
1
0
1
1
1
1
1
1
1
0
1
1
II
1
1
0
0
0
0
III
1
1
0
1
0
0
V
?
0
1
0
1
0
0
1
1
1
1
1
1
1
0
0
1
0
0
?
G
E
B
E
B
B
VII
1
I
1
II
0
III
V
0
0
?
1
0
?
B
A
B
C
D
E
F
G
A
B
C
D
E
F
G
I
1
II
1
III
0
IV
1
V
1
VI
1
VII
1
1
0
1
0
1
0
B
1
1
0
0
0
1
0
B
1
0
0
0
1
0
B
II
1
0
0
1
1
1
1
E
E
V
1
1
0
0
0
1
0
B
I
1
1
1
1
1
1
0
E
E
III
0
VI
1
VII
1
1
0
1
0
1
0
B
D
1
1
0
0
0
1
0
B
1
0
0
0
1
0
B
1
1
0
1
1
G
1
1
0
1
1
G
C
1
1
1
1
1
0
E
E
A
B
C
D
E
F
G
IV
1
1
0
0
0
1
0
B
I
1
1
0
1
0
1
0
B
D
0
0
1
1
1
1
E
E
II
1
1
1
1
0
1
1
G
C
I
II
III
V
?
A
III
V
?
?
B
C
D
E
F
G
II
III
III
V
V
?
?
B
C
D
E
F
G
Extiendo
III IV
0
1
1
1
1
0
1
0
1
0
1
1
0
0
E B
E A
?
II
I
1
II
1
III
0
IV
1
V
1
VI
1
VII
1
1
0
1
0
1
0
B
D
I
1
1
1
1
1
1
1
0
E
E
III
0
1
0
0
0
1
0
B
1
0
0
0
1
0
B
1
0
0
0
1
0
B
IV
1
0
0
1
1
1
1
E
E
V
1
VI
1
VII
1
1
0
1
0
1
0
B
D
1
1
1
1
1
1
0
E
E
1
0
0
0
1
0
B
A
0
0
1
1
1
1
E
E
1
0
0
0
1
0
B
A
1
0
0
0
1
0
B
A
1
1
0
1
1
G
C
II
1
1
1
0
1
1
G
C
el Matching
V VI VII
I
1
1
1
I
II
0
1
1
III
0
0
0
III
V
V
0
0
1
1
0
0
?
?
1
1
1
1
0
0
?
II
E B
B
E A
A
59
I
II
III
III
V
V
?
?
?
I
I
II
III
III
V
V
?
?
?
II
4.5.
Prueba:
Obvio pues el matching induce una funcion : 1 1 de X en Y y la imagen de S
por esa funcin est incluida en (S)
11
60
(17)
(18)
(19)
(20)
(
(
(
(
4.6.
17)
18)
19)
20)
X
xw
d(x)
|{z}
(21)
= |w|
( 21) Por ser G regular.
Similar prueba si: W Y
Observemos que por ser G bipartito: Ex = E = Ey
|Ex | = |Ey | |X| = |Y |
Como 6= 0 |X| = |Y |
Por lo tanto para ver si existe un matching perfecto en G, basta ver que existe un
matching completo de X a Y .
Por el teorema de Hall basta entonces con ver: |S| |(S)| S X
Sea entonces S X
Sea e Es
xS
: e = xy
yY
y (x) (S)
e = x y E(s)
Hemos probado que: Es E(S)
|Es | |E(S) |
|S| |(S)|
|S| |(S)|
61
4.7.
Minimizar la Suma
Restamos a
I
A 0
B 4
C 0
D 9
cada fila
II III
3 5
5 0
5 6
0 3
su mnimo
IV
5
6
9
3
I
2
9
1
10
II III
5
7
10 5
6
7
1
4
IV
7
11
10
4
I II
0 3
4 5
-5 0
9 0
III
5
0
1
3
IV
2
3
1
0
62
Sumamos
I
A 5
B 9
C 0
D 14
5a
II
3
5
0
0
la columna I
III IV
5
2
0
3
1
1
3
0
Restamos el
I
A 3
B 9
C 0
D 14
Hall un
I
A 3
B 9
C 0
D 14
Matching
II III
1
3
5
0
0
1
0
3
de 00 s.
IV
0
3
1
0
n
o
M = AIV : 7; BIII : 5; CI : 1; DII : 1
Hall un matching que minimiza la suma(14).
4.7.2.
Algoritmo Hngaro
C 1 6
7
D 10 1
4
IV
7
11
10
4
63
III
5
0
6
3
IV
5
6
9
3
III
5
0
6
3
IV
2
3
6
0
3. Buscamos Matching de 00 s
A
B
C
D
I
0
4
0
9
II
3
5
5
0
III
5
0
6
3
IV
2
3
6
0
A
B
C
D
I
0
4
0
9
C
II
3
5
5
0
III
5
0
6
3
IV
2
3
6
0
A
B
C
D
I
0
4
0
9
6C
III
3
0
4
3
IV
0
3
4
0
II
3
5
5
0
I
0
4
0
9
6C
II
3
5
5
0
III
5
0
6
3
IV
2
3
6
0
6I
6
A
B
C
D
I
0
4
0
9
6C
II
3
5
5
0
III
5
0
6
3
IV
2
3
6
0
I II
6I
A 0 1
m=2 B
6 5
C 0 3
6
D 11 0
Referencias:
S (s)
S (s)
S (S)
S (S)
No lo modifico
Sumo m
No lo modifico
Resto m
64
III
5
0
6
3
IV
2
3
6
0
I
6
6. Busco Matching de 00 S
I
A 0
B
6
a) No encuentro:
C 0
D 11
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
b) Intento extenderlo:
A
B
C
D
I
0
6
0
11
C
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
A
B
C
D
I
0
6
0
11
C
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
A
*
I
*
Extiendo el matching
I
A 0
B
6
7. Llegu al Matching de 00 s:
C 0
D 11
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
A
B
C
D
I
0
6
0
11
C
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
A
B
C
D
I
0
6
0
11
C
II
1
5
3
0
III
3
0
4
3
IV
0
3
4
0
A
A mano
1. Tachar filas de S, y las columnas de (S).
2. De lo no tachado, calcular el mnimo m.
3. Restar de lo no tachado m.
4. Sumar, a lo tachado dos veces, m.
4.7.4.
65
I
*
I
*
S
S
A A
B C
(S) (S)
Referencias
A: puede haber ceros.
B: No hay ceros, no hay matching.
C: Ceros del Matching.
S (S) y S (S) no cambian.
Por lo tanto cualquier 0 de matching ah permanece.
En S (S) no hay ceros, por lo tanto no hay matching.
Slo queda por ver: S (S), donde puede haber ceros, pero ninguno del matching,
pues supongamos que hubiera uno en la columna j, fila i.
i 6 S, j (s).
Cuando revisamos la columna j buscamos el elemento del matching, hubieramos
agregado la fila i a S, absurdo.
Corolario: luego de un cambio de matriz, aumenta el matching, (i.e. se termina el paso)
o bien aumenta S.
Prueba:
En S (S) habr un nuevo cero, digamos en la columna j, al revisar la j si est libre
extendemos el matching.
Sino hay una fila i con {i, j} M :matching, por lo tanto agregamos la fila i a S.
Entonces S crece.
Observacin: i no formaba parte de S, pues por el lema anterior i debe estar en S.
Corolario: hay a lo sumo n cambios de matriz en cada paso, pues S slo puede crecer
n veces.
66
Por lo tanto:
Compl(Hungaro) = n Compl(paso)
Compl(paso) =
n
Compl(cambiar la matriz) + O(n2 )
|{z}
cambio de matriz
Compl(cambiar la matriz) = O(n2 )
Compl(paso) = O(n3 )
Compl(Hungaro) = O(n4 )
67
5.
25
68
Definiciones
Br (x) = {y Zn2 : d(x, y) r}
Un cdigo C detecta r errores si: C Br (x) = {x} x C
Un cdigo C corrige t errores si: Bt (x) Bt (y) = x, y C : x 6= y
Notacin: = mn{d(x, y) : x 6= y : x, y C}
Ejemplos:
1. C1 = {00, 01, 10, 11} (C1 ) = 1
2. C2 = {000, 011, 110, 101}
HHC2
C2
HH
HH
000
011
110
101
2
2
2
2
2
000
011
110
101
(C2 ) = 2
000000
010101
101010
111111
000000
010101
101010
111111
3
6
6
3
3
69
(C3 ) = 3
y Bd (x) C
Como y 6= x
no detecta d errores.
c errores:
2. Corrige b d1
2
Sea t = b d1
c.
2
Sean x, y C, x 6= y.
Supongamos Bt (x) Bt (y) 6= z Bt (x) Bt (y)
d(x, y)
d(x, z) + d(z, y)
2t
1
0 1 absurdo
(22)
(23)
d1
d(y, z) = |y z| = |y x e | = |e e | = d 1 + b
c
2
0
d1
c+1
2
Demostracin de ?
Si d = 2k + 1 (Impar)
d 1 + b d1
c = 2k + 1 1 k = k = b d1
c < b d1
c+1
2
2
2
Si d = 2k (Par)
c = 2k 1 (k 1) = 2k 1 k + 1 = k = k 1 + 1 = b d1
c+1
d 1 + b d1
2
2
5.1.
1
2
Cota de Hamming
2n
1 + n + ... +
n
t
Bt (x)
xC
71
Bt (x) =
t
S
r=0
|Bt (x)| =
t
X
|Sr (x)|
r=0
y Sr (x) d(x, y) = r
(x y) = r donde defino (x y) = e
e : |e| = r : y = e x
| {z }
Sr (0)
|Bt (x)|
xC
!
t
X X
n
=
r
r=0
xC
t
X
n
=
C
r
r=0
SEV.
72
Pero Z2 = {0, 1}
1*X = X
0*X = 0
Trivialmente est en C, bastara ver que 0 C.
C 6= x C x
x} C
| {z
=0
C es lineal si y slo si ()
C 6=
x, y C x y C
n
o
Teorema: C lineal = mn |x| : x C, x 6= 0
Prueba:
Sea w = mn{|x| : x C, x 6= 0}
Sean x, y C : x 6= y con d(x, y) =
= |x y|
Como C es lineal x y C y x y 6= 0, pues x 6= y w
Sea ahora x C, x 6= 0 con |x| = w
Entonces w = d(x, 0) , 0 C pues C es lineal.
Como es la menor distancia tenemos que w
=w
Ejemplos: C1 , C2 , C3 son obviamente lineales
C1 = {11, 00, 01, 10} = Z22 w = = 1
C2 = {000, 110, 101, 011} w = = 2
C3 = {000000, 111111, 101010, 010101} w = = 3
Notacin: si C es lineal k denotar la dimensin de C.
Corolario: si C es lineal de dimensin k |C| = 2k
Prueba: obvio pues k = Dim(C) C ' Zk2 |C| = 2k
73
5.2.
Matriz generadora
Definicin: una matriz generadora G para C es una matriz cuyas filas forman una base
de C.
Por lo tanto si C es de dimesin k y longitud n y G es generadora de C entonces G es
Kx N .
G generadora G es Kx N, con k = Dim(x) y C = EF (G)
Recordemos que: EF (G) = {x Zn2 : U Zk2 : x = U G}
1 0 0 1 1 1
Sea G = 0 1 0 1 0 1
0 0 1 1 0 0
C = {x1 x2 x3 x4 x5 x6 : u1 , u2 , u3 : x = U G}
u1 u2 u3 G = u1 u2 u3 (u1 u2 u3 )u1 (u1 u2 )
0
C=
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
0
1
0
0
0
0
1
1
1
1
1
=2
1
En particular:
n1
z}|{
G=
..
.
Da el cdigo:
C = {x1 . . . xn : xn = x1 . . . xn1 } = {x1 . . . xn : x1 . . . xn1 xn = 0}
Bit parity Code tiene = 2
Otro ejemplo de cdigo lineal: cdigos de repeticin
z }| { z }| { z }| {
C = {x1 . . . xk x1 . . . xk . . . x1 . . . xk }
|
{z
}
r veces
n=rk
Una matriz generadora G = I I I I I
|
{z
r I0s
74
I = peso mnimo no nulo = r
}
5.3.
Matriz de chequeo
z
}|
{
t
I
A
A
I
|{z}
|{z}
k
es generadora de C n k |{z} |{z} es de chequeo.
kx k
nk
k
nk
Ut
[A |I]x = [A |I]
(U.A)t
t
= At U t (U A)t
= At U t At U t
=0
Entonces x N u([At I])
EF [I|A] N u([At |I])
Dim(N u([|{z}
At | |{z}
I
])) = k
k
nk
dep. indeptes
son iguales
Ejemplo:
1 0 0 1 1 1
1 1 1 1 0 0
G = 0 1 0 1 0 1 H = 1 0 0 0 1 0
1 1 0 0 0 1
0 0 1 1 0 0
x1
x2
1 1 1 1 0 0
x
3
Entonces N u(H) = x1 . . . x6 : 1 0 0 0 1 0 = 0
x4
1 1 0 0 0 1
x6
x1 x2 x3 x4 = 0
= x1 . . . x6 : x1 x5 = 0
x1 x2 x6 = 0
x4 = x1 x2 x3
= x1 . . . x6 : x5 = x1
que es lo que tena antes.
x6 = x1 x2
75
Ejercicio: calcular las palabras del cdigo que genera la siguiente matriz G.
1 1 0 1 1 1 0 0
0
0
1
1
0
0
0
1
0
Si G =
H=
0
0
1 0 1 1 0 0 0 1
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
1
1
0
1
1
0
1
1
0
0
1
0
1
en este caso = 3
1
0
Ejemplo
1
0
Sea H =
0
0
0
1
0
0
0
0
1
0
0
0
0
1
1
0
1
1
1
1
0
1
1
1
1
0
1
1
H es 4x 9
1
1
C = N u(H)
?
|C| = 2k = 25 = 32
k =94=5
9 variables - 4 independientes
(C) =
Como H no tiene la columna 0 ni columnas repetidas (C) 3
Como H (1) + H (5) = H (9)
28
Recordemos ei = 0 . . . 0 |{z}
1 0 . . . 0.
i
76
xz =0
= xyz :
yz =0
= {xyz : z = x = y}
= cdigo de repeticin
1 0 0
= H = 0 1 0
0 0 1
1010101
0110011
=H=
0001111
0000000
1 0 1 1
1 1 0 1 K = 4
0 1 1 1
0110101
0010011
K = 11
0001111
1111111
2n
Prueba: Hay que ver r = 1+n
Donde n = 2r 1 1 + n = 2r
2n
2n
r
= r = 2nr = 22 1r = 2k =
1+n
2
77
El algoritmo es:
1. Calcular Hy t .
2. Si Hy t = 0 Aceptar y.
3. Si Hy t = H (i) Aceptar y ei .
4. Si Hy t 6= 0, H (i) i hubo 2 errores, pedir retrasmisin.
Ejemplo:
1
0
H=
0
0
0
1
0
0
0
0
1
0
0
0
0
1
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
Se recibe: y = 01000100
Hy t = H (2) H (3) H (7)
0
0
1
1
1 0 1 0
(6)
=
0 1 0 = 1 = H
0
0
1
1
La palabra enviada fue x = y e6 = 011001100
Pero si recibo z = 000011000
Hz t = H (5) H (6)
0
1
1
1 0 1
(i)
=
1 1 = 0 6= 0, H i Hubo 2 errores
1
1
0
Por ejemplo me pueden haber mandado: 000000000 110011000
(i)
En el caso del Hamming Hy t siempre va a ser
0 algn
H
(i)
El algoritmo si se usa la matriz con H (i) =
Binario
Es ms fcil:
1. Calcular Hy t
2. Si Hy t = 0 aceptar y
3. Sino tomar i: (representacin binaria i)= Hy t y acepto y ei
78
Ejemplo
5
5 tiene
n =262 1 = 31 k = 31 5 = 26
5 =2
Supongamos que llega y = e1 e2 e11 e27 e31
Entonces:
79
5.4.
Cota Singleton
5.5.
Cdigos Cclicos
mod (1 + xn )
Prueba:
xW (x) = x w0 + w1 x + . . . wn1 xn1
= w0 x + w1 x2 + . . . + wn2 xn1 + wn1 xn
30
80
Aplico mdulo 1 + xn
xW (x)
(24)
(25)
Cociente
( 25) Conmuto.
Ejemplo
C = {0000, 1010, 0101, 1111}
C {0, 1 + x2 , x + x3 , 1 + x + x2 + x3 }
Tomo w = 1010 Rot(w) = 0101
1 + x2 x(1 + x2 ) = x + x3 mod (1 + x4 ) = x + x3 0101
Tomo w = 0101 Rot(w) = 1010
x + x3 x(x + x3 ) = x2 + x4
x2 + x4 mod (1 + x4 ) = x2 + 1 = 1 + x2 1010
Corolario:
Sea C cclico de longitud n,
W (x) C
Q(x) Z2 (x)
W (x)Q(x) mod (1 + xn ) C
81
clase pasada
mod (1 + xn ) C
La parte importante
Sea P (x) C Gr(P (x)) n 1
Para la segunda condicin:
Sean Q(x), R(x) Z2 (x) : P (x) = Q(x)G(x) + R(x): con Gr(R(x)) < Gr(G(x))
Gr(R(x)) < n 1
Como Gr(R(x)) < Gr(G(x))
Gr(Q(x)G(x)) n 1
Gr(P (x)) n 1
Entonces por Q(x)G(x) C
R(x) = P (x) + Q(x)G(x) C por ser lineal.
| {z } | {z }
C
Gr(R(x)) < Gr(G(x)) n 1
R(x) = 0
R(x) C
P (x) = Q(x)G(x) G(x)|P (x)
82
Teorema
Sea C cclico de longitud n, y G(x) el polinomio generador de C, con k = Dim(C)
Entonces:
1. Gr(G(x)) = n k
2. G(x)|1 + xn
3. G(x) = 1 +g1 (x) + . . . i.e. g0 = 1
Prueba
1. Sea P (x) : Gr(P (x)) n 1
Por el teorema anterior P (x) C Q(x) : P (x) = Q(x)G(x)
Si t = Gr(G(x)) n 1 Gr(P (x)) = Gr(Q(x)) + Gr(G(x))
| {z }
=t
Gr(Q(x)) n t 1
Viceversa si P (x) = Q(x)G(x) con Gr(Q(x)) n t 1
Entonces: Gr(P (x)) n t 1 + t = n 1
P (x) C
Gr(Q(x)) n t 1
C = P (x) : Q(x) :
P (x) = Q(x)G(x)
n
o
Esto da una biyeccin entre C y Q(x) : Gr(Q(x)) n t 1 = ?
|C| = | ? |
= |{Q(x) = q0 + q1 x + . . . + qnt1 xnt1 }|
= 2nt
Como k = Dim(C) |C| = 2k 2k = 2nt k = n t t = n k
2. Supongamos G(x) = g0 + g1 x + . . . + gnk1 xnk1 + xnk
Por lo demostrado en 1. sabemos que es de esa manera.
Multiplico por xk :
83
(26)
V (x) = m(x)G(x)
= (1 + x2 + x3 )2
= 1 + x4 + x6
1000101
Mando 1000101
84
Otra: m = 0110 x + x2
V (x) = (x + x2 )(1 + x2 + x3 )
= x + x 3 + x4 + x2 + x4 + x5
= x + x 2 + x3 + x5
0111010
Esto corresponde a la siguiente matriz generadora:
1 g1 g2 . . . gnk1
0 1 g1 g2
...
0 0 1 g1
g2
.. .. .. . .
.
..
. . .
.
0 0 0 0
1
1
0
G=
0
0
0
1
0
0
1
..
.
...
...
...
..
.
gnk1
...
gnk1
..
..
.
.
g1
g2
. . . gnk1
0 1 1 0 0 0
1 0 1 1 0 0
0 1 0 1 1 0
0 0 1 0 1 1
Segundo Mtodo
Idea: sea P (x) + P (x) mod G(x) = 0 mod (G(x))
G(x)|[P (x) + (P (x) mod G(x))]
Si el Gr(P (x)) n 1 ya est: P (x) + (P (x) mod G(x)) C
Truco
Dado m(x) con Gr(m(x)) k 1 Gr(xnk m(x)) n 1
En definitiva m(x) V (x) = xnk m(x) mod G(x) + xnk m(x)
Ejemplos:
m(x) = 1011 1 + x2 + x3 : n = 7 k = 4
x3 m(x) mod G(x) = 0
V (x) = 0 + x3 m(x) = x3 + x5 + x6 0001011
m(x) = 0110 x + x2
x3 m(x) = x4 + x5
?
85
0
0
..
.
1
x4 x + x3 (G(x))
x + 1 + x2 (G(x))
1 + x + x2 (G(x))
x5 x + x2 + x3 (G(x))
x + x2 + 1 + x2 (G(x))
1 + x (G(x))
x4 + x5 mod G(x) 1 +
x + x2 + 1 +
x x2
V (x) = (x4 + x5 ) mod G(x) + x4 + x5
= x2 + x4 + x5
001 0110
| {z }
m(x)
xnk
mod G(x) + xnk
xnk1
mod G(x) + xnk1
G = ..
..
..
..
.
.
.
.
n1
n1
x
mod G(x) + x
Tenamos:
x3
x4
x5
x6
mod
mod
mod
mod
G(x) 1 + x2
1
1
G(x) 1 + x + x2
G=
1
G(x) 1 + x
2
G(x) 1 + x
0
1 0 0 1
H = 0 1 0 0
0 0 1 1
0
1
1
1
1
1
0
1
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
derecha.
1 1 0
1 1 1
1 0 1
86
mod G(x) 1 + x2 + x3
x5
mod G(x) x + x3 + x4
x6
x + x3 + 1 + x2 + x3
1 + x + x2
mod G(x) x + x2 + x3
1
0
H=
0
0
5.5.1.
0
1
0
0
0
0
1
0
0
0
0
1
1
0
1
1
1
1
1
0
0
1
1
1
Teorema: sea C cclico de longitud n que corrige t errores, con G(x) = generador.
Asuma que se manda V (x) y llega W (x) : E(x) = V (x) W (x)
Con |E| t, error corregible.
Sean Si los sndromes: Si (x) = xi W (x) mod (G(x)) : 0 i n 1
Si i : |Si | t
E(x) = Rotni (Si )
= xni Si
mod (1 + xn )
mod G(x) = Q(x)(1 + xn mod G(x)) + Rot(U )
|
{z
}
mod (G(x))
0 pues G(x)|1+xn
mod G(x) 1 + x4 + x6 + x7
x9
mod G(x) x + x5 + x7 + x8
x10
x + x5 + x7 + 1 + x4 + x 6 + x7
1 + x + x4 + x5 + x6
mod G(x) x + x2 + x5 + x6 + x7
x11
mod G(x) x2 + x3 + x6 + x7 + x8
x12
x13
x2 + x3 + x6 + x 7 + 1 + x4 + x6 + x7
1 + x2 + x3 + x4
mod G(x) x + x3 + x4 + x5
mod G(x) x2 + x4 + x5 + x6
=1+x +x +x
|S0 | = 4 > 2
m
od G(x)
88
x9
m
od G(x)
x13
m
od G(x)
S2 = 1 + x + x2 + x3 + x5 + x6 + x7
S3 = 1 + x + x2 + x3 + x4
..
.
S6 = x3 + x4 + x5 + x6 + x7
S 7 = x4 + x5 + x6 + x 7 + x8
= x4 + x5 + x6 + x7 + 1 + x4 + x6 + x7
= 1 + x5
|S7 | = 2 2 = 7
Entonces: E(x) = xni Si mod (1 + xn )
= x157 S7 mod (1 + x15 )
= x8 (1 + x5 ) mod (1 + x15 )
= x8 + x13
V (x) = W (x) + E(x) = 1 + x + x4 + x5 + x6 + x9
Ejercicio: sea G(x) = 1 + x2 + x4 + x5 + x6 + x10 + x11 : n = 23 con t = 3
W (x) = 1 + x7 + x8 + x9 + x12 + x13
Respuesta:
V (x) = 1 + x8 + x9 + x12 + x13 + x14 + x15 + x16
Con S16 = 1 + x8 + x9
Definicin:
Polinomio Chequeador H(x) =
1 + xn
G(x)
Propiedad (ejercicio)
W (x) C H(x)W (x)
6.
P-NP
6.1.
La clase P
6.2.
La Clase NP
90
Formalmente
(I, S) N P j, t Ix J y P (x) tales que:
1. (Ix J, T ) P
2. Dado x I vale x S y J :
6.3.
(x, y) T
|y| P (|x|)
Co-NP
b
Es (x)
=
Complemento de
N o Si (x) = S
(I, S) (I, I S)
S Si (x) = N o
k-color NP k
Certificado: dado un coloreo con k colores ver que es propio es: O(m) = O(n2 )
Observacin:
Claramente P N P .
El problema del milln es P=NP?
6.4.
SAT
91
Reduccin Polinomial
k color P SAT
92
Di =
xi,j xi,r
j, r
j<r
j, r = 1, . . . , k
D = D1 . . . Dn
Sea Fi,j,l = xi,j xl,j
k
n
V
V
Fi,j,l
F =
j=1
i, l = 1
il E
Tomo B = C D F es O(n + m)
Ahora hay que probar que (G) k B es satisfactible.
Sea C un coloreo propio con k colores de G.
Debemos construir un asignamiento de valores a las variables.
xi,j x
bi,j {0, 1}
1 Si C(i) = j
Definimos x
bi,j =
0 c.c.
b = B(b
Debemos ver que : B
xi,j ) = 1
Todo vrtice tiene un color
i j k : C(i) = j
i j k : x
bi,j = 1
i : x
b x
bi,2 . . . x
bi,k = 1
{z
}
| i,1
ci
C
b=C
b1 . . . C
bn = 1
C
Todo vrtice tiene un slo color
i ! j k : C(i) = j
i @j 6= r : C(i) = j, C(i) = r
i, j < r : C(i) 6= j C(i) 6= r
x
bi,j = 0 x
bi,r = 0
o lo mismo: x
bi,j = 1 x
bi,r = 1
b =1
x
bi,j x
bi,r = 1 i, j < r D
Finalmente como el coloreo es propio
il E Tenemos C(i) 6= C(l)
i.e. il E, @j : C(i) = C(l) = j
il E, j :
(C(i) 6= j C(l) 6= (j)
|
{z
}
x
bi,j =1 x
bi,r =1
93
il E, j : x
bi,j x
bi,r = 1 Fb = 1
b=C
bD
b Fb = 1
B
Fin ()
b = 1 y queremos ver que: (G) k
bi,j con B
Ahora sabemos que existe x
C
bi,j = 1 (?)
b = 1 i, j : x
b
b
B = 1 D = 1 i, !j : x
bi,j = 1 definimos C(i) = el nico j con x
bi,j = 1
b
F = 1 ij E, C(i) 6= C(l) C es propio
? Cuento con la demostracin de la ida.
Observacin: Cook prob N P P SAT
Corolario: SAT P P = N P
6.5.
NP Completo
3-SAT es NP completo
3-SAT es como SAT pero en cada clasula debe haber exactamente 3 literales distintos.
3-SAT es NP completo
Prueba: probaremos que SAT P 3-SAT (por Cook).
b en CNF pero que
Es decir dada B en CNF debemos construir polinomialmente una B
tenga exactamente 3 literales por clasula y tal que B sea satisfactible B 0 lo es.
Supongamos que B = D1 . . . Dm : Di clasulas.
Variables de B = x1 , . . . , xn
Dada una clasula D arbitraria, definiremos una conjuncin de clasulas E (con ms
variables), y luego tomaremos:
B 0 = E1 E2 . . . Em donde Ei corresponde a Di .
94
95
#clasulas = k 2 lineal en k.
b = 1 j : L
bj = 1
Supongamos ahora D
Definamos:
yb1 = yb2 = . . . = ybj2 = 1
ybj1 = ybj = . . . = ybk3 = 0
b =(L
b1 L
b2 yb1 ) (b
b ) . . . (b
bj ) (b
bj+1 )
E
y 1 yb2 L
y j2 ybj1 L
y j1 b
yj L
|{z}
|{z} 3
|{z}
|{z}
=1
=1
HIP =1
=1
bk1 L
bk )
. . . (b
y k3 L
|{z}
=1
b=1
E
b=1
Veamos la vuelta: supongamos que E
b = 1. Supongamos que no.
Queremos ver que D
b
c
ck = 0 L
b
D = 0 L1 . . . L
r = 0 r
b = yb1 yb1 yb2 yb2 yb3 . . . ybk4 ybk3 ybk3
Nos queda: E
b=1
Como E
Tenemos:
yb1 = 1
yb2 = 1
yb1 yb2 = 1
yb3 = 1
. . . ybk4 = 1
yb2 yb3 = 1
y
b
=
1
k3
Absurdo
yb3 yb4 = 1
. . . ybk4 ybk3 = 1
b
y k3 = 1
6.5.2.
3-color es NP completo
96
6.5.3.
efefefnt YXP?PXYXYXYY
efefefefefnefnefnnn ??PPPXPXYPXYXYXYXYXYXYXYYYYY
e
e
e
f
e
e
f
e
?? PP
XX YY
e ff
nnn
eefefefefefeffff
?? PPPP XXXXXYXYXYXYXYXYYYYYYY
e
n
e
e
n
e
e
e
f
n
e
XXXXX YYYYYYY
f
e
f
P
n
e
?
f
e
e
P
f
n
P
XXXX
YYYYY
fff
eeeee
nn _
_ x4
_ x3
x 4
x3
x1, eee _ x1 fff
x2
x2 A
3
u
,,
A
3
u
A
u
33
AA
,,
uu
33
AA
uu
u
,,
'
AA
33
uu
u
,,
A
33
bb
efhmbefhm s
AA uuu
bb
e
bb
f
e
bb
e
f
h
bb
e
f
bb
e
h
bb
f
e
,,
33 bbbbbbbbbbbb eeeeefefefhfhfhhhmmm ||
uAu A
,,
uu Abb
bbbbbbbbbbbb33 eeeeeefefefefefefhfhfhfhfhhhmmmmm |||
bb
A
u
bb
bb
u
A
bb
ff
hh
mm
u bb
bbbb
,,
eeee3
AA
||
eeeefefeffffffffhhhhhh mmmmm
bbbbbbbbbbbbuuu
e
bb
e
A
bb
||
e
bb
e
,,
bb
e
e
A
u
|
e1,2
e
f
e
m
e
f
2,2
e
m
f
u
e
AAfffff
||
,,
eeeeee
uu
mmm
||
ueueeeeeee ffffffffffAAA
mmm
e
|
m
e
u
,,
e
m
e
e
|
AA
ff
ee u
|
mmm
,
eeeeee uuuu fffffffff
A
||
mmm
eeeeee
f
m
e
|
f
e
f
e
m
e
f
e
f
e
e2,1
e1,1
e2,3
e1,3
i1,1
{{
{{
{
{
{{
i1,2
CC
CC
CC
CC
_ i1,3
{{
{{
{
{
{{
i2,1 _
i2,2
CC
CC
CC
CC
i2,3
En general:
V = {s, t} {x1 , . . . , xn , x1 , . . . , xn } {W1 , . . . , Wm }
Con Wj = {ej,1 , ej,2 , ej,3 , ij,1 , ij,2 , ij,3 }
E = {st}{txk , txk , xk xk }nk=1 T1 . . .Tm E1 . . .Em F1 . . .Fm {sej,k }
Donde:
Tj = {ij,1 ij,2 ; ij,2 ij,3 ; ij,3 ij,1 }
Ej = {ej,1 ij,1 ; ej,2 ij,2 ; ej,3 ij,3 }
Fj = {ej,1 L1,j ; ej,2 L2,j ; ej,3 L3,j }
G tiene: 2 + 2n + 6m vrtices, polinomial.
G tiene: 1 + 3n + 3m + 9m = 1 + 3n + 12m lados, polinomial.
Hay que ver B satisfactible (G) 3
(Como G tiene tringulos (G) 3 (G) = 3)
97
1jm
k = 1, 2, 3
Veamos primero:
Sea C un coloreo de G de 3 colores queremos dar un asignamiento de valores a las
b) = 1
variables tal que: B(~x
Definamos:
1 Si C(xk ) = C(s)
xbk =
0 Sino
b) = 1
Queremos ver que B(~x
b) = 1
j basta ver: Dj (~x
b1,j L
b2,j L
b3,j = 1
Hay que probar j L
Veamos como Tj es un tringulo entonces los 3 colores estn representados.
Entonces:
k : C(ij,k ) = C(t)
ij,k ej,k E C(ej,k ) 6= C(ij,k ) = C(t)
sej,k E C(ej,k ) 6= C(s)
st E C(s) 6= C(t)
C(ej,k ) = tercer color
Como ej,k Lj,k E C(Lk,j ) 6= tercer color
tLk,j E C(Lk,j ) 6= C(t)
C(Lk,j ) = C(s)
bk,j = 1 Fin
Por definicin L
b : B(~x
b) = 1 debemos construir un coloreo propio
Dado un asignamiento de valores ~x
con 3 colores.
Definimos: C(s) = 1 , C(t) = 2 st No Crea Problemas (NCP).
Coloreamos:
C(xi ) = xbi
xi xi
(N CP )
C(xi ) = 1 xbi
Adems:
C(xi ), C(xi ) {0, 1}
C(t) = 2
txi , txi
b) = 1
Como B(~x
b) = 1 j = 1, . . . , m
Dj (~x
d
d d
i.e. L
1,j L2,j L3,j = 1
d
j, k : L
k,j = 1 (si hay ms de uno elijo alguno)
Coloreamos:
C(ej,k ) = 0
bk,j = 1 C(Lk,j ) = 1 Lk,j ej,k
Como L
Y coloreo:
C(ej,r ) = 2 : r 6= k
C(Lr,j ) {0, 1}
(N CP )
(N CP )
ej,r Lr,j
98
(N CP )
Como:
C(ej,k ) = 0
C(ej,r ) = 2 sej,k y los sej,r
C(s) = 1
(N CP )
Finalmente coloreamos:
C(ij,k ) = 2
C(ej,k ) = 0
ej,k ij,k
(N CP )
Y coloreamos: C(ij,r ) = 0 1 : r 6= k
ij,r ej,r
|{z} |{z}
0 1 =2
(N CP )
Finalmente el tringulo:
ij,1
}}
}}
}
}
}}
ij,2
AA
AA
AA
AA
_ ij,3
99
(N CP )
6.5.4.
2-SAT P
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
V ariables : x0 , . . . , xn1
SET EAR(v) : //M ACRO
X[v] = 1;
X[2n 1 v] = 0;
Q = Q P [v] P [2n 1 v]
N = { 0 , . . . , n1} ; // V a r i a b l e s no s e t e a d a s
M = { 0 , . . . , m1} ; // D i s j u n c i o n e s no s a t i s f e c h a s
Q = ;
f o r ( i = 0 , i < 2n , i ++){
x [ i ] = 1 ;
P [ i ] = { j M : i a p a r e c e en D[ j ] } ;
}
f o r ( j = 0 , j < m, j ++){ Sat [ j ] = 0 ; }
while ( N 6= )
Tomar i N, SETEAR( i ) ;
while (Q 6= ) {
E l e j i r j Q;
L ,R: D( j ) = {L ,R} ;
i f ( ( x [ L ] == 1 ) | | ( x [R] == 1 ) ) {
Sat [ j ] = 1 ;
Remover j de Q; // Pero no de M
} e l s e i f ( x [R] <0) {
SETEAR(R) ;
/ S i X[R] < 0 , d e b e s e r x [ i ] = 0 e n t o n c e s debo a s i g n a r x [R]
= 1 /
} e l s e i f ( x [ i ] <0) {
SETEAR(L)
/ E s t e e s t a d o e s cuando queda e l c a s o 00 , por l o t a n t o nos
equivocamos coon e l s e t e o de x [ i ]= 1 , por l o t a n t o hay
que cambiar /
} e l s e i f ( x [ i ] == 1 ) { // Anular t o d o s
t N, s M {
SAT( s ) = 0 ;
x [ t ] = x [ 2 n1t ] = 1;
}
Q = ;
SETEAR[ 2 n1 i ]
} else
return "NO SAT"
}
i N, j : SAT [j] = 1{
B o r r a r j de P [ i ] y P [ 2 n1 i ]
}
}
Return "SAT"
100
6.5.5.
HORN-SAT
HORN-SAT es como CNF-SAT pero donde cada clasula tiene a lo sumo un literal
positivo : xi positivo y xi negativo
Teorema: HORN -SAT P
Prueba:
x1 x2 . . . xk xk+1 x1 x2 . . . xk xk+1
x1 x2 . . . xk xk+1
El algoritmo empieza seteando todas las variables a f alse.
Recordamos: true true true
F alse ? true
true f alse f alse
Entonces todas las disjunciones de la forma:
x x2 . . . xk xk+1 van a ser true
{z
}
|1
|{z}
f alse
f alse
Las de la forma:
x1 x2 . . . xk x1 x2 . . . xk f alse
x1 x2 . . . xk f alse
|
{z
}
f alse
true
El nico problema son las disjunciones de la forma:
x true |{z}
x
f alse
f alse
Si hay una de esas, listo.
Si hay, seteamos estas variables a true (permanentemente).
Luego de eso se hacen true todas las variables xk+1 que estn en una disjuncin de la
forma: x1 . . . xk xk+1
En donde x1 , . . . , xk sean true.
Si en algn momento se llega a una contradiccin, no se puede satisfacer.
La contradiccin vendra de alguna de la forma:
x1 x2 . . . xk con todas las xi true
Ejemplo:
(x y z w) (x y) (z w x) (x z) (y z) y
yb = 1 zb = 1 x
b = 0, zb = 0
Pero supongamos que siguiera con . . . (y z U ) (u x)
b=1x
yb = 1 zb = 1 U
b=0
No se puede resolver x y
101
7.
7.1.
Hill Climbing
7.2.
Simulated Annealing
7.3.
Algoritmos Evolutivos
Tomar una poblacin de posibles soluciones (por ejemplo una cadena de bits).
1. Elegir un miembro de la poblacin.
2. Cambiar cada bit de ese miembro y evaluar si el cambio mejora la solucin.
Nos quedamos con el mejor:
Si hay uno repetir 2.
Sino, guardar el individuo en un conjunto B, y repetir 1.
3. Finalmente elegir el mejor de B.
Este algoritmo es evolutivo pero no gentico
7.4.
Algoritmos Genticos
Gentico Interaccin entre individuos.
AG.
Travel Salesman Problem.
102
Algo
Algo
Seleccin
7.5.
Ejemplo de un AG
Problema: dado un nmero natural escribirlo como suma, resta, producto y divisin
de los dgitos: 0, 1, . . . , 9 quizs repetidos (asociando a izquierda).
36
Adaptabilidad.
103
7.5.1.
n
o
Una posibilidad sera una cadena de smbolos del alfabeto A = 0, . . . , 9, +, , / pero
que debe tener: N Smbolo N .
Problema: crossover y mutaciones se pueden complicar.
Una posibilidad es hacer cadenas de pares (N ,operador) u (operador, N ) y suponer
que empezamos con 0.
Otra posibilidad: simplemente usar cadenas de bits, entonces un gen sern 4bits.
0000 0
0001 1
..
.
1001 9
1010 +
1011
1100
1101 /
1110 N ada
1111 N ada
El cromosoma ser el genotipo, el fenotipo en cambio tiene que ser una cadena:
0 Smbolo N Smbolo . . . que adems no tenga /0.
Genotipo F enotipo
Si es 14 15 lo descartamos.
Si es N y se requiere un Smbolo lo descartamos.
Si es un Smbolo y se requiere un N lo descartamos.
Sino se usa.
Si tenemos un /0 cambiar 0 por 1.
7.5.2.
7.5.3.
1
F enotipo31
P
si
F enotipo 6= 31
P
si
F enotipo = 31
7.5.5.
Operadores de Seleccin
Sea F =
Fi
i=1
la fitness promedio.
Ejemplo: 6 individuos.
Fitnesses
F1
F2
F3
F4
F5
F6
=
=
=
=
=
=
17,118
9,51
36,138
22,824
91,296
13,314
6
P
Fj = 190, 200
j=1
E1 = 0, 54
E2 = 0, 30
Fi
E3 = 1, 14
6
Ei =
E4 = 0, 72
190, 2
E = 2, 88
5
E6 = 0, 42
105
2 0, 84
i
P
3 1, 98
1 3
Ahora calculo:
Ej
4 2, 70
j=1
5 5, 58 2 , 4 , 5 , 6
66
Este mtodo puede producir lo que se llama Crowding de la poblacin por un
individuo o grupo de individuos y convergencia temprana a un mximo local, adems
tiene otro problema.
Hay 3 medidas de un operador de seleccin:
Bias.
Spread.
Eficiencia computacional.
Bias: es la diferencia entre FFi y el valor esperado de veces que el individuo ser seleci
cionado con el mtodo propuesto.
Bias(Ruleta) = 0.
Spread: rango de offspring que un individuo puede tener:
Ruleta(Spread(i)) = [0, n].
Conclusin: ruleta tiene Bias = 0 y Spread Mximo (malo).
Eficiencia: buena, pero se necesitan n randoms.
Alternativa a Ruleta: Stochastic Universal Sampling (SUS), usa un slo nmero al
azar, digamos r y toma los puntos: r, r + 1, r + 2, . . . , r + (n 1).
0,15
I1
En nuestro caso: r = 0, 15
1,15 2,15 3,15 4,15 5,15
I3
I4
I5
I5
I5
(0, 54)
(0, 34)
(1, 14)
(0, 72)
(2, 88)
(0, 42)
Bias = 0.
Pero Spread(i) = {bEi c, dEi e}.
Y un factor extra que tengo que elegir a quin reproduzco con quin.
106
7.5.7.
Por ejemplo se usan los restos: Ri = Ei bEi c y se distribuyan usando Ruleta o SUS.
Ejemplo:
bE1 c = b0, 54c = 0
bE2 c = b0, 30c = 0
bE3 c = b1, 14c = 1
bE4 c = b0, 72c = 0
bE5 c = b2, 88c = 2
bE6 c = b0, 42c = 0
R1
R2
R3
R4
R5
R6
= 0, 54
= 0, 30
= 0, 14
= 0, 72
= 0, 88
= 0, 42
I1
I5
I2
Orden
0,54 0,54
0,30 0,84
0,14 0,98
0,72 1,7
0,88 2,58
3
0,42
11
21
31
El asignamiento final nos queda:
y luego apareo al azar.
40
53
60
7.5.8.
Los mtodos que hemos visto con BIAS = 0 o casi pueden producir que al principio
cuando hay gran disparidad de Fitness, un grupo de individuos con alta fitness relativa,
cope la poblacin.
Impidiendo una bsqueda exhaustiva, de todo el espacio de bsqueda, por otro lado,
luego de que se estabilice la poblacin es difcil para un individuo con mayor Fitness
influenciar la bsqueda produciendo un estancamiento.
Por esto se han propuesto alternativas.
107
7.5.9.
Sigma Scaling
ci
En este mtodo se calculan las Ei en forma distinta E
F
=
6 0
1 + Fi2
c
Se define Ei =
: = desvo estndar de los Fi .
1
=0
Ventaja: al principio, suele se grande, entonces se evita Crownding, al final 0.
Entonces el mejor individuo se va a reproducir mucho ms.
Ejemplo: con las Fitness de antes obtengo = 30, 627
ci
Y voy calculando los E
c1 = 1 + 17, 118 31, 7 = 0, 762
Primero: E
2
i
P
ci
E
Ej
j=1
c1
E
c2
E
c3
E
c4
E
c5
E
c6
E
= 0, 762
= 0, 638
= 1, 072
= 0, 855
= 1, 973
= 0, 700
0, 762
1, 400
2, 472
3, 327
5, 3
6
Aplico Ruleta
Elijo n = 6, nmeros al azar
0, 15 0, 7 0, 22 0, 91 0, 46 0, 63
Multiplico por n = 6
0, 90 4, 2 1, 32 5, 46 2, 76 3, 78
I2
I5
I2
I6
I4
I5
Obtengo algo ms balanceado.
Si hubiera aplicado SUS: con r = 0, 15
0, 15 1, 15 2, 15 3, 15 4, 15 5, 15
I1
I2
I3
I4
I5
I5
Roletamiento
Fi
bi =
E
eT
P rj
eT
Mtodos de rango: se usa la Fitness para ordenar la poblacin y luego se usa una
medida que dependa slo de la posicin en esa poblacin.
Lineal Ranking: LR(pos) = (2 SP ) + 2(SP 1) pos1
n1
SP parmetro en [1, 2]
SP es por Selective Pressure
Estas tomaran el lugar de los Ei
i.e. sera: Ei = LR(P os(i))
Por ejemplo SP = 1 LR(pos)
= 1pos, no hay presin.
SP = 2 LR(pos) = 2 pos1
n1
SP (1; 2), por ejemplo SP = 1, 2
pos 1
LR(pos) = 0, 8 + 0, 4
n1
SP no tiene que ser fijo, podra ir aumentando para aumentar la presin.
Ejemplo: con las Fitness del ejemplo anterior
F2
< F6
< F1
< F4
< F3
< F5
Tomando SP = 1, 2:
E1
E2
E3
E4
E5
E6
= LR(3) = 0, 96 : 3 es la posicin
= LR(1) = 0, 8
= LR(5) = 1, 12
= LR(4) = 1, 04
= LR(6) = 1, 2
= LR(2) = 0, 8 + 0,4
= 0, 88
5
Seleccin Torneo
Seleccionar k (usualmente 2) individuos y quedarse con el mejor, en un torneo determinsticamente o probabilsticamente.
7.5.10.
Crossover
SinglePoint
TwoPointCroospoint
Mscara Binaria
Supongo que tengo esta mscara, generada al azar: 1,0,0,1,1,0,1,0,1,1.
P1 = 2
P2 = 4
9
2
7
3
2
6
5
6
109
3
3
1
9
6
8
5
0
8
9
Obtengo:
O1 = 2, 2, 3, 2, 5, 3, 1, 8, 5, 8
O2 = 4, 9, 7, 6, 6, 3, 9, 6, 0, 9
Partial Map Crossover
Qu pasa con codificacin del problema que depende de la posicin?
P1 = BIGAECJF DH
P2 = DJBF ECIGAH
Corta en dos lugares:
O1 = BIG|JECA|F DH
O2 = DJB|F IEC|GAH
Tambin se puede hacer con mscaras. Order Based
Cyclic Crossover
VERRRRRRRRRRRRRRRR
7.5.11.
Mutacin
3. Steady State
4. Migraciones
Inundacin: mato a los peores cada tanto, se usa mucho con restricciones muy cortas,
cada tanto tengo una subpoblacin no vlida pero la penalizo, pero es muy buena, luego
la mato.
7.6.
No Free Lunch
Referencias
[1] Biggs: Matematica Discreta
[2] Roberts, Applied Combinatorics
[3] Tarjan: Data Structures and Network Flows
[4] BFS: http://en.wikipedia.org/wiki/Breadth-first_search
[5] DFS: http://en.wikipedia.org/wiki/Depth-first_search
[6] rboles en Latex:
http://www.essex.ac.uk/linguistics/external/clmt/latex4ling/trees/
pstrees/
[7] Cdigo C en latex:
http://stackoverflow.com/questions/586572/make-code-in-latex-look-nice
37
111