示例#1
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);
    }
}
///////////////////////////////////////////////////////////////////////////////
// Get information about a dot from a specific place.
///////////////////////////////////////////////////////////////////////////////
string DotPlotBackend::getDotData( int i, int j ) {

	// Get the data directly from the handler.
	// If it's empty, return.
	string dataString = handler->getDotData( i, j );
	if( dataString == "" ) { return ""; }

	// Split the data into its pieces.
	double x, y, red, green, blue;
	stringstream data( dataString );
	data >> x;
	data >> y;
	data >> red;
	data >> green;
	data >> blue;

	// Shave off the border, then add a 10 pixel border.
	x = ( x - BORDER ) + 10;
	y = ( y - BORDER ) + 10;

	// Convert the colors to rgb.
	red *= 255;
	red = floor( red );
	green *= 255;
	green = floor( green );
	blue *= 255;
	blue = floor( blue );

	// Rebuild the data string and return it.
	stringstream rebuilt( stringstream::in | stringstream::out );
	rebuilt << x << " " << y << " "
	        << red << " " << green << " " << blue;
	return rebuilt.str();
}
///////////////////////////////////////////////////////////////////////////////
// Get a grid line.
///////////////////////////////////////////////////////////////////////////////
string DotPlotBackend::getGridLine( int number ) {

	// Get the handler's data as a string.
	string fullData = handler->toString();
	size_t gridStart = fullData.find( "Grid lines:" );
	size_t gridEnd = fullData.find( "Legend:" );
	size_t substringLength = gridEnd - gridStart;
	string data = fullData.substr( gridStart, substringLength );

	// Pull out the grid line.
	int counter = 0;
	istringstream stream( data );
	string line;
	while( getline( stream, line ) ) {
		if( counter == number ) {

			// Get raw data from the grid line.
			stringstream lineStream( line );
			double x1, y1, x2, y2, labelX, labelY;
			int label = 0;
			lineStream >> x1;
			lineStream >> y1;
			lineStream >> x2;
			lineStream >> y2;
			if( lineStream >> label ) {
				lineStream >> labelX;
				lineStream >> labelY;
			}

			// Shave off the border, then add a 10 pixel border.
			x1 = ( x1 - BORDER ) + 10;
			y1 = ( y1 - BORDER ) + 10;
			x2 = ( x2 - BORDER ) + 10;
			y2 = ( y2 - BORDER ) + 10;
			if( label > 0 ) {
				labelX = ( labelX - BORDER ) + 10;
				labelY = ( labelY - BORDER ) + 10;
			}

			// Return the rebuilt grid line.
			stringstream rebuilt( stringstream::in | stringstream::out );
			rebuilt << x1 << " " << y1 << " " << x2 << " " << y2 << " ";
			if( label > 0 ) {
				rebuilt << label << " " << labelX << " " << labelY;
			}
			return rebuilt.str();
		}
		counter++;
	}
示例#4
0
void Recompile::run()
{
    /*
     * @Initialize
     */
    // Directory
    QDir directory(this->_dir);
    if (!directory.exists()) {
        emit output(text("failure_directory").arg(directory.absolutePath()));
        emit recompile(this->_dir, QString());
        return;
    }
    // File
    QFileInfo apksigned(directory.absolutePath().append("/build/signedapk.apk"));
    QFileInfo rebuilt(directory.absolutePath().append("/build/rebuilt.apk"));
    QFileInfo recompiled(directory.absolutePath().append("/build/recompiled.apk"));
    QFileInfo zipaligned(directory.absolutePath().append("/build/zipaligned.apk"));
    /*
     * @APKTool
     */
    // Arguments
    QStringList recompile;
    recompile << QString("-Xms").append(QString::number(Utility::Configuration::heap())).append("m");
    recompile << QString("-jar");
    recompile << Utility::Configuration::apktool();
    recompile << QString("--force");
    if (Utility::Configuration::verbose())
        recompile << QString("--verbose");
    recompile << QString("--output");
    recompile << QString(recompiled.absoluteFilePath());
    recompile << QString("b");
    recompile << QString(directory.absolutePath());
    // Process
    QProcess apktool;
    apktool.setEnvironment(QProcess::systemEnvironment());
    apktool.setProcessChannelMode(QProcess::MergedChannels);
    // Start
    apktool.start(QString("java"), recompile, QIODevice::ReadOnly);
    // Wait (Start)
    if (!apktool.waitForStarted()) {
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    // Wait (Read)
    apktool.waitForReadyRead(5 * 1000);
    // Wait (Stop)
    apktool.waitForFinished(-1);
    // Verify
    if (!recompiled.exists() || !recompiled.isFile()) {
        // Read
        QString output = apktool.readAll();
        emit Recompile::output(output);
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    /*
     * @Sign
     */
    // Arguments
    QStringList sign;
    sign << QString("-Xms").append(QString::number(Utility::Configuration::heap())).append("m");
    sign << QString("-jar");
    sign << Utility::Configuration::signapk();
    sign << QString("-w");
    sign << Utility::Configuration::certificate();
    sign << Utility::Configuration::key();
    sign << recompiled.absoluteFilePath();
    sign << apksigned.absoluteFilePath();
    // Process
    QProcess signapk;
    signapk.setEnvironment(QProcess::systemEnvironment());
    signapk.setProcessChannelMode(QProcess::MergedChannels);
    // Start
    signapk.start(QString("java"), sign, QIODevice::ReadOnly);
    // Wait (Start)
    if (!signapk.waitForStarted()) {
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    // Wait (Read)
    signapk.waitForReadyRead(5 * 1000);
    // Wait (Stop)
    signapk.waitForFinished(-1);
    // Verify
    if (!apksigned.exists() || !apksigned.isFile()) {
        // Read
        QString output = signapk.readAll();
        emit Recompile::output(output);
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    /*
     * @Align
     */
    // Arguments
    QStringList align;
    align << QString("-f");
    if (Utility::Configuration::verbose())
        align << QString("-v");
    align << QString("4");
    align << apksigned.absoluteFilePath();
    align << zipaligned.absoluteFilePath();
    // Process
    QProcess zipalign;
    zipalign.setEnvironment(QProcess::systemEnvironment());
    zipalign.setProcessChannelMode(QProcess::MergedChannels);
    // Start
    zipalign.start(Utility::Configuration::zipalign(), align, QIODevice::ReadOnly);
    // Wait (Start)
    if (!zipalign.waitForStarted()) {
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    // Wait (Read)
    zipalign.waitForReadyRead(5 * 1000);
    // Wait (Stop)
    zipalign.waitForFinished(-1);
    // Verify
    if (!zipaligned.exists() || !zipaligned.isFile()) {
        // Read
        QString output = zipalign.readAll();
        emit Recompile::output(output);
        emit Recompile::recompile(this->_dir, QString());
        return;
    }
    if (rebuilt.exists())
        QFile(rebuilt.absoluteFilePath()).remove();
    // Verify
    if (QFile(zipaligned.absoluteFilePath()).rename(rebuilt.absoluteFilePath())) {
        QFile(recompiled.absoluteFilePath()).remove();
        QFile(apksigned.absoluteFilePath()).remove();
        QFile(zipaligned.absoluteFilePath()).remove();
        emit Recompile::recompile(this->_dir, directory.absolutePath());
    } else
        emit Recompile::recompile(this->_dir, QString());
}
示例#5
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);
}