use of org.apache.commons.math3.random.JDKRandomGenerator in project flink by apache.
the class Graph500 method main.
public static void main(String[] args) throws Exception {
// Set up the execution environment
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.getConfig().enableObjectReuse();
ParameterTool parameters = ParameterTool.fromArgs(args);
env.getConfig().setGlobalJobParameters(parameters);
if (!parameters.has("directed")) {
throw new ProgramParametrizationException(getUsage("must declare execution mode as '--directed true' or '--directed false'"));
}
boolean directed = parameters.getBoolean("directed");
if (!parameters.has("simplify")) {
throw new ProgramParametrizationException(getUsage("must declare '--simplify true' or '--simplify false'"));
}
boolean simplify = parameters.getBoolean("simplify");
// Generate RMat graph
int scale = parameters.getInt("scale", DEFAULT_SCALE);
int edgeFactor = parameters.getInt("edge_factor", DEFAULT_EDGE_FACTOR);
RandomGenerableFactory<JDKRandomGenerator> rnd = new JDKRandomGeneratorFactory();
long vertexCount = 1L << scale;
long edgeCount = vertexCount * edgeFactor;
boolean clipAndFlip = parameters.getBoolean("clip_and_flip", DEFAULT_CLIP_AND_FLIP);
Graph<LongValue, NullValue, NullValue> graph = new RMatGraph<>(env, rnd, vertexCount, edgeCount).generate();
if (directed) {
if (simplify) {
graph = graph.run(new org.apache.flink.graph.asm.simple.directed.Simplify<LongValue, NullValue, NullValue>());
}
} else {
if (simplify) {
graph = graph.run(new org.apache.flink.graph.asm.simple.undirected.Simplify<LongValue, NullValue, NullValue>(clipAndFlip));
} else {
graph = graph.getUndirected();
}
}
DataSet<Tuple2<LongValue, LongValue>> edges = graph.getEdges().project(0, 1);
// Print, hash, or write RMat graph to disk
switch(parameters.get("output", "")) {
case "print":
System.out.println();
edges.print();
break;
case "hash":
System.out.println();
System.out.println(DataSetUtils.checksumHashCode(edges));
break;
case "csv":
String filename = parameters.getRequired("output_filename");
String lineDelimiter = StringEscapeUtils.unescapeJava(parameters.get("output_line_delimiter", CsvOutputFormat.DEFAULT_LINE_DELIMITER));
String fieldDelimiter = StringEscapeUtils.unescapeJava(parameters.get("output_field_delimiter", CsvOutputFormat.DEFAULT_FIELD_DELIMITER));
edges.writeAsCsv(filename, lineDelimiter, fieldDelimiter);
env.execute("Graph500");
break;
default:
throw new ProgramParametrizationException(getUsage("invalid output type"));
}
JobExecutionResult result = env.getLastJobExecutionResult();
NumberFormat nf = NumberFormat.getInstance();
System.out.println();
System.out.println("Execution runtime: " + nf.format(result.getNetRuntime()) + " ms");
}
use of org.apache.commons.math3.random.JDKRandomGenerator in project flink by apache.
the class JaccardIndexTest method testRMatGraph.
@Test
public void testRMatGraph() throws Exception {
long vertexCount = 1 << 8;
long edgeCount = 8 * vertexCount;
RandomGenerableFactory<JDKRandomGenerator> rnd = new JDKRandomGeneratorFactory();
Graph<LongValue, NullValue, NullValue> graph = new RMatGraph<>(env, rnd, vertexCount, edgeCount).generate().run(new Simplify<LongValue, NullValue, NullValue>(false));
DataSet<Result<LongValue>> ji = graph.run(new JaccardIndex<LongValue, NullValue, NullValue>().setGroupSize(4));
Checksum checksum = new ChecksumHashCode<Result<LongValue>>().run(ji).execute();
assertEquals(13954, checksum.getCount());
assertEquals(0x00001b1a1f7a9d0bL, checksum.getChecksum());
}
Aggregations