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);
}
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");
}
}
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);
}
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);
}
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);
}
Aggregations