Skip to content

Commit 66467c3

Browse files
committed
Optimized graph generation
1 parent 6de51f3 commit 66467c3

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/main/java/ldbc/snb/datagen/generator/ClusteringKnowsGenerator.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class ClusteringKnowsGenerator implements KnowsGenerator {
2121
private int numCoreCoreEdges = 0;
2222
private int numCorePeripheryEdges = 0;
2323
private int numCoreExternalEdges = 0;
24-
// private float step_ = 0.10f;
2524
private float min_community_prob_ = 0.0f;
2625

2726
private class PersonInfo {
@@ -208,11 +207,6 @@ private void computeCommunityInfo(ClusteringInfo cInfo, Community c, float prob)
208207

209208
// Initializing cInfo with expected degrees
210209
for (PersonInfo pI : c.core_) {
211-
//double core_core_degree = (c.core_.size() - 1) * prob;
212-
//long complete_edges = (long)core_core_degree;
213-
//double incomplete_edge = core_core_degree - complete_edges;
214-
//if(rand.nextDouble() < incomplete_edge) complete_edges++;
215-
//cInfo.core_node_expected_core_degree_.set(pI.index_, new Double(complete_edges));
216210
cInfo.core_node_expected_core_degree_.set(pI.index_,(c.core_.size() - 1) * (double)prob);
217211
cInfo.core_node_excedence_degree_.set(pI.index_, pI.degree_ - cInfo.core_node_expected_core_degree_.get(pI.index_));
218212
cInfo.core_node_expected_periphery_degree_.set(pI.index_, 0.0);
@@ -241,7 +235,6 @@ private void computeCommunityInfo(ClusteringInfo cInfo, Community c, float prob)
241235

242236

243237
private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob ) {
244-
//System.out.println("Recompunting community with prob "+c.p_);
245238
computeCommunityInfo(cInfo, c, prob);
246239

247240
float probSameCommunity = 0.0f;
@@ -340,7 +333,8 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
340333
}
341334

342335
float clusteringCoefficient(ArrayList<Community> communities, ClusteringInfo cInfo ) {
343-
return clusteringCoefficient(communities, cInfo,true);
336+
float CC = clusteringCoefficient(communities, cInfo,true);
337+
return CC;
344338
}
345339

346340
float clusteringCoefficient( ArrayList<Community> communities, ClusteringInfo cInfo, Boolean countZeros ) {
@@ -389,7 +383,7 @@ void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> communities,
389383
}
390384

391385
float step(int n) {
392-
return 1.0f/(float)n;
386+
return 3.0f/(float)n;
393387
}
394388

395389
boolean improveCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
@@ -402,7 +396,6 @@ boolean improveCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
402396
Community c = filtered.get(index);
403397
float step = step(c.core_.size());
404398
c.p_ = c.p_ + step > 1.0f ? 1.0f : c.p_ + step;
405-
//c.p_ = c.p_ + step_ > 1.0f ? 1.0f : c.p_ + step_;
406399
cInfo.sumProbs+=0.01;
407400
estimateCCCommunity(cInfo, c, c.p_);
408401
return true;
@@ -418,7 +411,6 @@ boolean worsenCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
418411
Community c = filtered.get(index);
419412
float step = step(c.core_.size());
420413
c.p_ = c.p_ - step < min_community_prob_ ? min_community_prob_ : c.p_ - step ;
421-
//c.p_ = c.p_ - step_ < min_community_prob_ ? min_community_prob_ : c.p_ - step_ ;
422414
cInfo.sumProbs-=0.01;
423415
estimateCCCommunity(cInfo, c, c.p_ );
424416
return true;
@@ -443,6 +435,7 @@ void createEdgesCommunityCore(ArrayList<Person> persons, Community c) {
443435

444436
void createEdgesCommunityPeriphery(ClusteringInfo cInfo, ArrayList<Person> persons, Community c) {
445437

438+
//long start = System.currentTimeMillis();
446439
long [] peripheryBudget = new long[c.periphery_.size()];
447440
int index = 0;
448441
for(PersonInfo pI: c.periphery_) {
@@ -470,29 +463,35 @@ void createEdgesCommunityPeriphery(ClusteringInfo cInfo, ArrayList<Person> perso
470463
System.out.println("ERROR");
471464
}
472465
}
466+
//long end = System.currentTimeMillis();
467+
//System.out.println("Time to create core-periphery edges: "+(end-start));
473468
}
474469

475470
void fillGraphWithRemainingEdges(ClusteringInfo cInfo, ArrayList<Community> communities, ArrayList<Person> persons) {
476471
ArrayList<PersonInfo> stubs = new ArrayList<PersonInfo> ();
472+
LinkedList<Integer> indexes = new LinkedList<Integer>();
473+
Integer ii = 0;
477474
for ( Community c : communities ) {
478475
for (PersonInfo pI : c.core_ ) {
479476
long diff = pI.degree_ - persons.get(pI.index_).knows().size();
480477
if( diff > 0 ) {
481478
for( int i = 0; i < diff; ++i) {
482479
stubs.add(pI);
480+
indexes.add(ii++);
483481
}
484482
}
485483
}
486484
}
485+
487486
Collections.shuffle(stubs,rand);
488-
while(stubs.size()>0) {
489-
int index = rand.nextInt(stubs.size());
487+
Collections.shuffle(indexes,rand);
488+
489+
while(indexes.size()>0) {
490+
int index = indexes.pop();
490491
PersonInfo first = stubs.get(index);
491-
stubs.remove(index);
492-
if(stubs.size() > 0) {
493-
int index2 = rand.nextInt(stubs.size());
492+
if(indexes.size() > 0) {
493+
int index2 = indexes.pop();
494494
PersonInfo second = stubs.get(index2);
495-
stubs.remove(index2);
496495
// create edge
497496
if(persons.get(first.index_) == persons.get(second.index_)) {
498497
numMisses++;
@@ -520,18 +519,20 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
520519

521520

522521
for( Community c : communities ) {
522+
c.p_ = 1.0f;
523523
computeCommunityInfo(cInfo, c, 1.0f);
524524
}
525525

526526
for( Community c : communities ) {
527-
estimateCCCommunity(cInfo, c, 1.0f);
527+
c.p_ = 1.0f;
528+
estimateCCCommunity(cInfo, c, c.p_);
528529
}
529530

530531
float maxCC = clusteringCoefficient(communities, cInfo);
531532
System.out.println("maxCC: "+maxCC);
532533

533534
for( Community c : communities ) {
534-
c.p_ = 1.0f;//rand.nextFloat();
535+
c.p_ = 0.5f;//rand.nextFloat();
535536
//c.p_ = rand.nextFloat();
536537
estimateCCCommunity(cInfo, c, c.p_ );
537538
}
@@ -545,11 +546,14 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
545546
iterate = false;
546547
refineCommunities(cInfo, communities, fakeTargetCC);
547548
System.out.println("Creating graph");
549+
550+
long start, end;
548551
for(Community c : communities ) {
549552
createEdgesCommunityCore(persons, c);
550-
createEdgesCommunityPeriphery(cInfo, persons,c);
553+
createEdgesCommunityPeriphery(cInfo, persons, c);
551554
}
552555
fillGraphWithRemainingEdges(cInfo, communities, persons);
556+
553557
graph = new PersonGraph(persons);
554558
System.out.println("Computing clustering coefficient");
555559
double finalCC = 0;

0 commit comments

Comments
 (0)