Vecteur de vecteur c++
Résolu
mony84
Messages postés
75
Statut
Membre
-
mony84 Messages postés 75 Statut Membre -
mony84 Messages postés 75 Statut Membre -
Bonjour,
je veux écrire un programme qui détecte le nombre de partitions dans un graphe de noeuds.
j'ai utilisé une structure de vecteurs de vecteurs car je ne connais pas à priori la taille des partitions
la matrice
2 lignes égales signifie que les 2 noeuds appartiennent à la même parition
et dans une ligne les "1" signifient les noeuds qui appartiennent à la même parition que le noeud (dont le numéro est le numéro de la ligne)
l'erreur :
A priori il y a un problème d'indices, mais je n'arrive pas à voir où est ce qu'il est.
Merci pour votre aide
je veux écrire un programme qui détecte le nombre de partitions dans un graphe de noeuds.
j'ai utilisé une structure de vecteurs de vecteurs car je ne connais pas à priori la taille des partitions
int i=k=s=m=_partitionSet= 0;
vector <vector<int> > partitions;//vecteur de vecteur
bool find = false;
while (i< NETWORK_SIZE){
m=0;
for (j=0; j< NETWORK_SIZE; j++){
if (neighbors_matrix_connected[i][j] == 1){
partitions[_partitionSet][m]=j;
m++;
}
}
i++;
k=0;
//parcourir ttes les partitions pour vérifier si le noeud appartient dèjà une partition
while ((find == false) && (k <partitions.size())){
while ((find == false) && (s < partitions[k].size())){
if (i == partitions[k][s]) {
find = true;
}
s++;
}
k++;
}
if (find ==true)
i++;
else {
_partitionSet++;
}
}
la matrice
neighbors_matrix_connectedest de ce type :
1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1
2 lignes égales signifie que les 2 noeuds appartiennent à la même parition
et dans une ligne les "1" signifient les noeuds qui appartiennent à la même parition que le noeud (dont le numéro est le numéro de la ligne)
l'erreur :
error: attempt to subscript container with out-of-bounds index 0, but container only holds 0 elements.
A priori il y a un problème d'indices, mais je n'arrive pas à voir où est ce qu'il est.
Merci pour votre aide
A voir également:
- Vecteur de vecteur c++
- Créer un vecteur en matlab - Forum Matlab
- Definir un vecteur d' inconnu matlab ✓ - Forum Matlab
- Convertir un vecteur illustrator en tracé? - Forum Illustrator
- Excel mettre des indices,exposant,vecteur,etc - Forum Excel
- Illustrator impossibilité d'agrandir ou diminuer mon vecteur - Forum Illustrator
1 réponse
la solution :
j'espère qu eça pourrait intéresser quelqu'un
vector <vector<int> > partitions;
vector<int> partitions_intermediary;
int i,j,k,s;
bool find = true;// the node is already in a partition = true
i=0;
while (i< NETWORK_SIZE){
for (j=0; j< NETWORK_SIZE; j++){
if (neighbors_matrix_connected[i][j] == 1){
partitions_intermediary.push_back(j);
}
}
partitions.push_back(partitions_intermediary);
partitions_intermediary.clear();
find =true;
//////////////delete redundancy
i++;
//parcourir ttes les partitions
//find funtion return true if i is included
while (find==true){
find = false;
//find funtion return true if i is included
for (k=0 ;k <partitions.size(); k++){
for (s=0 ;s <partitions[k].size(); s++){
if (i==partitions[k][s])
find =true;
}
}
//////////////
if (find==true){
i++;}
}
}
j'espère qu eça pourrait intéresser quelqu'un