コード例 #1
0
ファイル: ukkonen.c プロジェクト: pandres/Bioinformatica
NODO *regla2b(NODO * nodoActual, int g, int j, int i, int *e, char *S){

    int *nuevo_to;
    NODO *nuevo1;		// Es el que parte la arista
    NODO *nuevo2;		// Es la nueva hoja
    char* Saux;
    
    nuevo_to = (int *) malloc(sizeof(int));
    if(nodoActual->posS1!=0)  Saux=S1;
    else Saux = S2;

    //Nodo que parte la arista      
    *nuevo_to = nodoActual->from + g - 1;
    nuevo1 = crearNodo(0, nodoActual->padre, NULL, nodoActual->from, nuevo_to, Saux);
    //Actualizamos nodoActual
    nodoActual->padre = nuevo1;
    nodoActual->from = *nuevo_to + 1;
    nuevo1->hijos[s_i(Saux, nodoActual->from)] = nodoActual; // le asigno el hijo al nuevo1
    //Nodo que contiene a S[i+1]
    nuevo2 = crearNodo(0, nuevo1, NULL, i + 1, e, S);

    
//cuando digo que nuevo1 lo tiene a nuevo2 de hijo??????
    extension_regla2b(nuevo1, nuevo2, j, nodoActual->posS1, nodoActual->posS2);
    return nuevo2;
}
コード例 #2
0
ファイル: pgb.c プロジェクト: soviet/VCP-PGB
/**
 *
 * Funcion que corrige el arbol una vez creado, revisa si cada Funcion tiene
 * su sus argumentos respectivos, si le falta le agrega uno deterministicamente
 *
 **/
void rebuilt(Arbol *a)
{
  if(a != NULL)
    {
      if(funciones[a->valor] == 1)
	{
	  if(a->izq == NULL)
	    {
	      Arbol *aux;
	      int setear = abs((a->id % 16) - (a->valor % 16)) + 16;
	      aux = crearNodo(((setear < 32) ? setear: 16), contador++);
	      if(a->izq == NULL)
		a->izq = aux;
	      else
		a->der = aux;
	    }
	}

      if(funciones[a->valor] == 2)
	{
	  if(a->izq == NULL)
	    {
	      Arbol *aux;
	      int setear = abs((a->id % 16) - (a->valor % 16)) + 16;
	      aux = crearNodo(((setear < 32) ? setear: 16), contador++);
	      a->izq = aux;
	    }
	  if(a->der == NULL)
	    {
	      /* gramatica */
	      Arbol *aux;
	      int setear, valor;
	      /* Si el padre es un Funcion de Coloracion el  lado derecho tiene
		 que ser un terminal*/
	      if(a->valor < 7)
		{
		  setear = abs((a->id % 16) - (a->valor % 16) + 16);
		  valor = (setear < 32) ? setear: 16;
		}
	      /* Si el padre es un Funcion Generica el  lado derecho tiene
		 que ser una funcion de coloracion */
	      else
		{
		  setear = abs((a->id % 5) - (a->valor % 5));
		  valor = (setear < 5) ? setear: 4;
		}
	      aux = crearNodo(valor, contador++);
	      a->der = aux;
	    }
	}

      rebuilt(a->izq);
      rebuilt(a->der);
    }
}
コード例 #3
0
ファイル: huffman.c プロジェクト: brokendragon/PERDICE
int cargarArbolHuffman(struct nodo **raiz, BYTE *mem)
{
	struct nodo *aux, *nuevo;
	int pos_mem=0, pos_pos=0, dch=0;
	BYTE b;


	*raiz=crearNodo();
	readBits(mem, &pos_mem, &pos_pos, &b, 1);
	if (b == UNO)
	{
		readBits(mem, &pos_mem, &pos_pos, &b, 8);
		(*raiz)->c=b;
		return 2;
	}

	aux=*raiz;
	while (aux != NULL)
	{
		nuevo=crearNodo();
		nuevo->padre=aux;

		readBits(mem, &pos_mem, &pos_pos, &b, 1);
		if (b == 0)
		{
			if (dch)
			{
				aux->hdch=nuevo;
				dch=0;
			}
			else
				aux->hizq=nuevo;

			aux=nuevo;
		}
		else
		{
			readBits(mem, &pos_mem, &pos_pos, &b, 8);
			nuevo->c=b;

			if (dch)
			{
				aux->hdch=nuevo;
				aux=buscarNodoSinHdch(aux);
			}
			else
			{
				aux->hizq=nuevo;
				dch=1;
			}
		}
	}

	return pos_mem+1;
}
コード例 #4
0
ファイル: ukkonen.c プロジェクト: pandres/Bioinformatica
NODO *regla2a(NODO * nodoActual, int j, int i, int *e, char *S)
{
    NODO *nuevo;
    nuevo = crearNodo(0, nodoActual, NULL, i + 1, e, S);
    extension_regla2a(nuevo, j); // para los arboles generalizados
    return nuevo;
}
コード例 #5
0
/*Agrega un elemento en la posicion correspondiente a su prioridad.
 * cp: cola de prioridades a agregarle el elemento nuevo.
 * info: informacion a agregar en la cola de prioridades.
 * prior: prioridad de la informacion a agregar.
 */
