Skip to content

Commit 1080ec9

Browse files
committed
Merge branch 'new_execution_flow'
2 parents 8029951 + 43d521e commit 1080ec9

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

params.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ ldbc.snb.datagen.serializer.personActivitySerializer:ldbc.snb.datagen.serializer
1111

1212
ldbc.snb.datagen.generator.numThreads:1
1313

14-
ldbc.snb.datagen.serializer.updateStreams:true
14+
1515

src/main/java/ldbc/snb/datagen/hadoop/HadoopMergeFriendshipFiles.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ldbc.snb.datagen.hadoop;
22

3-
import ldbc.snb.datagen.generator.KnowsGenerator;
43
import ldbc.snb.datagen.generator.LDBCDatagen;
54
import ldbc.snb.datagen.objects.Knows;
5+
import ldbc.snb.datagen.objects.Knows.FullComparator;
66
import ldbc.snb.datagen.objects.Person;
77
import org.apache.hadoop.conf.Configuration;
88
import org.apache.hadoop.fs.Path;
@@ -15,16 +15,19 @@
1515

1616
import java.io.IOException;
1717
import java.util.ArrayList;
18+
import java.util.Collections;
1819

1920
/**
2021
* Created by aprat on 29/07/15.
2122
*/
2223
public class HadoopMergeFriendshipFiles {
2324

25+
2426
public static class HadoopMergeFriendshipFilesReducer extends Reducer<TupleKey, Person, TupleKey, Person> {
2527

2628
private Configuration conf;
2729
private HadoopFileKeyChanger.KeySetter<TupleKey> keySetter = null;
30+
private int numRepeated = 0;
2831

2932
protected void setup(Context context) {
3033
this.conf = context.getConfiguration();
@@ -40,21 +43,41 @@ protected void setup(Context context) {
4043
public void reduce(TupleKey key, Iterable<Person> valueSet,Context context)
4144
throws IOException, InterruptedException {
4245

46+
ArrayList<Knows> knows = new ArrayList<Knows>();
4347
Person person = null;
4448
int index = 0;
4549
for ( Person p : valueSet) {
4650
if( index == 0 ) {
4751
person = new Person(p);
48-
} else {
49-
for ( Knows k : p.knows() ) {
50-
person.knows().add(k);
51-
}
52+
}
53+
for(Knows k : p.knows()) {
54+
knows.add(k);
5255
}
5356
index++;
5457
}
58+
person.knows().clear();
59+
Knows.FullComparator comparator = new Knows.FullComparator();
60+
Collections.sort(knows, comparator);
61+
if(knows.size() > 0 ) {
62+
long currentTo = knows.get(0).to().accountId();
63+
person.knows().add(knows.get(0));
64+
for (index = 1; index < knows.size(); ++index) {
65+
Knows nextKnows = knows.get(index);
66+
if(currentTo != knows.get(index).to().accountId()) {
67+
person.knows().add(nextKnows);
68+
currentTo = nextKnows.to().accountId();
69+
} else {
70+
numRepeated++;
71+
}
72+
}
73+
}
74+
5575
//System.out.println("Num persons "+index);
5676
context.write(keySetter.getKey(person),person);
5777
}
78+
protected void cleanup(Context context){
79+
System.out.println("Number of repeated edges: "+numRepeated);
80+
}
5881
}
5982

6083
private Configuration conf;

src/main/java/ldbc/snb/datagen/objects/Knows.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@
3636
*/
3737
package ldbc.snb.datagen.objects;
3838

39+
import ldbc.snb.datagen.dictionary.Dictionaries;
40+
import ldbc.snb.datagen.generator.DatagenParams;
41+
import ldbc.snb.datagen.util.RandomGeneratorFarm;
3942
import org.apache.hadoop.io.Writable;
4043

4144
import java.io.DataInput;
4245
import java.io.DataOutput;
4346
import java.io.IOException;
44-
47+
import java.util.ArrayList;
48+
import java.util.Comparator;
49+
import java.util.Random;
4550

4651

4752
public class Knows implements Writable, Comparable<Knows> {
@@ -103,11 +108,55 @@ public void write(DataOutput arg0) throws IOException {
103108
}
104109

105110
public int compareTo(Knows k) {
106-
int res = (int)(to_.accountId() - k.to().accountId());
107-
if( res != 0 ) return res;
108-
long res2 = creationDate_ - k.creationDate();
111+
long res = (to_.accountId() - k.to().accountId());
112+
if( res > 0 ) return 1;
113+
if( res < 0 ) return -1;
114+
/*long res2 = creationDate_ - k.creationDate();
109115
if( res2 > 0 ) return 1;
110116
if( res2 < 0 ) return -1;
117+
*/
111118
return 0;
112119
}
120+
121+
static public class FullComparator implements Comparator<Knows> {
122+
123+
public int compare(Knows a, Knows b) {
124+
long res = (a.to_.accountId() - b.to().accountId());
125+
if( res > 0 ) return 1;
126+
if( res < 0 ) return -1;
127+
long res2 = a.creationDate_ - b.creationDate();
128+
if( res2 > 0 ) return 1;
129+
if( res2 < 0 ) return -1;
130+
return 0;
131+
}
132+
133+
}
134+
135+
public static int num = 0;
136+
137+
public static boolean createKnow( Random random, Person personA, Person personB ) {
138+
long creationDate = Dictionaries.dates.randomKnowsCreationDate(
139+
random,
140+
personA,
141+
personB);
142+
creationDate = creationDate - personA.creationDate() >= DatagenParams.deltaTime ? creationDate : creationDate + (DatagenParams.deltaTime - (creationDate - personA.creationDate()));
143+
creationDate = creationDate - personB.creationDate() >= DatagenParams.deltaTime ? creationDate : creationDate + (DatagenParams.deltaTime - (creationDate - personB.creationDate()));
144+
if( creationDate <= Dictionaries.dates.getEndDateTime() ) {
145+
float similarity = Person.Similarity(personA,personB);
146+
if(!personB.knows().add(new Knows(personA, creationDate, similarity))) return false;
147+
if(!personA.knows().add(new Knows(personB, creationDate, similarity))) return false;
148+
return true;
149+
}
150+
return false;
151+
}
152+
153+
public static long target_edges(Person person, ArrayList<Float> percentages, int step_index ) {
154+
int generated_edges = 0;
155+
for (int i = 0; i < step_index; ++i) {
156+
generated_edges += Math.ceil(percentages.get(i)*person.maxNumKnows());
157+
}
158+
generated_edges = Math.min(generated_edges, (int)person.maxNumKnows());
159+
int to_generate = Math.min( (int)person.maxNumKnows() - generated_edges, (int)Math.ceil(percentages.get(step_index)*person.maxNumKnows()));
160+
return to_generate;
161+
}
113162
}

0 commit comments

Comments
 (0)