Search in sources :

Example 1 with LongValueSequenceIterator

use of org.apache.flink.util.LongValueSequenceIterator in project flink by apache.

the class CompleteGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    // Vertices
    DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
    // Edges
    LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, this.vertexCount - 1);
    DataSet<Edge<LongValue, NullValue>> edges = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Edge iterators").flatMap(new LinkVertexToAll(vertexCount)).setParallelism(parallelism).name("Complete graph edges");
    // Graph
    return Graph.fromDataSet(vertices, edges, env);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 2 with LongValueSequenceIterator

use of org.apache.flink.util.LongValueSequenceIterator in project flink by apache.

the class GraphGeneratorUtils method vertexSequence.

/**
 * Generates {@link Vertex Vertices} with sequential, numerical labels.
 *
 * @param env the Flink execution environment.
 * @param parallelism operator parallelism
 * @param vertexCount number of sequential vertex labels
 * @return {@link DataSet} of sequentially labeled {@link Vertex vertices}
 */
public static DataSet<Vertex<LongValue, NullValue>> vertexSequence(ExecutionEnvironment env, int parallelism, long vertexCount) {
    Preconditions.checkArgument(vertexCount >= 0, "Vertex count must be non-negative");
    if (vertexCount == 0) {
        return env.fromCollection(Collections.emptyList(), TypeInformation.of(new TypeHint<Vertex<LongValue, NullValue>>() {
        })).setParallelism(parallelism).name("Empty vertex set");
    } else {
        LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, vertexCount - 1);
        DataSource<LongValue> vertexLabels = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Vertex indices");
        return vertexLabels.map(new CreateVertex()).setParallelism(parallelism).name("Vertex sequence");
    }
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) NullValue(org.apache.flink.types.NullValue) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) LongValue(org.apache.flink.types.LongValue)

Example 3 with LongValueSequenceIterator

use of org.apache.flink.util.LongValueSequenceIterator in project flink by apache.

the class CirculantGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    // Vertices
    DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
    // Edges
    LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, this.vertexCount - 1);
    // Validate ranges
    Collections.sort(offsetRanges);
    Iterator<OffsetRange> iter = offsetRanges.iterator();
    OffsetRange lastRange = iter.next();
    while (iter.hasNext()) {
        OffsetRange nextRange = iter.next();
        if (lastRange.overlaps(nextRange)) {
            throw new IllegalArgumentException("Overlapping ranges " + lastRange + " and " + nextRange);
        }
        lastRange = nextRange;
    }
    DataSet<Edge<LongValue, NullValue>> edges = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Edge iterators").flatMap(new LinkVertexToOffsets(vertexCount, offsetRanges)).setParallelism(parallelism).name("Circulant graph edges");
    // Graph
    return Graph.fromDataSet(vertices, edges, env);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 4 with LongValueSequenceIterator

use of org.apache.flink.util.LongValueSequenceIterator in project flink by apache.

the class GridGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    Preconditions.checkState(!dimensions.isEmpty(), "No dimensions added to GridGraph");
    // Vertices
    DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
    // Edges
    LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, this.vertexCount - 1);
    DataSet<Edge<LongValue, NullValue>> edges = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Edge iterators").flatMap(new LinkVertexToNeighbors(vertexCount, dimensions)).setParallelism(parallelism).name("Grid graph edges");
    // Graph
    return Graph.fromDataSet(vertices, edges, env);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 5 with LongValueSequenceIterator

use of org.apache.flink.util.LongValueSequenceIterator in project flink by apache.

the class SingletonEdgeGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    Preconditions.checkState(vertexPairCount > 0);
    // Vertices
    long vertexCount = 2 * vertexPairCount;
    DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
    // Edges
    LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, vertexCount - 1);
    DataSet<Edge<LongValue, NullValue>> edges = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Edge iterators").map(new LinkVertexToSingletonNeighbor()).setParallelism(parallelism).name("Complete graph edges");
    // Graph
    return Graph.fromDataSet(vertices, edges, env);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Aggregations

LongValue (org.apache.flink.types.LongValue)6 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)6 Edge (org.apache.flink.graph.Edge)5 Vertex (org.apache.flink.graph.Vertex)5 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)1 NullValue (org.apache.flink.types.NullValue)1