void agregarElemP(ColaP* cp, char* info, int prior){
	Nodo* np = crearNodo(info,prior);
	if (cp->tam == 0){
		cp->pri = np;		
		cp->tam = 1;
		return;
	}
	Nodo* aux = cp->pri;
	int i = 0;
	for (i = 0; i < cp->tam && aux->prior < prior; i++)
		aux = aux->sig;	
	if (aux == NULL){
		aux = cp->pri;
		for (i=0; i < cp->tam && aux->sig != NULL; i++)
			aux = aux->sig;
		aux->sig = np;
		np->ant = aux;
		cp->tam += 1;
		return;
	}
	if (aux->ant == NULL){
		cp->pri = np;
	} else {
		aux->ant->sig = np;
	}
	np->sig = aux;
	np->ant = aux->ant;
	aux->ant = np;
	cp->tam += 1;
}
コード例 #6
0
void *atenderANodo(void *argConexion)
{
	SocketConecta *conexion = argConexion;


	while(estaConectado(conexion))
	{

		char nombrePaquete;
		t_nodo *nodo;
		recibirMensaje(conexion, &nombrePaquete,1);
		if(estaConectado(conexion))
		{
			if (nombrePaquete == CANTIDAD_BLOQUES)
				nodo = crearNodo(conexion);
			else if (nombrePaquete == BLOQUEAR_ATENDER_NODO){
				reservarConexionNodo(nodo);
				devolverConexionNodo(nodo);
			}
		}else
		{
			deshabilitarNodoPorDesconexion(nodo);
			loguear(LOG_LEVEL_INFO,"Se desconecto el nodo %s\n",nodo->nombre);
			cerrarSocketConecta(conexion);

		}
	}
	return 0;
}
コード例 #7
0
void capturaPolinomio( POLINOMIO *ptrPolinomio )
{
   POLINOMIO ptrNuevo = NULL;
   int coef, exp, nM , opc = 1;
   nM = 0;
   
   printf( "\n Introduzca los miembros del polinomio \n ");
   
   do
   {
      printf( "\n Miembro %d \n\n", nM += 1  );     
      
      printf( " Coeficiente = " );
      scanf( "%d", &coef );
      
      printf( " Exponente de x = " );
      scanf( "%d", &exp );
      
      if( crearNodo( &ptrNuevo , coef, exp ) )
      {
        ptrNuevo -> ptrLiga = *ptrPolinomio;
        *ptrPolinomio = ptrNuevo;
      }else
          {
            printf( " Error se ha desbordado la memoria \n\n ");    
            break;
          }
    
     printf("\n Otro miembro ? ( 1:Si - 0:No ) " );
     scanf( "%d", &opc );
      
   }while( opc );
}
コード例 #8
0
ファイル: main.c プロジェクト: p8queen/pila_en_c
int main(int argc, char **argv)
{
    Nodo *head;
    head = NULL;
    head = crearNodo(12,"gustavo",head);
    head = crearNodo(14,"maria",head);
    head = crearNodo(16,"pedro",head);
    head = crearNodo(15,"gabriel",head);
    
    //recorrer pila
    Nodo* ptr;
    ptr = head;
    while (ptr != NULL){
	    printf("sd:[%d] nombre:[%s] \n", ptr->sd, ptr->nombre);
	    ptr = ptr->siguiente;
    } 	
    
    return 0;
}
コード例 #9
0
ファイル: pgb.c プロジェクト: soviet/VCP-PGB
/**
 *
 * Funcion que construye desde un string de enteros, el arbol, usa notacion
 * preorden(prefija), osea de izq a der.
 *
 **/
