Search in sources :

Example 1 with JDKRandomGenerator

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");
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) JDKRandomGeneratorFactory(org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) NullValue(org.apache.flink.types.NullValue) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) JDKRandomGenerator(org.apache.commons.math3.random.JDKRandomGenerator) NumberFormat(java.text.NumberFormat)

Example 2 with JDKRandomGenerator

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());
}
Also used : JDKRandomGeneratorFactory(org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Result(org.apache.flink.graph.library.similarity.JaccardIndex.Result) RMatGraph(org.apache.flink.graph.generator.RMatGraph) NullValue(org.apache.flink.types.NullValue) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) LongValue(org.apache.flink.types.LongValue) JDKRandomGenerator(org.apache.commons.math3.random.JDKRandomGenerator) Test(org.junit.Test)

Aggregations

JDKRandomGenerator (org.apache.commons.math3.random.JDKRandomGenerator)2 JDKRandomGeneratorFactory (org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory)2 LongValue (org.apache.flink.types.LongValue)2 NullValue (org.apache.flink.types.NullValue)2 NumberFormat (java.text.NumberFormat)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)1 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)1 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)1 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)1 RMatGraph (org.apache.flink.graph.generator.RMatGraph)1 Result (org.apache.flink.graph.library.similarity.JaccardIndex.Result)1 Test (org.junit.Test)1