I'm close to the end of the program that I needed to register for my university courses, but I ran into the last problem: formatting the output!
Nothing about the code: it's just cosmetics (but I need to fix it because my result got respect for some standards).
Basically, my program will read the CSV file and process it, dividing the resulting graph into clusters. I want them numbered, no matter how (I don't care if it starts with 2 instead of 1, if the numbers are true for c). The problem is that I cannot figure out how to do this Oo
I already have the correct data structure for working with my clustering: each node in the graph points to a list. If I have n clusters, I will have n lists. Lists are displayed inside the Vertex class, and the algorithm will combine them at runtime, so I cannot number them as easily as I would if they were in a vector or something like that.
So now I have, say, n lists. I can start easily by looking at the first vertex (they are in vector V) and following the pointer. After that, I got to the first list. I can move it and get every node that points to this list, and I want my program to put "1" on the map inside. Then I looked inside V for another vertex, the list of which is different from the previous one, and again go to the list and save the nodes with "2", etc.
: 3 CSV , :
c 1 1
c 2 1
c 3 1
c 4 1
c 5 1
c 6 5
c 7 1
c 8 1
c 9 1
c 10 1
c 11 1
c 12 5
c 13 5
c 14 1
c 15 1
c 16 1
c 17 1
c 18 17
c 19 17
c 20 17
c 21 17
c 22 5
c 23 17
c 24 17
c 25 17
c 26 17
c 27 17
c 28 17
c 29 17
c 30 17
c 31 5
c 32 5
1, 5, 17 1, 2, 3 lol U_U
map<int, int> clusterProcessor(Grafo &G, map_t &Map, int clusters, vector<Vertex*> &V {
map<int, int> clustermap;
list<Vertex*>::iterator listiter;
int j;
int counter = 1;
for (j=1; j < V.size(); ++j) {
if (V[j]->getMyset()->front() != V[j-1]->getMyset()->front())
counter++;
for (listiter = V[j]->getMyset()->begin(); listiter != V[j]->getMyset()->end();
listiter++)
clustermap.insert(pair<int, int> ( (*listiter)->id, counter) );
}
return clustermap;
}
void clusterPrinter(map<int, int> m) {
map<int, int>::iterator i;
for (i = m.begin(); i != m.end(); i++)
cout << "c " << i->first << " " << i->second << endl;
}