/*!
 * reads a line from the input file and return the three doubles in the
 * beginning of the line, used to know the coordinates of each point
 */
char* GInputFile::readDoubleDoubleDouble(double &dX, double &dY, double &dZ) {
    char *l = readUncommentedLine() ;

    sscanf(l, "%lf %lf %lf", &dX, &dY, &dZ);

    return l;
}
/*!
 * seeks a pattern and return the line if found, or NULL if not found
 *
 * \return the line that contains the pattern
 */
char* GInputFile::seek(char *patt){
    int len = strlen(patt);
    int found = 0;

    while( !found ){
        char* l = readUncommentedLine();
        if( l==NULL )
            return NULL;
        l[len] = '\0';
        if( strcmp(l,patt)==0 )
            return l;
    }

    return NULL;
}
Beispiel #3
0
void loadGraphe(char* filename){	
	openfile(filename);

	
	char* buf;
	char* tok;
	
	int nbArretesAjoutee=0;
	
	while (buf=readUncommentedLine()) {
		tok=getNextToken();
		
		if(*tok=='p'){ // lecture de la taille du graphe
			tok=getNextToken(); //pas interessant
			tok=getNextToken();
			nbSommets=atoi(tok);
			tok=getNextToken();
			nbArretes=atoi(tok);
			
			// creation du graphe
			tConnect=malloc(sizeof(char*) * nbSommets);
			for(int i=0; i<nbSommets; i++){
				tConnect[i]=malloc(sizeof(char) * nbSommets);
				for (int j=0; j<nbSommets; j++)
					tConnect[i][j]=0;
			}
			
			// creation de la couleur associée à chaque sommet pour tous les individus de la population
			tPopulationColor=malloc(sizeof(int*) * populationSize);
			for (int i=0; i<populationSize; i++) {
				tPopulationColor[i] = malloc(sizeof(int) * nbSommets);
			}
			tColor = tPopulationColor[0];
			
			// creation de la meilleure solution trouvee
			tBestSol = malloc(sizeof(int) * nbSommets);
	
			
			// creation du nombre de conflits de chaque sommet
			tConflicts = malloc(sizeof(int) * nbSommets);
			
			// creation de l'impact pour chaque sommet d'une transition vers chaque couleur
			tNewConflitsWithColor = malloc(sizeof(int*) * nbSommets );
			for(int i=0; i<nbSommets; i++){
				tNewConflitsWithColor[i]=malloc(sizeof(int) * (nbColor+2));
			}			
			
			// creation des periodes tabou des sommets
			tTabou = malloc(sizeof(int*) * nbSommets);
			for(int i=0; i<nbSommets; i++){
				tTabou[i]=malloc(sizeof(int) * (nbColor));
			}
			
			// creation de la liste des meilleures ameliorations
			tBestImprove = malloc(sizeof(int) * nbSommets);  // valeur
			tNbBestImprove = malloc(sizeof(int) * nbSommets); // couleur
			ttBestImproveColor = malloc(sizeof(int*) * nbSommets); // couleur
			for (int i=0; i<nbSommets; i++) {
				ttBestImproveColor[i]=malloc(sizeof(int) * nbColor);
			}
			
			// creation de la liste des noeuds avec conflit
			tNodeWithConflict = malloc(sizeof(int) * nbSommets);
			tNodeAdded = malloc(sizeof(int) * nbSommets);
			
			
			
			// MACOL - creation de la distance entre chaque couple d'individus
			tDistSolSol = malloc(sizeof(int*) * populationSize);
			for (int i=0; i<populationSize; i++) {
				tDistSolSol[i]=malloc(sizeof(int) * populationSize);
			}

			// MACOL - creation de la fitness de chaque individu (nombre d'arretes en conflit)
			tFitness = malloc(sizeof(int) * populationSize);
			
			// MACOL - creation de la couleur associe a chaque noeud du fils
			tChild = malloc(sizeof(int) * nbSommets);
			
			// MACOL - tableau des indices des parents pour creation du fils
			tParentsIndices = malloc(sizeof(int) * MAX_NB_PARENTS);
			
			
			printf("Sommets ajoutes: %d\n", nbSommets);
		}
		
		if(*tok=='e'){ // lecture d'une arrete
			tok=getNextToken();
			int v1=atoi(tok);
			tok=getNextToken();
			int v2=atoi(tok);
			tConnect[v1-1][v2-1]=1;
			tConnect[v2-1][v1-1]=1;
			nbArretesAjoutee++;
		}
	}
	
	printf("Arretes ajoutees: %d / %d\n",nbArretesAjoutee ,nbArretes);
	closefile();


	buildVoisins();
}
/*!
 * reads a line from the input file and return the two integers in the
 * beginning of the line
 *
 */
char* GInputFile::readIntInt(int &i, int &j)
{
    char *l=readUncommentedLine() ;
    sscanf (l, "%d %d", &i, &j) ;
    return l ;
}
/*!
 * reads a line from the input file and return the integer in the beginning
 * of the line
 *
 */
char* GInputFile::readInt(int &i)
{
    readUncommentedLine() ;
    i = strtol (line, NULL, 10) ;
    return line ;
}