ebook img

Algoritmos Combinatorios Notas del Dr. Luis B. Morales IIMAS, UNAM PDF

88 Pages·2014·0.36 MB·Spanish
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Algoritmos Combinatorios Notas del Dr. Luis B. Morales IIMAS, UNAM

Algoritmos Combinatorios Notas del Dr. Luis B. Morales IIMAS, UNAM 1 Los algoritmos combinatorios se clasifican acuerdo a su propósito: • Generación. Construcción de todas las estructuras de un particular tipo. • Enumeración. Computar el número de diferentes estructuras de un particular tipo • Búsqueda. Encontrar al menos un ejemplo de una estructura de particular tipo, o probar que no existe 2 Ejemplos de estructuras combinatorias: • Conjuntos y Listas X={1,2,4,5}, Y={1,4}, Z = [5,2,7] lista (importa orden) ordenaciones Producto Cartesiano XxY = {[1,1],[1,4],[2,1],[2,4],[4,1],[4,4],[5,1],[5,4]} Conjunto potencia 2X ={ Y⊆ X} • Gráficas (V,E), V vértices, E⊆{{x,y} | x,y ∈ V} aristas 3 • Sistemas de conjuntos X (X,B), X conjunto, B ⊆ 2 Ejemplo. X = {1,2,3,4,5,6,7} B ={{1,2,4},{2,3,5},{3,4,6},{4,5,7}, {5,6,1},{6,7,2},{7,1,3}} (diseños combinatorios) Propiedad. Cada pareja de X aparece en el mismo número de bloques, a saber 1 4 • Permutaciones. Llamamos permutación de un conjunto a cada una de las posibles ordenaciones de todos los elementos de dicho conjunto. Ejemplo. El conjunto = {1,2,3} tiene 6 permutaciones “1,2,3", "1,3,2", "2,1,3", "2,3,1", "3,1,2" y "3,2,1" Un conjunto finito de n elementos tiene n! (cid:3404) n*(cid:4666)n‐1(cid:4667)*…*2*1permutaciones (factorial de n) Una permutación sobre un conjunto X es una funciónbiyectivade dicho conjunto en sí mismo. Por ejemplo la función biyectiva dada por π (cid:4666)1(cid:4667) (cid:3404)3,  π(cid:4666)2(cid:4667) (cid:3404) 1,  π(cid:4666)3(cid:4667) (cid:3404) 2, corresponde a la permutación "3,1,2". 1 2 3 Notación π (cid:3404) (cid:4672) (cid:4673) 3 1 2 Generación de permutaciones aleatoria ( Knuth in The Art of Computer Programming) Para mezclarun arregloa of nelementos (indices 0,…,n-1) forifromn − 1 downto 1 do j ← random integer with 0 ≤ j ≤ i exchange a[j] and a[i] 5 Partición de un Conjunto Una partición de un conjunto no vacíoX es una colección de subconjuntos S de X tal que i X = (cid:1666)SS(cid:1665)S = (cid:1486). i i i   Ejemplo. X = {0,1,2,3,4,5,6,7,8,9,10,11} {0,1,2,3}, {4,5,6,7},{8,9,10,11} es una partición de X. 6 Programa que calcula las particiones de un conjunto function ( npart, jarray, iarray, more ) /*********************************************************************** / /* EQUIV_NEXT computes the partitions of a set one at a time. Discussion: A partition of a set assigns each element to exactly one subset. The number of partitions of a set of size N is the Bell number B(N). Licensing: This code is distributed under the GNU LGPL license. Modified: 30 July 2004 Author: MATLAB version by John Burkardt. Reference: A Nijenhuis and H Wilf, Combinatorial Algorithms, Academic Press, 1978, second edition, ISBN 0-12-519260-6. Parameters: Input, integer N, the number of elements in the set to be partitioned. Input, integer NPART, the number of subsets in the previous partition. Input, integer JARRAY(N), the number of elements in each subset of the previous partition. Input, integer IARRAY(N), the subset to which each element belongs in the previous partition. Input, logical MORE, is set to FALSE on the first call, and the input values of NPART, JARRAY and IARRAY are not needed. On subsequent calls, MORE should be TRUE, and NPART, JARRAY, and IARRAY should have the values of the output quantities NPART, JARRAY and IARRAY from the previous call. Output, integer NPART, the number of subsets in the new partition. Output, integer JARRAY(N), the number of elements in each subset of the new partition. Output, integer IARRAY(N), the subset to which each element belongs in the new partition. Output, logical MORE, is TRUE as long as the new partition returned is not the last one. When MORE is returned FALSE, all the partitionshave been computed and returned. */ 7 void equiv_next(int n, int *npart,int jarray[],int iarray[], int *more) { int i; int l; int m; if ( !( *more ) ){ *npart = 1; for ( i = 0; i < n; i++ ) { iarray[i] = 1; } jarray[0] = n; } else{ m = n; while ( jarray[iarray[m-1]-1] == 1 ){ iarray[m-1] = 1; m = m - 1; } l = iarray[m-1]; *npart = *npart + m - n; jarray[0] = jarray[0] + n - m; if ( l == *npart ) { *npart = *npart + 1; jarray[*npart-1] = 0; } iarray[m-1] = l + 1; jarray[l-1] = jarray[l-1] - 1; jarray[l] = jarray[l] + 1; } *more = ( *npart != n ); return; } 8 Problemas Combinatorios Los Problemas de búsqueda que estudiaremos son de varios tipos, dentro de los más famosos está el de la Mochila (knapsack problem) Mochila (problema de decisión) Instancia: Valores: p ,..., p 1 n Pesos: w ,..., w 1 n Capacidad: M Objetivo P n Pregunta: ¿Existe (x ,..., x ) en {0,1} tal que 1 n Σ p x≥ P i i Σ w x≤ M ? i i (Respuesta sí o no, para toda instancia del problema) 9 Mochila (problema de búsqueda) Instancia: Valores: p ,..., p 1 n Pesos: w ,..., w 1 n Capacidad: M Objetivo P n Encontrar: (x ,..., x ) en {0,1} tal que 1 n Σ p x≥ P i i Σ w x≤ M i i (si existe tal n-tupla) (igual que el problema de decisión, solo que encontramos la n-tupla (x ,..., x ) en caso que la respuesta de la búsqueda es sí) 1 n 10

Description:
Una partición de un conjunto no vacíoX es una colección de subconjuntos Si de . Agente viajero (traveling salesman problem, TSP). Problema de la
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.