|
36 | 36 | */
|
37 | 37 | package ldbc.snb.datagen.objects;
|
38 | 38 |
|
| 39 | +import ldbc.snb.datagen.dictionary.Dictionaries; |
| 40 | +import ldbc.snb.datagen.generator.DatagenParams; |
| 41 | +import ldbc.snb.datagen.util.RandomGeneratorFarm; |
39 | 42 | import org.apache.hadoop.io.Writable;
|
40 | 43 |
|
41 | 44 | import java.io.DataInput;
|
42 | 45 | import java.io.DataOutput;
|
43 | 46 | import java.io.IOException;
|
44 |
| - |
| 47 | +import java.util.ArrayList; |
| 48 | +import java.util.Comparator; |
| 49 | +import java.util.Random; |
45 | 50 |
|
46 | 51 |
|
47 | 52 | public class Knows implements Writable, Comparable<Knows> {
|
@@ -103,11 +108,55 @@ public void write(DataOutput arg0) throws IOException {
|
103 | 108 | }
|
104 | 109 |
|
105 | 110 | 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(); |
109 | 115 | if( res2 > 0 ) return 1;
|
110 | 116 | if( res2 < 0 ) return -1;
|
| 117 | + */ |
111 | 118 | return 0;
|
112 | 119 | }
|
| 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 | + } |
113 | 162 | }
|
0 commit comments