c++ - Unhandled exception at 0x76d84b61 in Partition_2.exe: 0xC00000FD: Stack overflow -
i running tarjan algorithm find scc in c++. code running me when number of nodes 80k. when ran code more 80k graph nodes. giving me error stack overflow
unhandled exception @ 0x76d84b61 in partition_2.exe: 0xc00000fd: stack overflow.
i looked online suggestions, says functions passes maximum number of recursion. have no idea now?
here code:
tarjan::tarjan(vector<linkedlist> &graph, vector<vector<linkedlist*>> &scc) { cout<<endl<<"finding scc in graph ....."<<endl; clock_t start, finish; start = clock(); int num = 1; vector<linkedlist*> stack; for(size_t = 0; i<graph.size(); i++) { if(graph[i].index == 0) { strongconnect(&graph[i], num, stack, scc); } } finish = clock(); if(scc.size()>0) { cout<<"number of cycles found in graph "<<scc.size()<<endl; timetracker=(finish-start); cout<<"time taken find cycles in graph "<<timetracker<<" ms "<<endl; } else cout<<"no cycles found in graph "<<endl<<endl; } void tarjan::strongconnect(linkedlist* vertex, int &num, vector<linkedlist*> &stack, vector<vector<linkedlist*>> &cycles) { vertex->index = num; vertex->lowlink = num; num++; vertex->instack = true; stack.push_back(vertex); for(map<linkedlist*, string>::iterator it=vertex->childaddr.begin(); it!=vertex->childaddr.end(); it++) { if(it->first->index == 0) { strongconnect(it->first, num, stack, cycles); vertex->lowlink = min(vertex->lowlink, it->first->lowlink); } else { if(it->first->instack) { vertex->lowlink = min(vertex->lowlink, it->first->index); } } } if(vertex->lowlink == vertex -> index) { vector<linkedlist*> temp; linkedlist* x; do{ x=stack[stack.size()-1]; vector<linkedlist*>::iterator st = stack.end(); st--; stack.erase(st); x->instack=false; temp.push_back(x); if(temp.size()>1) x->inclique = true; }while(vertex->node != x->node); if(temp.size()>1) { temp[0]->inclique=true; cycles.push_back(temp); } } } linkedlist.h class linkedlist { public: string node; map<linkedlist*, string> childaddr; bool instack; // find ssc bool inclique; // distinguish if node belongs clique or not int index; // find ssc int lowlink; // find ssc bool visited; }; i had spent weeks on figure out solution no gain. please me here. thanks.
for millions of nodes, or if program needs compilation on computer don't control compiler options, consider replacing recursion std::stack data structure , loop: http://www.codeproject.com/articles/418776/how-to-replace-recursive-functions-using-stack-and (or 1 shorter, not in c++ http://haacked.com/archive/2007/03/04/replacing_recursion_with_a_stack.aspx/ )
Comments
Post a Comment