-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathundirected_oslomnet_evaluate.h
826 lines (449 loc) · 20.6 KB
/
undirected_oslomnet_evaluate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
inline double log_zero(double a) {
if(a<=0)
return -1e20;
else
return log(a);
}
class oslomnet_evaluate : public oslomnet_louvain {
public:
oslomnet_evaluate(deque<deque<int> > & b, deque<deque<pair<int, double> > > & c, deque<int> & d): oslomnet_louvain() { set_graph(b,c,d); set_maxbord(); set_changendi_cum(); };
oslomnet_evaluate(string a): oslomnet_louvain() { set_graph(a); set_maxbord(); set_changendi_cum(); };
oslomnet_evaluate(map<int, map<int, pair<int, double> > > & A) : oslomnet_louvain() { set_graph(A); set_maxbord(); set_changendi_cum(); };
~oslomnet_evaluate(){};
double CUP_both(const deque<int> & _c_, deque<int> & gr_cleaned, int);
double CUP_check(const deque<int> & _c_, deque<int> & gr_cleaned, int);
double group_inflation(const deque<int> & _c_, deque<int> & gr_cleaned, int);
private:
void erase_cgroup(int wnode);
void insert_cgroup(int wnode);
bool erase_the_worst(int & wnode);
int set_maxbord();
void set_cgroup_and_neighs(const deque<int> & G);
double all_external_test(int kout_g, int tm, int Nstar, int nneighs, const double & max_r_one, const double & maxr_two, deque<int> & gr_cleaned, bool only_c, weighted_tabdeg & previous_tab_c);
double cup_on_list(cup_data_struct & a, deque<int> & gr_cleaned);
void get_external_scores(weighted_tabdeg & ne_, cup_data_struct & fitness_label_to_sort, int kout_g, int tm, int Nstar, int nneighs, const double & max_r, bool only_c, weighted_tabdeg & previous_tab_c);
double CUP_runs(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int kin_cgroup_prev, int ktot_cgroup_prev, deque<int> & gr_cleaned, bool only_c, int runs);
void initialize_for_evaluation(const deque<int> & _c_, weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int & kin_cgroup_prev, int & ktot_cgroup_prev);
void initialize_for_evaluation(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int & kin_cgroup_prev, int & ktot_cgroup_prev);
double partial_CUP(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int kin_cgroup_prev, int ktot_cgroup_prev, deque<int> & gr_cleaned, bool only_c);
void set_changendi_cum();
void insertion(int changendi);
bool insert_the_best();
double CUP_iterative(const deque<int> & _c_, deque<int> & gr_cleaned, int);
double CUP_search(const deque<int> & _c_, deque<int> & gr_cleaned, int);
/* DATA ***************************************************/
double max_r_bord; // this is the maximum r allowed for the external nodes (we don't want to look at all the graph, it would take too long)
int maxb_nodes; // this is the maximum number of nodes allowed in the border (similar as above)
deque<double> changendi_cum; // this is the cumulative distribution of the number of nodes to add to the cluster in the group_inflation function
// ************* things to update *************************
weighted_tabdeg cgroup; //*
weighted_tabdeg neighs; //*
//*
int kin_cgroup; //*
int ktot_cgroup; //*
/*********************************************************/
};
void oslomnet_evaluate::set_changendi_cum() {
if(dim!=0 && oneM!=0) {
int flat_until= cast_int(oneM/dim * 3);
flat_until=min(dim/2, flat_until);
int max_p= max(paras.CUT_Off, flat_until); // this is something which might be optimized
max_p=min(dim/2, max_p);
powerlaw(max_p, flat_until+1, 3, changendi_cum);
deque<double> distr;
distribution_from_cumulative(changendi_cum, distr);
double ac=1;
if(distr.size()>0)
ac=distr[0];
for(int i=0; i<flat_until; i++)
distr.push_front(ac);
normalize_one(distr);
cumulative_from_distribution(changendi_cum, distr);
}
}
int oslomnet_evaluate::set_maxbord() {
max_r_bord=paras.maxbg_ordinary;
maxb_nodes=paras.maxborder_nodes;
return 0;
}
void oslomnet_evaluate::erase_cgroup(int wnode) {
map<int, facts>::iterator itm= cgroup.lab_facts.find(wnode);
if(itm!=cgroup.lab_facts.end()) {
int kp = itm->second.internal_degree;
int kt = itm->second.degree;
double mtlw= itm->second.minus_log_total_wr;
kin_cgroup-= 2 * kp;
ktot_cgroup-=kt;
int kout_g= ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
double fi= compute_global_fitness_ofive(kp, kout_g, tm, kt, mtlw, neighs.size()+1, dim - cgroup.size() +1);
neighs.edinsert(wnode, kp, kt, mtlw, fi);
cgroup.erase(wnode);
deque<int> tobe;
for(int i=0; i<vertices[wnode]->links->size(); i++) {
if(cgroup.update_group(vertices[wnode]->links->l[i], -vertices[wnode]->links->w[i].first, -vertices[wnode]->links->w[i].second,
dim - cgroup.size(), neighs.size(), kout_g, tm, vertices[vertices[wnode]->links->l[i]]->stub_number, tobe)==false)
neighs.update_neighs(vertices[wnode]->links->l[i], -vertices[wnode]->links->w[i].first, -vertices[wnode]->links->w[i].second,
dim - cgroup.size(), kout_g, tm, vertices[vertices[wnode]->links->l[i]]->stub_number);
}
for(int i=0; i<int(tobe.size()); i++)
erase_cgroup(tobe[i]);
}
}
bool oslomnet_evaluate::erase_the_worst(int & wnode) {
// this function is to look for the worst node in cgroup and to erase it
int Nstar= dim - cgroup.size();
int nn= neighs.size();
int kout_g = ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
double wf;
cgroup.worst_node(wnode, wf, kout_g, Nstar, nn, tm);
if(cgroup.size()==0) {
return false;
}
erase_cgroup(wnode);
return true;
}
void oslomnet_evaluate::insert_cgroup(int wnode) {
// this function is to insert wnode into cgroup updating all the system, neighs - kin_cgroup - ktot_cgroup
// it needs to be differenciated between weighted and unweighted
int kp, kt;
double mtlw;
{
map<int, facts>::iterator itm= neighs.lab_facts.find(wnode);
if(itm!=neighs.lab_facts.end()) {
kp = itm->second.internal_degree;
kt = itm->second.degree;
mtlw= itm->second.minus_log_total_wr;
} else {
kp=0;
kt=vertices[wnode]->stub_number;
mtlw=0;
}
}
int kout_g= ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
double fi= compute_global_fitness_ofive(kp, kout_g, tm, kt, mtlw, neighs.size(), dim - cgroup.size());
kin_cgroup+= 2 * kp;
ktot_cgroup+=kt;
kout_g= ktot_cgroup - kin_cgroup;
tm= oneM - ktot_cgroup;
cgroup.edinsert(wnode, kp, kt, mtlw, fi);
neighs.erase(wnode);
deque<int> tobe;
for(int i=0; i<vertices[wnode]->links->size(); i++) {
if(cgroup.update_group(vertices[wnode]->links->l[i], vertices[wnode]->links->w[i].first, vertices[wnode]->links->w[i].second,
dim - cgroup.size(), neighs.size(), kout_g, tm, vertices[vertices[wnode]->links->l[i]]->stub_number, tobe)==false)
neighs.update_neighs(vertices[wnode]->links->l[i], vertices[wnode]->links->w[i].first, vertices[wnode]->links->w[i].second,
dim - cgroup.size(), kout_g, tm, vertices[vertices[wnode]->links->l[i]]->stub_number);
}
}
void oslomnet_evaluate::set_cgroup_and_neighs(const deque<int> & G) {
// this function initially sets the data structures for the group and its neighbors
kin_cgroup=0;
ktot_cgroup=0;
cgroup.clear();
neighs.clear();
for(int i=0; i<int(G.size()); i++)
insert_cgroup(G[i]);
}
double oslomnet_evaluate::cup_on_list(cup_data_struct & a, deque<int> & gr_cleaned) {
int Nstar;
if(paras.weighted)
Nstar=neighs.size();
else
Nstar=dim-cgroup.size();
double critical_xi= -log(1-paras.threshold)/fitted_exponent(Nstar);
int pos=Nstar;
int until=-1; // until tells how many nodes should be included into the cluster - actually the number of good nodes are (until +1)
double probability_a, probability_b; // these are the two extremes of a possible good node I could have found
double c_min=1; // this is the score we give to the border we are evaluating here
//cout<<"critical_xi: "<<critical_xi<<" --------------------------------------- "<<neighs.size()<<" cgroup "<<cgroup.size()<<endl<<endl<<endl;
cup_data_struct :: iterator itl=a.begin();
while(itl!=a.end()) {
double c_pos=order_statistics_left_cumulative(Nstar, pos, itl->first);
//cout<<"position .... "<<pos<<" "<<order_statistics_left_cumulative(Nstar, pos, itl->first + itl->second.second)<<" >>AAA<< "<<Nstar<<" +++ "<<itl->first + itl->second.second<<" "<<itl->first - itl->second.second<<endl;
c_min=min(c_pos, c_min);
if(c_pos<critical_xi) {
/*
this is the basic condition of the order statistics test
it's saying: look, this guy (itl->second.first) has an average fitness (itl->first)
whose order_statistics_left_cumulative is below the threshold
*/
if(until==-1) { // this node is the first node to be below the threshold
until= Nstar-pos;
c_min=c_pos;
probability_a=itl->first - itl->second.second;
probability_b=itl->first + itl->second.second;
} else {
/*
the previous node was already below the threshold.
In this case I need to know if I should stop now or go on.
The condition is related to the probability_to_overtake the previous guy
*/
double probability_to_overtake= compare_r_variables(probability_a, probability_b, itl->first - itl->second.second, itl->first + itl->second.second);
if(probability_to_overtake>0.4999) { /*preliminary check: this node is basically equivalent to the previous guy, I consider it good*/
until= Nstar-pos;
c_min=c_pos;
probability_a=itl->first - itl->second.second;
probability_b=itl->first + itl->second.second;
} else {
/*now I need to compute the bootstrap probability that the previous guy would have stopped the process*/
if( (probability_to_overtake==0) || ((1.-probability_to_overtake) * compute_probability_to_stop(probability_a, probability_b, critical_xi, Nstar, pos+1)> 0.5001)) {
if(equivalent_check_gather(a, until, probability_a, probability_b, Nstar, critical_xi))
break;
}
until= Nstar-pos;
c_min=c_pos;
probability_a=itl->first - itl->second.second;
probability_b=itl->first + itl->second.second;
}
}
} else { /* this node is not below the threshold */
if(until!=-1) { /* this means that this node is not good and the previous one was good. So, I stop here */
if(equivalent_check_gather(a, until, probability_a, probability_b, Nstar, critical_xi))
break;
}
}
--pos;
++itl;
}
// equalizer check
// this check is important to see if the procedure stopped just because there were a lot of equivalents nodes
if(until!=-1 && itl==a.end())
equivalent_check_gather(a, until, probability_a, probability_b, Nstar, critical_xi);
// inserting nodes in gr_cleaned
int nodes_added=-1;
itl=a.begin();
while(itl!=a.end()) {
if(nodes_added==until)
break;
gr_cleaned.push_back(itl->second.first);
++itl;
++nodes_added;
}
return pron_min_exp(Nstar, c_min);
}
double oslomnet_evaluate::all_external_test(int kout_g, int tm, int Nstar, int nneighs, const double & max_r_one, const double & maxr_two, deque<int> & gr_cleaned, bool only_c, weighted_tabdeg & previous_tab_c) {
double max_r=min(max_r_one, maxr_two);
cup_data_struct fitness_label_to_sort;
get_external_scores(neighs, fitness_label_to_sort, kout_g, tm, Nstar, nneighs, max_r, only_c, previous_tab_c);
return cup_on_list(fitness_label_to_sort, gr_cleaned);
}
void oslomnet_evaluate::initialize_for_evaluation(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int & kin_cgroup_prev, int & ktot_cgroup_prev) {
int Nstar= dim - cgroup.size();
int nn= neighs.size();
int kout_g = ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
previous_tab_c.set_and_update_group(Nstar, nn, kout_g, tm, cgroup);
previous_tab_n.set_and_update_neighs(Nstar, nn, kout_g, tm, neighs);
kin_cgroup_prev=kin_cgroup;
ktot_cgroup_prev=ktot_cgroup;
}
void oslomnet_evaluate::initialize_for_evaluation(const deque<int> & _c_, weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int & kin_cgroup_prev, int & ktot_cgroup_prev) {
set_cgroup_and_neighs(_c_);
int Nstar= dim - cgroup.size();
int nn= neighs.size();
int kout_g = ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
previous_tab_c.set_and_update_group(Nstar, nn, kout_g, tm, cgroup);
previous_tab_n.set_and_update_neighs(Nstar, nn, kout_g, tm, neighs);
kin_cgroup_prev=kin_cgroup;
ktot_cgroup_prev=ktot_cgroup;
}
double oslomnet_evaluate::partial_CUP(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int kin_cgroup_prev, int ktot_cgroup_prev, deque<int> & border_group, bool only_c) {
// still there is some stochasticity due to possible ties
/* previous_stuff is the module-stuff before the CUP (Clean Up Procedure)
cgroup + border_group is the module cleaned */
border_group.clear();
cgroup._set_(previous_tab_c);
neighs._set_(previous_tab_n);
kin_cgroup=kin_cgroup_prev;
ktot_cgroup=ktot_cgroup_prev;
if(cgroup.size()==dim) {
return 1;
}
double bscore=1;
while (true) {
bscore= all_external_test(ktot_cgroup - kin_cgroup, oneM - ktot_cgroup, dim - cgroup.size(), neighs.size(), maxb_nodes/double(dim-cgroup.size()), max_r_bord, border_group, only_c, previous_tab_c);
if(border_group.size()>0)
break;
if(cgroup.size()==0)
break;
int wnode;
erase_the_worst(wnode);
}
return bscore;
}
double oslomnet_evaluate::CUP_runs(weighted_tabdeg & previous_tab_c, weighted_tabdeg & previous_tab_n, int kin_cgroup_prev, int ktot_cgroup_prev, deque<int> & gr_cleaned, bool only_c, int number_of_runs) {
/* this if statemets are here to speed up the program if there are big clusters */
if(previous_tab_c.size()>100000)
number_of_runs=3;
else if(previous_tab_c.size()>10000)
number_of_runs=5;
else if(previous_tab_c.size()>1000)
number_of_runs=10;
gr_cleaned.clear();
if(previous_tab_c.size()==0)
return 1;
int max_gr_size=0;
double bscore=1;
int good_runs=0;
for(int i=0; i<number_of_runs; i++) {
deque<int> gr_run_i;
double score_i= partial_CUP(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_run_i, only_c);
if(cgroup.size()+ int(gr_run_i.size())> max_gr_size) {
bscore=score_i;
cgroup.set_deque(gr_cleaned);
for(int j=0; j<int(gr_run_i.size()); j++)
gr_cleaned.push_back(gr_run_i[j]);
max_gr_size=gr_cleaned.size();
sort(gr_cleaned.begin(), gr_cleaned.end());
}
if(gr_run_i.size()>0) {
++good_runs;
if(good_runs>=0.55 * number_of_runs)
return bscore;
}
}
if(good_runs<0.55*number_of_runs) {
gr_cleaned.clear();
bscore+=paras.threshold;
bscore=min(1., bscore);
}
return bscore;
}
double oslomnet_evaluate::CUP_check(const deque<int> & _c_, deque<int> & gr_cleaned, int number_of_runs = paras.clean_up_runs) {
/*_c_ is the module to clean up and gr_cleaned is the result */
weighted_tabdeg previous_tab_c;
weighted_tabdeg previous_tab_n;
int kin_cgroup_prev;
int ktot_cgroup_prev;
double bscore;
initialize_for_evaluation(_c_, previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
bscore=CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, true, number_of_runs);
return bscore;
}
double oslomnet_evaluate::CUP_search(const deque<int> & _c_, deque<int> & gr_cleaned, int number_of_runs = paras.clean_up_runs) {
/*_c_ is the module to clean up and gr_cleaned is the result */
weighted_tabdeg previous_tab_c;
weighted_tabdeg previous_tab_n;
int kin_cgroup_prev;
int ktot_cgroup_prev;
double bscore;
initialize_for_evaluation(_c_, previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
bscore=CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, false, number_of_runs);
return bscore;
}
double oslomnet_evaluate::CUP_both(const deque<int> & _c_, deque<int> & gr_cleaned, int number_of_runs = paras.clean_up_runs) {
/*_c_ is the module to clean up and gr_cleaned is the result */
weighted_tabdeg previous_tab_c;
weighted_tabdeg previous_tab_n;
int kin_cgroup_prev;
int ktot_cgroup_prev;
double bscore;
initialize_for_evaluation(_c_, previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
bscore=CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, false, number_of_runs);
initialize_for_evaluation(gr_cleaned, previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
bscore=CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, true, number_of_runs); /*this "true" means I can only look at nodes in previous_tab_c*/
return bscore;
}
double oslomnet_evaluate::CUP_iterative(const deque<int> & _c_, deque<int> & gr_cleaned, int number_of_runs = paras.clean_up_runs) {
double bs= CUP_both(_c_, gr_cleaned, number_of_runs);
int stopp=0;
do {
deque<int> _c_temp = gr_cleaned;
bs = CUP_search(_c_temp, gr_cleaned, number_of_runs);
++stopp;
if(stopp==paras.iterative_stopper)
break;
} while (gr_cleaned.size()>_c_.size());
return bs;
}
bool oslomnet_evaluate::insert_the_best() {
int Nstar= dim - cgroup.size();
int nn= neighs.size();
int kout_g = ktot_cgroup - kin_cgroup;
int tm= oneM - ktot_cgroup;
double lowest_r;
int benode;
neighs.best_node(benode, lowest_r, kout_g, Nstar, nn, tm);
if(benode==-1)
return false;
insert_cgroup(benode);
return true;
}
void oslomnet_evaluate::insertion(int changendi) {
for(int i=0; i<changendi; i++)
insert_the_best();
}
double oslomnet_evaluate::group_inflation(const deque<int> & _c_, deque<int> & gr_cleaned, int number_of_runs=paras.inflate_runs) {
/* preliminary check */
double bscore=CUP_iterative(_c_, gr_cleaned);
if(gr_cleaned.size()>0) {
return bscore;
}
/* preliminary check */
//cout<<"group inflating... "<<endl;
weighted_tabdeg _c_tab_c;
weighted_tabdeg _c_tab_n;
int kin_cgroup_c;
int ktot_cgroup_c;
initialize_for_evaluation(_c_, _c_tab_c, _c_tab_n, kin_cgroup_c, ktot_cgroup_c);
weighted_tabdeg previous_tab_c;
weighted_tabdeg previous_tab_n;
int kin_cgroup_prev;
int ktot_cgroup_prev;
int stopper=0;
while(true) {
cgroup._set_(_c_tab_c);
neighs._set_(_c_tab_n);
kin_cgroup=kin_cgroup_c;
ktot_cgroup=ktot_cgroup_c;
int changendi=lower_bound(changendi_cum.begin(), changendi_cum.end(), ran4()) - changendi_cum.begin() + 1;
changendi=min(changendi, neighs.size());
insertion(changendi);
if(cgroup.size()==dim)
return 1;
/*here it make a CUP_search using c_group with the nodes added*/
initialize_for_evaluation(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, false, number_of_runs);
if(gr_cleaned.size()>0) {
/*the first clean up passed. now it makes the CUP_check*/
initialize_for_evaluation(gr_cleaned, previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev);
bscore=CUP_runs(previous_tab_c, previous_tab_n, kin_cgroup_prev, ktot_cgroup_prev, gr_cleaned, true, paras.clean_up_runs);
//cout<<"exiting... "<<gr_cleaned.size()<<endl;
if(gr_cleaned.size()>0) {
return bscore;
}
}
++stopper;
if(stopper==paras.inflate_stopper)
break;
}
//cout<<"bad group"<<endl;
return 1;
}
void oslomnet_evaluate::get_external_scores(weighted_tabdeg& neighs, cup_data_struct & fitness_label_to_sort, int kout_g, int tm, int Nstar, int nneighs, const double & max_r, bool only_c, weighted_tabdeg & previous_tab_c) {
multimap<double, int>:: iterator bit= neighs.fitness_lab.begin();
int counter=0;
while(bit!=neighs.fitness_lab.end()) {
map<int, facts> :: iterator itm= neighs.lab_facts.find(bit->second);
double interval;
double F= compute_global_fitness(itm->second.internal_degree, kout_g, tm, itm->second.degree, itm->second.minus_log_total_wr, nneighs, Nstar, interval);
if(F>max_r) {
/*if(only_c == false || previous_tab_c.is_internal(itm->first))
cout<<"no node: "<<vertices[itm->first]->id_num<<" "<<itm->second.internal_degree<<" / "<< itm->second.degree<<" fitness: "<<F<<endl;*/
counter++;
if(counter>num_up_to)
break;
}
else {
/*if(only_c == false || previous_tab_c.is_internal(itm->first))
cout<<"node: "<<" "<<itm->second.internal_degree<<" / "<< itm->second.degree<<" fitness: "<<F<<" "<<interval<<endl;*/
if(only_c == false || previous_tab_c.is_internal(itm->first))
fitness_label_to_sort.insert(make_pair(F, make_pair(itm->first, interval)));
}
bit++;
}
}