22 int cutstep = gparm.maxid;
26 a =
new double [gparm.maxid];
27 Q =
new double [gparm.n+1];
28 joins =
new apair [gparm.n+1];
29 for (
int i=0; i<gparm.maxid; i++) { a[i] = 0.0; }
30 for (
int i=0; i<gparm.n+1; i++) { Q[i] = 0.0; joins[i].
x = 0; joins[i].y = 0; }
32 Qmax.y = -4294967296.0; Qmax.x = 0;
33 if (cutstep > 0) { groupListsSetup(); }
35 cout <<
"now building initial dQ[]" << endl;
39 cout <<
"starting algorithm now." << endl;
41 int isupport, jsupport;
42 while (h->heapSize() > 1) {
46 dQmax = h->popMaximum();
47 if (dQmax.
m < -4000000000.0) {
break; }
53 if (dq[dQmax.
i].v ==
nullptr || dq[dQmax.
j].v ==
nullptr) {
54 cout << dQmax.
i<<endl;
55 cout << dQmax.
j<<endl;
56 cout <<
"WARNING: invalid join (" << dQmax.
i <<
" " << dQmax.
j <<
") found at top of heap\n"; cin >> pauseme;
58 isupport = dq[dQmax.
i].v->returnNodecount();
59 jsupport = dq[dQmax.
j].v->returnNodecount();
60 if (isupport < jsupport) {
63 mergeCommunities(dQmax.
i, dQmax.
j);
69 dq[dQmax.
i].heap_ptr = dq[dQmax.
j].heap_ptr;
70 dq[dQmax.
i].heap_ptr->i = dQmax.
i;
71 dq[dQmax.
i].heap_ptr->j = dQmax.
j;
72 mergeCommunities(dQmax.
j, dQmax.
i);
76 Q[t] = dQmax.
m + Q[t-1];
88 if (t <= cutstep) { groupListsUpdate(joins[t].x, joins[t].y); }
91 if (Q[t] > Qmax.y) { Qmax.y = Q[t]; Qmax.x = t; }
95 cout <<
"exited safely" << endl;
97 int index = getClusterIndex();
98 return c[index].members;
119 cout <<
" scanning input file for basic information." << endl;
120 cout <<
" edgecount: [0]"<<endl;
121 ifstream fscan(path.c_str(), ios::in);
122 while (fscan >> s >> f) {
124 if (f < s) { t = s; s = f; f = t; }
125 if (f > numnodes) { numnodes = f; }
126 edgeList.push_back(s-1);
127 edgeList.push_back(f-1);
130 cout <<
" edgecount: ["<<numlinks<<
"] total (first pass)"<<endl;
131 gparm.maxid = numnodes+2;
132 elist =
new myEdge [2*numlinks];
137 cout <<
" allocating space for network." << endl;
138 e =
new myEdge [gparm.maxid];
139 last =
new myEdge* [gparm.maxid];
143 cout <<
" reparsing the input file to build network data structure." << endl;
144 cout <<
" edgecount: [0]"<<endl;
145 ifstream fin(path.c_str(), ios::in);
146 while (fin >> s >> f) {
148 if (f < s) { t = s; s = f; f = t; }
158 while (current !=
nullptr) {
159 if (current->
si==f) {
164 current = current->
next;
167 newedge = &elist[ecounter++];
170 last[s] -> next = newedge;
182 newedge = &elist[ecounter++];
185 last[f] -> next = newedge;
190 cout <<
" edgecount: ["<<numlinks<<
"] total (second pass)"<<endl;
221 double eij = (double)(0.5/gparm.m);
222 for (
int i=1; i<gparm.maxid; i++) {
227 while (current->
next !=
nullptr) {
229 current = current->
next;
231 Q[0] += -1.0*a[i]*a[i];
236 dq =
new nodenub [gparm.maxid];
237 for (
int i=0; i<gparm.maxid; i++) {
239 if (e[i].so != 0) { dq[i].v =
new myVector(2+(
int)floor(gparm.m*a[i])); }
240 else { dq[i].v =
nullptr; }
253 for (
int i=1; i<gparm.maxid; i++) {
256 dQ = 2.0*(eij-(a[current->
so]*a[current->
si]));
258 dQmax.
i = current->
so;
259 dQmax.
j = current->
si;
260 dq[i].v->insertItem(current->
si, dQ);
261 while (current->
next !=
nullptr) {
262 current = current->
next;
263 dQ = 2.0*(eij-(a[current->
so]*a[current->
si]));
266 dQmax.
j = current->
si;
268 dq[i].v->insertItem(current->
si, dQ);
270 dq[i].heap_ptr = h->insertItem(dQmax);
281 c =
new myStub [gparm.maxid];
282 for (
int i=0; i<gparm.maxid; i++) {
286 c[i].members = newList;
329 myDpair *list, *current, *temp;
337 list = dq[i].v->returnTreeAsList();
346 while (current!=
nullptr) {
350 if (current->
x != j) {
356 if (dq[j].v->findItem(current->
x)) {
362 dq[current->
x].v->insertItem(j,current->
y);
366 dq[current->
x].v->deleteItem(i);
371 newMax = dq[current->
x].v->returnMaxStored();
372 h->updateItem(dq[current->
x].heap_ptr, newMax);
376 dq[j].v->insertItem(current->
x,current->
y);
382 double axaj = -2.0*a[current->
x]*a[j];
385 dq[current->
x].v->insertItem(j,current->
y + axaj);
389 dq[current->
x].v->deleteItem(i);
394 newMax = dq[current->
x].v->returnMaxStored();
395 h->updateItem(dq[current->
x].heap_ptr, newMax);
399 dq[j].v->insertItem(current->
x,current->
y + axaj);
404 current = current->
next;
412 dq[j].v->deleteItem(i);
417 newMax = dq[j].v->returnMaxStored();
418 h->updateItem(dq[j].heap_ptr, newMax);
429 list = dq[j].v->returnTreeAsList();
433 while (current !=
nullptr) {
438 if ((current->
x != i) && (!dq[i].v->findItem(current->
x))) {
442 double axai = -2.0*a[current->
x]*a[i];
445 dq[current->
x].v->insertItem(j, axai);
448 newMax = dq[current->
x].v->returnMaxStored();
449 h->updateItem(dq[current->
x].heap_ptr, newMax);
453 dq[j].v->insertItem(current->
x, axai);
454 newMax = dq[j].v->returnMaxStored();
456 h->updateItem(dq[j].heap_ptr, newMax);
461 current = current->
next;
480 dq[i].heap_ptr =
nullptr;
492 c[y].last->next = c[x].members;
493 c[y].last = c[x].last;
494 c[y].size += c[x].size;
496 c[x].members =
nullptr;
512 for (
int i=0; i<gparm.maxid; i++) {
515 current = c[i].members;
530 myDpair *list, *current, *temp;
532 for (
int i=0; i<gparm.maxid; i++) {
533 if (dq[i].heap_ptr !=
nullptr) {
534 list = dq[i].v->returnTreeAsList();
536 while (current !=
nullptr) {
538 cout << i-1 <<
"\t" << current->
x-1 <<
"\t" << current->
y << endl;
541 current = current->
next;
554 gstats.numgroups = 0;
556 gstats.minsize = gparm.maxid;
558 for (
int i=0; i<gparm.maxid; i++) {
562 if (c[i].size > gstats.maxsize) { gstats.maxsize = c[i].size; }
563 if (c[i].size < gstats.minsize) { gstats.minsize = c[i].size; }
565 gstats.meansize = (double)(c[i].size)/count + (((double)(count-1.0)/count)*gstats.meansize);
570 gstats.sizehist =
new double [gstats.maxsize+1];
571 for (
int i=0; i<gstats.maxsize+1; i++) { gstats.sizehist[i] = 0; }
572 for (
int i=0; i<gparm.maxid; i++) {
574 gstats.sizehist[c[i].size] += 1.0;
579 for (
int i=0; i<gstats.maxsize+1; i++) { gstats.sizehist[i] = gstats.sizehist[i]/count; }
myEdge * next
Pointer zur naechsten Kante.
mytuple * heap_ptr
Adresse des Knoten im MaxHeap.
myDpair * next
Pointer auf naechstes Datenpaar.
int si
Index des Kantenendes.
double y
Beschreibt den Wert/Parameter an der Stelle x.
int i
Zeilenindex des Elements.
double m
Abgelegter Wert/Parameter.
int x
Beschreibt einen Key oder einen Index.
int j
Spaltenindex des Elements.
int x
Der hinzufuegende Knoten.
int so
Index des Kantenursprungs.