Getting cygwin_exception::open_stackdumpfile working with vectors

224 Views Asked by At

I get cygwin_exception::open_stackdumpfile trying to run my code. I guess it is an error concerning memory. I am almost 100% sure I get this error because of not properly creating, sending to function or dealing with maximalSets and/or compsub vectors. Please help me to solve this error and thank you for all your answers! update: fixed the problem pointed out by Paul Evans. Now I get the exception from time to time, but still get it.

class Graph {
private:
    int size; // the number of node
    vector<vector<bool> > connected;
    vector<vector<int> > bkv2(vector<int> oldSet, int ne, int ce,
        vector<int> &compsub, vector<vector<int> > maximalSets);
public:
    Graph(int size);
    vector<vector<int> > findMaximalSets();
}

Graph::Graph(int n) { 
    int i, j;
    srand((unsigned int) time( NULL));
    size = n;
    connected.resize(size);
    for (int i=0; i<size; i++) {
        connected[i].resize(size);
    }

    for (i = 0; i < size; i++) { // the graph is randomly generated
        connected[i][i] = 1;
        for (j = i + 1; j < size; j++) {
            if (rand() % 2 == 1) {
                connected[i][j] = 1;
                connected[j][i] = 1;
            } else {
                connected[i][j] = 0;
                connected[j][i] = 0;
            }
        }
    }
}

vector<vector<int> > Graph::findMaximalSets() {
    int i;
    vector<int> all(size);
    vector<int> compsub;
    vector<vector<int> > maximalSets;
    for (i = 0; i < size; i++) {
        all[i] = i;
    }
    return bkv2(all, 0, size, compsub, maximalSets);
}
vector<vector<int> > Graph::bkv2(vector<int> oldSet, int ne, int ce,
        vector<int> &compsub, vector<vector<int> > maximalSets) {
    vector<int> newSet(ce);

    int nod, fixp;
    int newne, newce, i, j, count, pos, p, s, sel, minnod;

    minnod = ce;
    nod = 0;
    for (i = 0; i < ce && minnod != 0; i++) {
        p = oldSet[i];
        count = 0;
        for (j = ne; j < ce && count < minnod; j++)
            if (connected[p][oldSet[j]]) {
                count++;
                pos = j;
            }
        if (count < minnod) {
            fixp = p;
            minnod = count;
            if (i < ne) {
                s = pos;
            } else {
                s = i;
                nod = 1;
            }
        }
    }
    for (nod = minnod + nod; nod >= 1; nod--) {
        p = oldSet[s];
        oldSet[s] = oldSet[ne];
        sel = oldSet[ne] = p;
        newne = 0;
        for (i = 0; i < ne; i++) {
            if (!connected[sel][oldSet[i]]) {
                newSet[newne++] = oldSet[i];
            }
        }
        newce = newne;
        for (i = ne + 1; i < ce; i++) {
            if (!connected[sel][oldSet[i]]) {
                newSet[newce++] = oldSet[i];
            }
        }

        compsub.push_back(sel);
        if (newce == 0) {
            vector<int> copy = compsub;
            maximalSets.push_back(copy);

        } else if (newne < newce) {
            maximalSets = bkv2(newSet, newne, newce, compsub, maximalSets);
        }

        compsub.pop_back();

        ne++;
        if (nod > 1) {
            for (s = ne; !connected[fixp][oldSet[s]]; s++) {
            }
        }


    }
    return maximalSets;
}
1

There are 1 best solutions below

3
On

It's because you're not initializing size anywhere.