void construir(Arbol **raiz, int valor, int i, int padre, int lado)
{

  /* printf("inicioConst\n"); */
  if((*raiz) == NULL && bandera == 0)
    {
      /* Gramatica */
      /* Si el padre es una funcion de coloracion su hijo debe ser un terminal */
      if(padre < 7 && valor < 16)
      	{
      	  int setear = abs((i % 16) - (valor % 16)) + 16;
      	  valor = (setear < 32) ? setear: 16;
      	}
      /* Si el padre es una funcion generica su hijo derecho debe ser una
	 funcion generica o funcion de coloracion */
      else if(padre > 6 && padre < 16 && lado == 1 && valor > 15)
      	{
      	  int setear = abs((i % 16) - (valor % 16));
      	  valor = (setear < 16) ? setear: 0;
      	}

      *raiz = crearNodo(valor, i);
      bandera = 1;
    }
  else if((*raiz) != NULL)
    {
      if((*raiz)->valor > 15)
	{
	  /* printf("\tterminal-\n"); */
	}
      else
	{
	  /* printf("\tfuncion-\n"); */
	  if(funciones[(*raiz)->valor] == 1)
	    {
	      /* printf("\tizq arg1\n"); */
	      construir(&((*raiz)->izq), valor, i, (*raiz)->valor, 0);

	    }
	  else if(funciones[(*raiz)->valor] == 2)
	    {
	      /* printf("\tizq arg2"); */
	      construir(&((*raiz)->izq), valor, i, (*raiz)->valor, 0);
	      /* printf("\tder arg2"); */
	      construir(&((*raiz)->der), valor, i, (*raiz)->valor, 1);
	    }

	}
    }

  /* printf("FinConst\n"); */
}
コード例 #10
0
ファイル: Huffman.cpp プロジェクト: busiris2014/7506TPREPO
Huffman::Huffman() {
	this->sz = 0;
	this->buffer.bitsOcupados = 0;
	this->buffer.buffer = 0;
	this->caracterNuevo = true;
	this->termino = false;
	this->buscarPosicion = false;
	this->codigo = new Cola();
	this->cantidadAimprimir = 1;
	this->i = 1;

	for (int i = 0; i < MAX; i++) {
		inicialCompleto[i] = crearNodo(i, 1);
		a[i] = inicialCompleto[i]; // Asigno al vector "a" todo el vector inicialCompleto
	}
}
コード例 #11
0
ファイル: huffman.c プロジェクト: brokendragon/PERDICE
struct nodo *insertar(struct nodo *raiz, BYTE c)
/*
 * Inserta al principio de la lista enlazada un nuevo
 * nodo con el caracter `c'
 */
{
	struct nodo *tmp=raiz;


	raiz=crearNodo();
	raiz->c=c;
	raiz->freq=1;
	raiz->sig=tmp;

	return raiz;
}
コード例 #12
0
ファイル: main.c プロジェクト: zerokullneo/IArtificial
int main(int argc, char **argv)
{
	printf("Ejercicio TicTacToe.\n");
	int jugador;  //+1 o -1
	int primero,ganador;
	tNodo *juego = crearNodo(tablero_inicial);
	dispNodo(juego);

	printf("El Agente Inteligente juega con X \n El Jugador Humano con O \n Elige el turno 1:Primero o 2:Segundo ");
	scanf("%d",&primero);
	printf("\n");

	if(primero == 1)
		jugador = -1; //Turno de Min
	else
		jugador = 1; //Turno de Max

	ganador = terminal(juego,jugador);

	while(juego->vacias > 0 && ganador == 0)
	{
		if(jugador == 1)
			juego = (tNodo *) PSEUDOminimax(juego);
		else
			juego = (tNodo *) jugadaAdversario(juego);

		dispNodo(juego);
		ganador = terminal(juego,jugador);
		jugador = opuesto(jugador);//turno del adversario
	}

	switch(ganador)
	{
		case 100:
			printf("\n HE GANADOOOO\n");
			break;
		case 0:
			printf("\n EMPATE\n");
			break;
		case -100:
			printf("\n Increible pero has ganado tu :(( \n\n");
			break;
		default: printf("\n algo ha salido mal en el juego ..\n");
	}
	return 0;
}
コード例 #13
0
ファイル: EjercicioOral.cpp プロジェクト: mazcui2/TpAlgor
Nodo* CrearLista(int enteros[], int tamanio)
{
	if(tamanio != 0){
		nodo *lista, *aux, *nuevoNodo;
		tamanio =-tamanio;
		crearNodo(&lista, enterios[tamanio]);
		aux = lista;
		for(int i = tamanio-j;i>=0; i--){
			CrearNodo(&nuevoNodo, enteros[i]);
			aux->anterior = nuevoNodo;
			nuevoNodo->siguiente = aux;
			aux = nuevoNodo;
		}
		return lista;
	}
	return null;
}
コード例 #14
0
ファイル: huffman.c プロジェクト: brokendragon/PERDICE
struct nodo *crearArbolHuffman(struct nodo *raiz)
{
	struct nodo *nuevo;


