Exemplo n.º 1
0
void parcour_Profondeur(tGraphe g,char* sommet){
  
  
  int i,nbVoisin;
  
  tNumeroSommet sommetDepart,suivant,x;
  tNomSommet nom;
 tTabCouleurs coul;
  tPileSommets file;
  
  
  file= pileSommetsAlloue();
  sommetDepart=grapheChercheSommetParNom(g,sommet);
  
  // n opérations pour la boucle
  for (i=0;i<grapheNbSommets(g);i++)
    coul[i]=1;
  coul[sommetDepart] = 2;


  printf("\n\n\n\ndebut de l'empilade\n");
  pileSommetsEmpile(file,sommetDepart);
  while(!pileSommetsEstVide(file))
    {
      x=pileSommetsDepile(file);
      nbVoisin=grapheNbVoisinsSommet(g,x);
   
      for(i=0;i<nbVoisin;i++)
	{
	  suivant=grapheVoisinSommetNumero(g,x,i);
	  if(coul[suivant]==1)
	    {
	      coul[suivant]=2;
	      pileSommetsEmpile(file,suivant);
	      
	    }
	  coul[x]=0;
	     grapheRecupNomSommet(g,x,nom);
      printf("%s est trouvé\n",nom);
	}
    }  
}
/*
* Boucle principal
*/
void traitement_pile(tPileSommets pile, tNumeroSommet xSommet, int i[MAX_SOMMETS], tGraphe graphe, tTabCouleurs couleurs){
  tNumeroSommet iSucc;
    tNomSommet nomSommet;
      tNomSommet nomSommet2;
  int trouver = 0;
  int nSucc =0;
  int j =0;
  i[xSommet] = i[xSommet] + 1;
  nSucc = grapheNbSuccesseursSommet(graphe, xSommet);
  while(i[xSommet] <= nSucc && trouver == 0){
    iSucc = grapheSuccesseurSommetNumero(graphe, xSommet, j);
      grapheRecupNomSommet(graphe, iSucc, nomSommet);
      grapheRecupNomSommet(graphe, xSommet, nomSommet2);
    printf("sommet x %s\n", nomSommet2);
      printf("succ du sommet x %s\n", nomSommet);
    printf("sommet %d\n", i[xSommet]);
    printf("couleur i %d\n",couleurs[iSucc] );
    printf("BLEU = %d\n", BLEU);
    printf("-----------------------------\n");
    if(couleurs[iSucc] == BLEU){
      trouver = 1;
    }
    else{
      i[xSommet] = i[xSommet] +1;
      j++;
    }
  }
  if(trouver == 1){
    couleurs[iSucc] = VERT;
    printf("empile \n");
    pileSommetsEmpile(pile, iSucc);
  }
  else{
    couleurs[xSommet] = ROUGE;
    printf("depile \n");
    pileSommetsDepile(pile);
  }
}
Exemplo n.º 3
0
int solutionLab(tGraphe graphe, tNomSommet entree, tNomSommet sortie, tTabCouleurs tabCouleurs)
{

  int i, pasVoisinBleu;
  tNumeroSommet numE, numS, x, y, varChemin;
  tNomSommet nomVarChemin, nom1,nom2;
  tPileSommets pile, pileChemin;

  pile = pileSommetsAlloue();
  pileChemin = pileSommetsAlloue();
  pasVoisinBleu = 1 == 1;
  for(i = 0; i < grapheNbSommets(graphe); i++)
  {

    tabCouleurs[i] = BLEU;
  }
  numE = grapheChercheSommetParNom(graphe, entree);
  numS = grapheChercheSommetParNom(graphe, sortie);
  tabCouleurs[numE] = VERT;
  pileSommetsEmpile(pile, numE);
  while(!pileSommetsEstVide(pile)&& pileSommetsTete(pile) != numS)
  {

    x = pileSommetsTete(pile);
    pasVoisinBleu = 1 == 1;
    for(i = 0; i < grapheNbVoisinsSommet(graphe, x);i++)
    {
      y = grapheVoisinSommetNumero(graphe, x, i);
      if(tabCouleurs[y] == BLEU)
      {

        tabCouleurs[y] = VERT;
        pileSommetsEmpile(pile, y);
        pasVoisinBleu = pasVoisinBleu && 0 == 1;
      }
    }
    if(pasVoisinBleu)
    {

      x = pileSommetsDepile(pile);
      tabCouleurs[x] = ROUGE;
    }
  }
  if(!pileSommetsEstVide(pile)&& pileSommetsTete(pile) == numS)
  {

    while(!pileSommetsEstVide(pile))
    {

      varChemin = pileSommetsDepile(pile);
      pileSommetsEmpile(pileChemin, varChemin);

      if(!pileSommetsEstVide(pile))
      {
        while(!estVoisin(graphe, pileSommetsTete(pile), varChemin))
        {

          pileSommetsDepile(pile);
        }
      }
    }

    while(!pileSommetsEstVide(pileChemin))
    {
      grapheRecupNomSommet(graphe, pileSommetsDepile(pileChemin), nomVarChemin);
      printf("%s\n", nomVarChemin );
    }
    return 0 == 0;
  }
  return 0 == 1;
}
/*
* Vide la pile
*/
void nettoyer_pile(tPileSommets pile){
  while (!pileSommetsEstPleine(pile)) {
    pileSommetsDepile(pile);
  }
}