7 const int64_t n = myset.size();
9 std::set<int64_t>::const_iterator w, e = myset.end();
11 for(w = myset.begin(), i = 0; w != e; w++, i++){
19 int64_t mindegree = 1000000;
21 const int64_t n = this->
NNodes();
22 for(int64_t i = 0; i < n; i++){
23 if(ExploredNodes[i] == 1)
continue;
25 if(degree < mindegree){
40 for(int64_t i = 0; i < parents.
NElements(); i++){
43 for(int64_t j = 0; j < nlocal; j++){
44 const int64_t node = localAdjNodes[j];
45 if(exceptedNodes[node] == 0 && History[node] == 0){
46 adjNodes[count] = node;
57 const int64_t n = this->
Degree(parent);
59 for(int64_t i = 0; i < n; i++){
68 std::multimap<int64_t,int64_t> order;
70 const int64_t ndegree = this->
Degree(parent);
72 for(int64_t i = 0; i < ndegree; i++){
74 if(exceptedNodes[adj] == 1)
continue;
75 const int64_t adjDegree = this->
Degree(adj);
76 order.insert(std::make_pair(adjDegree,adj));
82 if(count != (int64_t)(order.size()) ){
86 std::multimap<int64_t,int64_t>::const_iterator mapIt;
88 for(i = 0, mapIt = order.begin(); mapIt != order.end(); i++, mapIt++){
89 adjNodes[i] = mapIt->second;
95 LevelStructure.Resize(0);
101 thisLevel[0] = rootNode;
105 for(int64_t iLevel = 0; iLevel < this->
NNodes(); iLevel++){
107 const int64_t nThisLevel = thisLevel.
NElements();
108 if(nThisLevel == 0)
break;
109 for(int64_t i = 0; i < nThisLevel; i++){
110 const int64_t node = thisLevel[i];
111 ProcessedNodes[node] = 1;
113 LevelStructure.Push( thisLevel);
115 this->
GetAdjacentNodes(LevelStructure[LevelStructure.NElements() - 1], ProcessedNodes, thisLevel);
119 LevelStructure.Shrink();
124 std::multimap<int64_t,int64_t> mymap;
125 for(int64_t i = 0; i < nodes.
NElements(); i++){
126 const int64_t node = nodes[i];
128 mymap.insert(std::make_pair(degree,node));
130 std::multimap<int64_t,int64_t>::const_iterator mapIt;
132 for(i = 0, mapIt = mymap.begin(); mapIt != mymap.end(); i++, mapIt++){
133 nodes[i] = mapIt->second;
139 const int64_t nelsOrig = LastLevel.
NElements();
144 std::map< int64_t, int64_t > mymap;
145 for(int64_t i = 0; i < LastLevel.
NElements(); i++){
146 const int64_t node = LastLevel[i];
150 LastLevel.
Resize(mymap.size());
151 std::map< int64_t, int64_t >::const_iterator w, e = mymap.end();
153 for(i = 0, w = mymap.begin(); w != e; w++, i++){
154 LastLevel[i] = w->second;
158 const int64_t newsize = (nelsOrig+2)/2;
160 LastLevel.
Resize( newsize );
178 std::ofstream myfile(
"c:\\Temp\\PseudoPeripheralNodes.txt");
182 const int64_t maxCount = 10;
187 while(count < maxCount || endNode == -1){
190 const int64_t cpStart = startNode;
191 const int64_t cpEnd = endNode;
193 myfile <<
"\nstart = " << startNode <<
" end = " << endNode <<
"\n\n";
195 const int64_t nlevels = LevelStructure.
NElements();
197 LastLevel = LevelStructure[ nlevels-1 ];
204 int64_t we = 1000000000L;
205 int64_t hs = nlevels;
206 const int64_t nelLastLevel = LastLevel.
NElements();
207 for(int64_t iQ = 0; iQ < nelLastLevel; iQ++){
209 const int64_t nodeAtQ = LastLevel[iQ];
211 myfile << count <<
"\t" << iQ <<
"\t";myfile.flush();
215 myfile <<
"rooted\t";myfile.flush();
218 const int64_t
h = localLevelStructure.
NElements();
220 for(int64_t j = 0; j <
h; j++){
221 const int64_t localW = localLevelStructure[j].
NElements();
222 if(localW > w) w = localW;
224 if(h > hs && w < we){
226 LevelStructure = localLevelStructure;
228 myfile <<
"break\n";myfile.flush();
237 myfile <<
"end\n";myfile.flush();
242 myfile <<
"\n"; myfile.flush();
245 if(cpStart == startNode && cpEnd == endNode){
250 if(startNode == -1 || endNode == -1)
DebugStop();
284 this->
Resequence(permGather, permScatter, permGatherReverse, permScatterReverse);
287 perm = permGatherReverse;
288 iperm = permScatterReverse;
301 std::cout <<
"TPZCutHillMcKee ConvertGraph...";
312 int64_t grafoindex[7] = {0,3,6,9,14,19,22};
313 int64_t grafo[22] = {3,4,5, 2,3,4, 1,3,4, 0,1,2,4,5, 0,1,2,3,5, 0,3,4};
315 for(int64_t i = 0; i < 7; i++) graph.
fnodegraphindex[i] = grafoindex[i];
317 for(int64_t i = 0; i < 22; i++) graph.
fnodegraph[i] = grafo[i];
322 std::ofstream myfile(
"c:\\Temp\\LevelStructure.txt");
323 for(int64_t iLevel = 0; iLevel < LevelStructure.NElements(); iLevel++){
324 myfile <<
"Level " << iLevel <<
": ";
325 for(int64_t j = 0; j < LevelStructure[iLevel].NElements(); j++){
326 myfile << LevelStructure[iLevel][j] <<
" ";
333 int64_t startNode = -1, endNode = -1;
337 std::ofstream myfile(
"c:\\Temp\\LevelStructureAfterPeripheral.txt");
338 for(int64_t iLevel = 0; iLevel < LevelStructure.
NElements(); iLevel++){
339 myfile <<
"Level " << iLevel <<
": ";
340 for(int64_t j = 0; j < LevelStructure[iLevel].
NElements(); j++){
341 myfile << LevelStructure[iLevel][j] <<
" ";
351 std::queue<int64_t> Q;
355 const int64_t nnodes = graph.NNodes();
360 std::cout <<
"TPZCutHillMcKee process...\n";std::cout.flush();
363 bool firstTime =
true;
366 std::cout <<
"Calling TPZCutHillMcKee::SGraph::SmallestDegree\n";
371 int64_t startNode = -1, endNode = -1;
372 graph.PseudoPeripheralNodes(startNode, endNode);
376 else Parent = graph.SmallestDegree(ExploredNodes);
379 if(R.
NElements() == graph.NNodes())
return;
385 const int64_t Child = Q.front();
397 std::set<int64_t> check;
398 for(int64_t i = 0; i < n; i++) check.insert(R[i]);
399 if( ((int64_t)(check.size())) != n)
DebugStop();
404 std::cout <<
"TPZCutHillMcKee Filling perm and iperm vectors...";std::cout.flush();
408 permScatterReverse.Resize(n);
409 for(int64_t i = 0; i < n; i++) permScatterReverse[n-1-i] = R[i];
410 permGatherReverse.
Resize(n);
411 for(int64_t i = 0; i < n; i++) permGatherReverse[ permScatterReverse[i] ] = i;
416 for(int64_t i = 0; i < n; i++) permGather[ permScatter[i] ] = i;
425 std::queue<int64_t> &Q,
429 ExploredNodes[Parent] = 1;
431 const int64_t nadj = adjNodes.
NElements();
432 for(int64_t i = 0; i < nadj; i++){
433 if(ExploredNodes[adjNodes[i]] == 0){
435 ExploredNodes[adjNodes[i]] = 1;
void Set2Vec(const std::set< int64_t > &myset, TPZVec< int64_t > &myVec) const
TPZManVector< int64_t > fnodegraph
Implements a vector class which allows to use external storage provided by the user. Utility.
void ShrinkLastLevel(TPZVec< int64_t > &LastLevel)
void GetAdjacentNodes(const TPZVec< int64_t > &parents, const TPZVec< int64_t > &exceptedNodes, TPZStack< int64_t > &adjNodes)
void ConvertGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex, TPZManVector< int64_t > &nodegraph, TPZManVector< int64_t > &nodegraphindex)
Will convert an element graph defined by elgraph and elgraphindex into a node graph defined by nodegr...
virtual void Resequence(TPZVec< int64_t > &permGather, TPZVec< int64_t > &permScatter, TPZVec< int64_t > &permGatherReverse, TPZVec< int64_t > &permScatterReverse)
virtual ~TPZCutHillMcKee()
void degree(int root, int adj_num, int adj_row[], int adj[], int mask[], int deg[], int *iccsze, int ls[], int node_num)
void AdjacentNodes(int64_t parent, TPZVec< int64_t > &adjNodes)
clarg::argBool h("-h", "help message", false)
int64_t Degree(int64_t node)
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
void RootedLevelStructure(int64_t rootNode, TPZStack< TPZStack< int64_t > > &LevelStructure)
TPZVec< int64_t > fElementGraphIndex
Indicates for each element the index of the first entry with fElementGraph for that element The size ...
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
void Push(const T object)
Pushes a copy of the object on the stack.
This abstract class which defines the behavior which derived classes need to implement for implement...
#define DebugStop()
Returns a message to user put a breakpoint in.
int64_t SmallestDegree(TPZVec< int64_t > &ExploredNodes)
void AdjacentNodesOrdered(int64_t parent, const TPZVec< int64_t > &exceptedNodes, TPZVec< int64_t > &adjNodes)
void Shrink()
It reallocates storage to fit the necessary storage exactly.
TPZVec< int64_t > fElementGraph
Node number of each element.
TPZManVector< int64_t > fnodegraphindex
int64_t * AdjacentNodesPtr(int64_t parent, int64_t &n)
int64_t NElements() const
Returns the number of elements of the vector.
void SortNodes(TPZVec< int64_t > &nodes)
void PseudoPeripheralNodes(int64_t &startNode, int64_t &endNode)
void ProcessParentNode(int64_t Parent, SGraph &graph, TPZVec< int64_t > &ExploredNodes, TPZStack< int64_t > &R, std::queue< int64_t > &Q, TPZVec< int64_t > &adjNodes)
void