void ArbreCompletion::estRecent(string dataDonnee) {
	Noeud* mot = trouver(dataDonnee);

	//Si le mot est déja récent
	if (mot->getEstRecent())
	{
		//Mettre le mot au début de la liste (le retirer d'abord)
		for (int j = 0; j < motsRecents.size(); j++){
			if (motsRecents[j] == dataDonnee)
			{
				motsRecents.erase(motsRecents.begin() + j);
				break;
			}
		}
	}

	//Si la liste est pleine, on doit enlever le moins récent
	else if (motsRecents.size() == TAILLE_MAX)
	{
		(trouver(motsRecents[0]))->setEstRecent(false);
		motsRecents.erase(motsRecents.begin());
	}

	//Ajouter le mot et mettre à jour ses attributs
	motsRecents.push_back(dataDonnee); 
	mot->setEstRecent(true);
	mot->augmenteFrequence();
}
Exemple #2
0
void cree_graphe_connexe_value(char* nom_fich, int nbs, int nba)
/* format du fichier :
   nbsommets nbaretes
   aretes sous forme de triplets origine extremité                           */ {
    FILE *fich;
    GRAPH g;
    t_ens e;
    int ori, ext;
    int i, rori, rext;
    float val;

    fich = fopen(nom_fich, "wt");

    fprintf(fich, "%d %d\n", nbs, nba);

    init_graphe(nbs, nba, &g);
    init_ens(nbs, &e);

    /* génération aléatoire de nbs-1 aretes pour assurer la connexité du graphe */
    while (e.nbClass > 1) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
            rori = trouver(ori, &e);
            rext = trouver(ext, &e);
        } while ((ori == ext) || (g.matrix[ori][ext]) || (rori == rext));
        /* pour interdire les boucles et ne pas générer 2 fois la meme arete */

        do {
            val = (rand() % (int) (10 * MAXVALUATION)) / 10.;
        } while (val == 0.0);
        /* pour n'avoir qu'une décimale */
        g.matrix[ori][ext] = g.matrix[ext][ori] = val;
        reunir(rori, rext, &e);
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    /* on complète à nba avec des aretes aléatoires */
    for (i = nbs; i <= nba; i++) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
        } while ((ori == ext) || (g.matrix[ori][ext]));
        /* pour interdire les boucles et ne pas générer 2 fois la meme arete */

        do {
            val = (rand() % (int) (10 * MAXVALUATION)) / 10.;
        } while (val == 0.0);
        /* pour n'avoir qu'une décimale */
        g.matrix[ori][ext] = g.matrix[ext][ori] = val;
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    fclose(fich);
}
//Affiche les mots descendants
vector<string> ArbreCompletion::imprimer(string data)
{
	if (!liste.empty())
		liste.clear();

	//Data n'est pas necessairement un mot
	Noeud* noeud = trouver(racine, data, true);
	imprimer(noeud);
	return liste;
}
//Un paramètre motInvalide permet d'indiquer si le mot cherche est un mot ou un bout de mot
Noeud* ArbreCompletion::trouver(Noeud* noeud, string dataDonnee, bool motInvalide) {
	bool valide = noeud->getEstMot() || motInvalide;
	if (valide && noeud->getData() == dataDonnee)
		return noeud;
	Noeud* arret = NULL;

	//Regarder les enfants
	for (int i = 0; arret == NULL && i < noeud->getEnfants().size(); i++) {
		arret = trouver(noeud->getEnfants()[i], dataDonnee, motInvalide);
	}
	return arret;
}
Exemple #5
0
void MainWindow::MAJ_treeview_Composition()
{
    ui->TreeWidget->clear();
    ProjetManager& projetmanager = ProjetManager::getInstance();
    vector<QTreeWidgetItem*> afficher;

    for(vector<Projet *>::const_iterator it_projets = projetmanager.getProjets().begin(); it_projets != projetmanager.getProjets().end(); ++it_projets){
        QTreeWidgetItem *treeItem = addTreeRoot((*it_projets)->getId(), (*it_projets)->getTitre());
        afficher.push_back(treeItem);
        vector<Tache*> A_afficher = (*it_projets)->getTaches();
        vector<Tache*>::iterator it_taches = A_afficher.begin();
        // Affichage des tâches directement reliées au projet
        while(it_taches != A_afficher.end()){
            if((*it_taches)->getPere() == 0){
                afficher.push_back(addTreeChild(treeItem, (*it_taches)->getIdentificateur(), (*it_taches)->getTitre()));
                it_taches = A_afficher.erase(it_taches);
            } else {
                ++it_taches;
            }
        }

        // Affichage des compositions
        it_taches = A_afficher.begin();
        while(!A_afficher.empty()){
            QTreeWidgetItem* item = trouver(afficher, (*it_taches)->getPere()->getIdentificateur());
            if(item){
                afficher.push_back(addTreeChild(item, (*it_taches)->getIdentificateur(), (*it_taches)->getTitre()));
                it_taches = A_afficher.erase(it_taches);
            } else {
                ++it_taches;
            }
            if(it_taches == A_afficher.end())
                it_taches = A_afficher.begin();
        }
    }
}
int ArbreCompletion::getFrequence(string dataDonnee){
	if (trouver(dataDonnee) != NULL)
		return trouver(dataDonnee)->getFrequence();
	else
		return 0;
}
//Trouver un mot
Noeud* ArbreCompletion::trouver(string dataDonnee) {
	return trouver(racine, dataDonnee, false);
}
Exemple #8
0
int trouver(int x, t_ens *ens)
/* recherche de la classe de x avec compression de chemins */ {
    if (ens->parent[x] < 0) return x;
    else return (ens->parent[x] = trouver(ens->parent[x], ens));
}