	if (raiz == NULL)
		return NULL;

	while (raiz->sig != NULL)
	{
		nuevo=crearNodo();
		nuevo->freq=raiz->freq + raiz->sig->freq;
		nuevo->hizq=raiz;
		nuevo->hdch=raiz->sig;
		raiz=insertarOrden(raiz->sig->sig, nuevo);
	}

	return raiz;
}
コード例 #15
0
ファイル: Huffman.cpp プロジェクト: busiris2014/7506TPREPO
void Huffman::crearArbol(Nodo* nodoActual[], int numeroMaximo) {
	bool yaEncontrePosicion;
	int u = 0, posicionInsercion, frecuencia;
	Nodo* ptr;
	ordenarNodos(nodoActual, numeroMaximo);

	for (int n = numeroMaximo; n > 1; n--) {
		//ordenarNodos(nodoActual,n);
		u = nodoActual[0]->getFrecuencia() + nodoActual[1]->getFrecuencia();
		str = nodoActual[0]->getNumero() + nodoActual[1]->getNumero();
		ptr = crearNodo(str, u);

		ptr->setHijoDerecho(nodoActual[1]);
		ptr->setHijoIzquierdo(nodoActual[0]);

		nodoActual[0] = ptr;

		yaEncontrePosicion = false;
		posicionInsercion = n - 2;
		frecuencia = nodoActual[0]->getFrecuencia();
		for (int i = 1; i < n - 1; i++) {
			if (!yaEncontrePosicion && nodoActual[i]->getFrecuencia()
					> frecuencia) {
				posicionInsercion = i - 2;
				yaEncontrePosicion = true;
			}
			nodoActual[i] = nodoActual[i + 1];
		}

		for (int j = 0; j < posicionInsercion; j++) {
			nodoActual[j] = nodoActual[j + 1];
		}

		nodoActual[posicionInsercion] = ptr;
	}
}
コード例 #16
0
ファイル: pgb.c プロジェクト: soviet/VCP-PGB
/**
 *
 * Funcion que que convierte el cromosma binario en un Arbol, esta funcion es
 * llamada por la funcionObjetivo del AG
 *
 **/
