Complex counter is only int, but it will not work on request

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;
}
+3
3

, . , counter++ .

, .

, , ?

, ,

if (V[j]->getMyset()->front() != V[j-1]->getMyset()->front() ) counter++;

if (V[j]->getMyset()->begin()->id != V[j-1]->getMyset()->begin()->id) counter++;
+1

. , , . , , , . , , .

+1

, - . , , bool, .

, -, . .

:

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;
vector<bool> checkvertex(V.size(), false); // Got 1 bool per each vertex. When I visit it, it'll be set "true".
for (j=1; j < V.size() ; ++j) {
    //if (V[j]->getMyset()->front() != V[j-1]->getMyset()->front() ) count++;
        if (checkvertex[j] == false) {
            for (listiter = V[j]->getMyset()->begin(); listiter != V[j]->getMyset()->end(); listiter++)
            {
                clustermap.insert(pair<int, int> ( (*listiter)->id, counter) );
                checkvertex[(*listiter)->id-1] = true;
            }
        counter++;
        }
}
return clustermap;
}

: c 1 1 c 2 1 c 3 1 c 4 1 c 5 1 c 6 2 c 7 1 c 8 1 c 9 1 c 10 1 c 11 1 c 12 2 c 13 2 c 14 1 c 15 1 c 16 1 c 17 1 c 18 3 c 19 3 c 20 3 c 21 3 c 22 2 c 23 3 c 24 3 c 25 3 c 26 3 c 27 3 c 28 3 c 29 3 c 30 3 c 31 2 c 32 2

, , . , , 32 : ! O.o

c 2 1 c 3 2 c 4 3 c 5 4 c 6 5 c 7 6 c 8 7 c 9 8 c 10 9 c 11 10 c 12 11 c 13 12 c 14 13 c 15 14 c 16 15 c 17 16 c 18 17 c 19 18 c 20 19 c 21 20 c 22 21 c 23 22 c 24 23 c 25 24 c 26 25 c 27 26 c 28 27 c 29 28 c 30 29 c 31 30 c 32 31

The fact is that this will not happen only at its limit: for this file it will happen for any number greater than 13 (13 anyway).

0
source

Source: https://habr.com/ru/post/1751819/


All Articles