use of org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement in project gradoop by dbs-leipzig.
the class CentroidFRLayouter method execute.
@Override
public LogicalGraph execute(LogicalGraph g) {
g = createInitialLayout(g);
DataSet<EPGMVertex> gradoopVertices = g.getVertices();
DataSet<EPGMEdge> gradoopEdges = g.getEdges();
DataSet<LVertex> vertices = gradoopVertices.map(LVertex::new);
DataSet<LEdge> edges = gradoopEdges.map(LEdge::new);
centroids = chooseInitialCentroids(vertices);
// flink can only iterate over one dataset at once. Create a dataset containing both
// centroids and vertices. Split them again at the begin of every iteration
DataSet<SimpleGraphElement> graphElements = vertices.map(x -> x);
graphElements = graphElements.union(centroids.map(x -> x));
IterativeDataSet<SimpleGraphElement> loop = graphElements.iterate(iterations);
vertices = loop.filter(x -> x instanceof LVertex).map(x -> (LVertex) x);
centroids = loop.filter(x -> x instanceof Centroid).map(x -> (Centroid) x);
centroids = calculateNewCentroids(centroids, vertices);
center = calculateLayoutCenter(vertices);
LGraph graph = new LGraph(vertices, edges);
// we have overridden repulsionForces() so layout() will use or new centroid-based solution
layout(graph);
graphElements = graph.getVertices().map(x -> x);
graphElements = graphElements.union(centroids.map(x -> x));
graphElements = loop.closeWith(graphElements);
vertices = graphElements.filter(x -> x instanceof LVertex).map(x -> (LVertex) x);
gradoopVertices = vertices.join(gradoopVertices).where(LVertex.ID_POSITION).equalTo(new Id<>()).with(new LVertexEPGMVertexJoinFunction());
return g.getFactory().fromDataSets(gradoopVertices, gradoopEdges);
}
use of org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement in project gradoop by dbs-leipzig.
the class FusingFRLayouter method execute.
@Override
public LogicalGraph execute(LogicalGraph g) {
applicator = new FRForceApplicator(getWidth(), getHeight(), getK(), (outputFormat != OutputFormat.POSTLAYOUT) ? iterations : iterations - POST_ITERATIONS);
g = createInitialLayout(g);
DataSet<EPGMVertex> gradoopVertices = g.getVertices();
DataSet<EPGMEdge> gradoopEdges = g.getEdges();
// Flink can only iterate over a single dataset. Therefore vertices and edges have to be
// temporarily combined into a single dataset.
// Also the Grapdoop datatypes are converted to internal datatypes
DataSet<SimpleGraphElement> tmpvertices = gradoopVertices.map((v) -> new LVertex(v));
DataSet<SimpleGraphElement> tmpedges = gradoopEdges.map((e) -> new LEdge(e));
DataSet<SimpleGraphElement> graphElements = tmpvertices.union(tmpedges);
IterativeDataSet<SimpleGraphElement> loop = graphElements.iterate((outputFormat != OutputFormat.POSTLAYOUT) ? iterations : iterations - POST_ITERATIONS);
// split the combined dataset to work with the edges and vertices
LGraph graph = new LGraph(loop);
// perform the layouting
layout(graph);
// Use the VertexFusor to create a simplified version of the graph
graph = new VertexFusor(getCompareFunction(), threshold).execute(graph);
// again, combine vertices and edges into a single dataset to perform iterations
graphElements = graph.getGraphElements();
graphElements = loop.closeWith(graphElements);
// again, split the combined dataset (after all iterations have been completed)
graph = new LGraph(graphElements);
switch(outputFormat) {
case SIMPLIFIED:
return buildSimplifiedGraph(g, graph);
case EXTRACTED:
return buildExtractedGraph(g, graph, true);
case RAWEXTRACTED:
return buildExtractedGraph(g, graph, false);
case POSTLAYOUT:
return buildPostLayoutGraph(g, graph);
default:
throw new IllegalArgumentException("Unsupported output-format");
}
}
Aggregations