void convertion(bool *chrm, bool grafica)
{

  Arbol *A, *izq, *aux, *aux2;
  int i, nChrm, h, hmax, setear, nuevo_valor, *array;/* [8] = {6, 0, 16, 7, 1, 18, 4, 21}; */
  bool lado = 0;
  FILE *filetree;
  char *str;
  char nombres[][35] = {
    /* Funciones de Coloracion */
    "Greedy Coloring", "ColoringMoreFrequentColor", "ColoringLessFrequentColor", "UnColoring",
    "ColoringNeighbors", "InterchangeColor", "UncoloringNeighbors",
    /* Funciones que se repiten - solo de coloracion */
    "EqualX", "IfX",  "AndX",
    /* Funciones Genericas */
    "While", "If", "And", "Equal", "Or", "Not",
    /* Terminales */
    "vertexLargestDegree","vertexMinimumDegree", "firstVertex", "vertexLowestNumberedColor",
    "vertexHighestNumberedColor", "vertexMoreFrequentColor", "vertexLessFrequentColor",
    "vertexSaturationDegree", "vertexMoreUncoloredNeighbors", "vertexIncidenceDegree",
    "not_Increase?", "ExistUncoloredVertex?",
    /* Terminales que se repiten */
    "vertexLowestNumberedColor", "vertexHighestNumberedColor", "vertexMoreFrequentColor",
    "vertexLessFrequentColor"};

  A = NULL;
  nChrm = sizeChrm / nByte;
  contador  = nChrm;
  bandera = 0;
  h = 0;
  hmax = 12;

  array = calloc(nChrm, sizeof(int));
  getChrm(chrm, array);

  for(i=0; i<5; i++)
    funciones[i] = 1;
  for(i=5; i<16; i++)
    funciones[i] = 2;

  funciones[15] = 1;
  funciones[6] = 1;

  for(bandera=0, i=0; i<nChrm; i++)
    {
      /* /\* Si el primer elemento es un Terminal se cambia por una Funcion *\/ */
      /* if(i == 0 && array[i] > 15) */
      /* 	{ */
      /* 	  setear = abs((0 % 16) - (array[i] % 16)); */
      /* 	  array[0] = (setear < 16) ? setear: 0; */
      /* 	} */

      /* /\* Si el ultimo elemento es una Funcion se cambia por un Terminal *\/ */
      /* if(i == (nChrm - 1) && array[(nChrm - 1)] < 16) */
      /* 	array[nChrm - 1] = array[nChrm - 1] + 16; */

      construir(&A, array[i], i, -1, -1);

      if(bandera == 0)
	{
	  /* Guardamos el arbol en otro arbol auxiliar */
	  aux = A;

	  /* Creamos un segundo Arbol auxiliar con los datos del nodo que
	     correspondia */
	  aux2 = crearNodo(array[i], i);

	  /* El arbol original lo setiamos y creamos un nodo con una
	     Funcion, que sea siempre con dos argumentos, una funcion generica*/
	  setear = abs((A->id % 16) - (A->valor % 16));
	  nuevo_valor = ((setear < 15) ? setear: 14);

	  if(funciones[nuevo_valor] == 1)
	    nuevo_valor = nuevo_valor + 10;

	  if(nuevo_valor ==  5 || nuevo_valor ==  6)
	    {
	      nuevo_valor = nuevo_valor + 8;
	    }

	  A = crearNodo(nuevo_valor, contador++);
	  /* El nuevo nodo tiene de hijo a la izq al primer auxiliar y el
	     der. al segundo auxiliar si LADO es 0 si es 1 viceversa.
	     Se van rotando para que los arboles no sean tan desbalanciados*/

	  if(lado == 0)
	    {
	      A->izq = aux;
	      A->der = aux2;
	      lado = 1;
	    }
	  else
	    {
	      A->izq = aux2;
	      A->der = aux;
	      lado = 0;
	    }

	}
      bandera = 0;
      /* printf("Fin Costruir\n\n"); */

    }
  /* Liberar el arreglo con las F y T */
  /* free(array); */
  rebuilt(A);
  /* salidaNameArbol(A); */

  if(grafica) {

    i = snprintf(NULL, NULL, "%s/Arbol.dot", ruta_resultados);
    str = malloc((i+1) *sizeof(char));
    snprintf(str, i+1, "%s/Arbol.dot", ruta_resultados);

    filetree = fopen(str, "w");
    free(str);
    fprintf(filetree, "digraph G{\n");
    fprintf(filetree, "%d [ label = \"%s\" ];\n", A->id, nombres[A->valor]);

    izq = A->izq;

    fprintf(filetree, "%d [ label = \"%s\" ];\n", izq->id, nombres[izq->valor]);
    imprimir(A, filetree, nombres);

    fprintf(filetree, "}");

    fclose(filetree);

    i = snprintf(NULL, NULL, "dot %s/Arbol.dot -o %s/arbol.png -Tpng", ruta_resultados, ruta_resultados);
    str = malloc((i+1) *sizeof(char));
    snprintf(str, i+1, "dot %s/Arbol.dot -o %s/arbol.png -Tpng", ruta_resultados, ruta_resultados);

    printf("%s\n",str);

    if(system(str))
      printf("No se pudo dibujar el Arbol\n");
    free(str);
  }

  conexion(A, grafica);

  freeArbol(A);
  free(array);
}
コード例 #17
0
ファイル: ukkonen.c プロジェクト: pandres/Bioinformatica
NODO *ukkonen(NODO* I, char *S, int m, int* e){
    int root_to;
    int matcheado=0;
    int i, j_i, j_estrella;	// i = fases j = extensiones
    int regla3 = 0;
    int reglaAnterior = 0;
    int faseInicial;
    int auxg=0;
//  estas variables se utilizan para hacer reglas 3 en el caso especial
    int k, p1, p2;  
    NODO* auxiliar; 
//    int auxj_i=0;
    NODO* nodoAnterior;
    if(flagString == 1){
        faseInicial = 1;
        *e = 0;
        root_to = 0;
        j_i = 1;
    
    /*------------Genero I(1)------------*/

        // Crear el root
        I = crearNodo(0, NULL, NULL, 0, &root_to, S);
        //Creamos el hijo
        *e = *e + 1;
        nodoAnterior = crearNodo(0, I, NULL, 1, e, S);
        nodoAnterior->posS1=1;
    }
    else{
         special_find(ST, &auxg, &matcheado);
//         printf("auxg: %d n->S1: %d n->S2: %d e: %d\n", auxg, nodoAnterior->posS1, nodoAnterior->posS2, matcheado);
//         printTotalString(nodoAnterior);
         //printSTree(ST,1);
         if(matcheado>=2){
					  p2=matcheado-1;
					 	for(k=2;k<=matcheado;k++){
							 p1=p2;
		           auxiliar=find_j_i_naive(ST, &p1, k, S2, 1);
		           calculaRegla(auxiliar, p1, k, i, S2);
						   p2--;
						}            
				 }		
         //printSTree(ST,1);				 
         *e = matcheado;
         faseInicial = matcheado;
         nodoAnterior=ST; // inicialmente empieza desde la raiz
         j_i = 0;
   
    }
    /*-----------Calculo I(i+1)-----------*/
    for (i = faseInicial; i <= (m - 1); i++) {	//Comienza Fase i+1
           /*----SPA---- */   //ver pag 106 Dan Gusfuield
     	  // paso 1
		regla1(e);
		reglaAnterior = 1;

 	 // paso 2
		while ((i + 1 > j_i) && (!regla3)){//mientras(no regla3 o hicimos todas las extnsiones
		    nodoAnterior =
                    SEA(I, nodoAnterior, j_i + 1, i, &regla3, &reglaAnterior, e, S);
		    						j_i++;
/*		    						if(reglaAnterior==3 && flagString==2 && auxj_i==0){
		    							 auxj_i=j_i;
		    						}*/
                    //printSTree(I, 1);
  		}
/*			if(auxj_i!=0 && flagString == 2){ //restauro el valor de j_i pues hice muchas veces regla 3
					j_i=auxj_i;
					auxj_i=0;
   		}
*/
	   	 if (regla3) {
		    j_estrella = j_i;
		    regla3 = 0;
		 }
		 else j_estrella = i + 2;
         //paso 3
	 j_i = j_estrella - 1;
	 if(i==faseInicial) flagSpecial = 0;
    }
    return (I);
}