/*
* Copyright (c) 2013 LDBC
* Linked Data Benchmark Council (http://ldbc.eu)
*
* This file is part of ldbc_socialnet_dbgen.
*
* ldbc_socialnet_dbgen is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ldbc_socialnet_dbgen is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ldbc_socialnet_dbgen. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2011 OpenLink Software <bdsmt@openlinksw.com>
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; only Version 2 of the License dated
* June 1991.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package ldbc.snb.datagen.generator.distribution;
import ldbc.snb.datagen.generator.DatagenParams;
import ldbc.snb.datagen.generator.distribution.utils.Bucket;
import ldbc.snb.datagen.generator.distribution.utils.BucketedDistribution;
import org.apache.hadoop.conf.Configuration;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Random;
/**
* This class generates Facebook-like social degree distribution
* <p/>
* A. Preparation
* For a specific social network size (total number of users)
* 1) compute the mean value of social degree
* 2) compute the range of each bucket (100 buckets) using the data from facebookBucket100.dat
* B. Generate social degree for each user
* 1) Determine the bucket (Take a random number from 0-99)
* 2) Randomly select a social degree in the range of that bucket
*/
public class FacebookDegreeDistribution extends BucketedDistribution {
private int mean_ = 0;
private static final int FB_MEAN_ = 190;
private static final int BUCKET_NUM_ = 100;
private ArrayList<Bucket> buckets_;
public FacebookDegreeDistribution() {
}
@Override
public ArrayList<Bucket> getBuckets(Configuration conf) {
mean_ = (int) Math.round(Math.pow(DatagenParams.numPersons, (0.512 - 0.028 * Math.log10(DatagenParams.numPersons))));
System.out.println("Mean = " + mean_);
buckets_ = new ArrayList<Bucket>();
loadFBBuckets();
rebuildBucketRange();
return buckets_;
}
public void loadFBBuckets() {
try {
BufferedReader fbDataReader = new BufferedReader(
new InputStreamReader(getClass().getResourceAsStream(DatagenParams.fbSocialDegreeFile), "UTF-8"));
String line;
while ((line = fbDataReader.readLine()) != null) {
String data[] = line.split(" ");
buckets_.add(new Bucket(Float.parseFloat(data[0]), Float.parseFloat(data[1])));
}
fbDataReader.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public void rebuildBucketRange() {
double newMin, newMax;
for (int i = 0; i < buckets_.size(); i++) {
newMin = buckets_.get(i).min() * mean_ / FB_MEAN_;
newMax = buckets_.get(i).max() * mean_ / FB_MEAN_;
if (newMax < newMin) newMax = newMin;
buckets_.get(i).min(newMin);
buckets_.get(i).max(newMax);
}
}
}