Beispiel #1
0
double initLongueurTrajet() {
    int classe = distDistanceTrajet(gen);
    int min_i = 0;
    if (classe > 0)
        min_i =  stats_distanceTrajet[classe-1];
    
    boost::random::uniform_real_distribution<> longueur(min_i, stats_distanceTrajet[classe]);
    
    return longueur(gen);
}
Beispiel #2
0
/**
 * @brief Affiche un puzzle
 * @param[in,out] p le Puzzle à afficher
 * @param[in,out] os le flux de sortie où afficher
 */
void afficher(Puzzle& p, std::ostream& os) {
	os << "*** LEE - long : " << longueur(p.lEE) << endl;
	for (unsigned int i = 0; i < longueur(p.lEE); ++i) {
		afficher(lire(p.lEE, i), os);
		os << endl;
	}
	os << endl << "*** LEAE - long : " << longueur(p.lEAE) << endl;
	for (unsigned int i = 0; i < longueur(p.lEAE); ++i) {
		afficher(lire(p.lEAE, i), os);
		os << endl;
	}
}
Beispiel #3
0
/**
 * @brief Recherche un Etat dans une liste
 * @param[in] e l'Etat a rechercher
 * @param[in,out] l la Liste dans laquelle chercher
 * @return true si l'Etat a été trouvé, false sinon
 */
bool rechercher(const Etat& e, Liste& l) {
	for (unsigned int i = 0; i< longueur(l); ++i) {
		if (comparer(e.damier, lire(l, i).damier))
			return true;
	}
	return false;
}
Beispiel #4
0
//*****************************************************
// Calcul le nombre de lettres differents entre 2 chaines
// motRef: la chaine de reference
// motV  : la chaine a corriger
//*****************************************************
int Correlation ( char* motRef, char* motV )
{
  int indRef = 0;  int indV = 0;
  int indC = 0;  int memeLettre = 0;
  int longRef = longueur ( motRef );
  int longV = longueur ( motV );
  
  for( indV = 0; (indV < longV ); indV = indV + 1 )
    {
      for( indC = indRef; (indC < longRef) && (indC < indRef + 4 ); indC = indC+1 )
	{
	  if ( motRef[ indC ] == motV[ indV ] ) { memeLettre = memeLettre + 1; indRef = indC+1; break; }
	}
    }

  if (longRef > longV) { return( longRef - memeLettre ); }
  else               { return( longV - memeLettre ); }
}
Beispiel #5
0
/**
 * @brief Cherche l'Etat optimal à traiter dans une liste
 * @param[in,out] l liste des états à explorer
 * @return position de l'Etat optimal à traiter dans l
 */
unsigned int minimal(Liste& l) {
	unsigned int index = 0;
	Etat eMin = lire(l, index);
	for (unsigned int i = 1; i < longueur(l); ++i) {
		Etat e = lire(l, i);
		if (e.g + e.h < eMin.g + eMin.h ||
			(e.g + e.h == eMin.g + eMin.h && e.h <= eMin.h)) {
			eMin = e;
			index = i;
		}
	}
	return index;
}
void ajoutQueue(FileAttente& f, const ElementFile e)
{
	Maillon* np;

	np = new Maillon;

	(*np).numero = e;
	(*np).suivant = NULL;
	
	if (longueur(f) == 0)
	{
		//premier ajout
		f.tete = np;
		f.queue = np;
	} 
	else
	{
		(*f.queue).suivant = np;
		f.queue = np;
	}
}
Beispiel #7
0
/**
 * @brief Résout un puzzle
 * @param[in,out] p le puzzle à résoudre
 * @param[in] t le damier initial
 * @param[in,out] os flux de sortie
 */
void jouer(Puzzle& p, const Tab2D& t, std::ostream& os) {
	Etat etatInitial;
	Etat etatCourant;
	Tab2D damierFinal;
	Etat etatDerive;

	double tempsDebutRecherche = getTime();

	but(damierFinal, t.nbL, t.nbC);
	initialiser(etatInitial.damier, t.nbL, t.nbC);
	etatInitial.mouvement = FIXE;
	etatInitial.precedent = 0;
	etatInitial.g = 0;

	//Copie du damier inititial dans etatInitial
	for (unsigned int l = 0; l < t.nbL; ++l) {
		for (unsigned int c = 0; c < t.nbC; ++c) {
			etatInitial.damier.tab[l][c] = t.tab[l][c];
		}
	}
	etatInitial.h = manhattan(etatInitial.damier, damierFinal);

	initialiser(etatDerive.damier, t.nbL, t.nbC);

	inserer(p.lEAE, 0, etatInitial); //étatInitial dans LEAE

	bool solutionTrouvee = false;
	bool mvtPossible;
	unsigned int pos;

	while (p.lEAE.nb != 0) {
		pos = minimal(p.lEAE);
		etatCourant = lire(p.lEAE, pos); //on prend le 1er état à explorer
		//insérer étatCourant dans LEE
		inserer(p.lEE, longueur(p.lEE), etatCourant);
		supprimer(p.lEAE, pos); //supprimer étatCourant de LEAE

		if (etatCourant.h == 0) { // le damier de étatCourant est le damier but
			solutionTrouvee = true;
			break; //sortir de la boucle while
		}

		/*pour_tout (mouvement possible associé à étatCourant)
		mouvement possible relatif à damier de étatCourant (etatCourant.damier)
		ordre d'exploration (obligatoire) NORD, EST, SUD, OUEST */
		//initialiser un étatDérivé // d'après le mouvement

		for(int m = OUEST; m >= NORD; --m) {
			mvtPossible = deriver(etatCourant, (Mouvement) m, etatDerive);
			if (mvtPossible && !rechercher(etatDerive, p.lEAE)\
				&& !rechercher(etatDerive, p.lEE)) {
				etatDerive.precedent = longueur(p.lEE) - 1;
				etatDerive.h = manhattan(etatDerive.damier, damierFinal);
				etatDerive.g = etatCourant.g + 1;
				//insérer étatDérivé dans LEAE
				inserer(p.lEAE, longueur(p.lEAE), etatDerive);
			}
		}
	}

	double tempsFinRecherche = getTime();
	cout << "Durée de recherche : " << tempsFinRecherche - tempsDebutRecherche
		<<" seconde(s)."<< endl;

	if (solutionTrouvee) {
		Pile sol;
		Etat etatSol;
		initialiser(sol, 3, 2);
		initialiser(etatSol.damier, t.nbL, t.nbC);

		//Stockage de la solution
		etatSol = lire(p.lEE, longueur(p.lEE)-1);
		empiler(sol, etatSol);
		while (etatSol.precedent != 0) {
			etatSol = lire(p.lEE, etatSol.precedent);
			empiler(sol, etatSol);
		}
		empiler(sol, etatInitial);

		//Affichage de la solution
		os << "Damier : " << t.nbL << " lignes " << t.nbC << " colonnes"
			<< endl;
		os << "Solution en " << sol.sommet << " mouvements" << endl;
		while (!estVide(sol)) {
			afficher(sommet(sol), os);
			os << endl;
			depiler(sol);
		}
		detruire(sol);
		detruire(etatSol.damier);
	}
	else {
		os << "Solution non trouvée" << endl;
	}
	detruire(etatInitial.damier);
	detruire(etatCourant.damier);
	detruire(etatDerive.damier);
	detruire(damierFinal);
}
Beispiel #8
0
void remplir_tab_longueur(Arbre * a)
{
    longueur(a,0);
    a = creerArbreCanonique();
    recupererCode(a);
}