use of org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator in project gradoop by dbs-leipzig.
the class FRLayouter method applyForces.
/**
* Applies the given forces to the given vertices.
*
* @param vertices Vertices to move
* @param forces Forces to apply. At most one per vertex. The id indicates which vertex
* the force should be applied to
* @param iterations Number of iterations that will be performed (NOT the number of the
* current iteration). It is used to compute the simulated annealing shedule.
* @return The input vertices with x and y coordinated changed according to the given force and
* current iteration number.
*/
protected DataSet<LVertex> applyForces(DataSet<LVertex> vertices, DataSet<Force> forces, int iterations) {
FRForceApplicator applicator = new FRForceApplicator(getWidth(), getHeight(), getK(), iterations);
applicator.setPreviousIterations(startAtIteration);
return vertices.join(forces).where(LVertex.ID_POSITION).equalTo(Force.ID_POSITION).with(applicator);
}
use of org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator 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");
}
}
use of org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator in project gradoop by dbs-leipzig.
the class FusingFRLayouter method buildPostLayoutGraph.
/**
* Extract all subverties/subedges from the super-vertices/super-edges and place them at the
* location of the super-vertex (and add some random jitter to the positions).
* Then some more layouting-iteraions are performed.
*
* @param input Original input graph
* @param graph Result of the layouting
* @return The final graph, containing all vertices and edges from the original graph.
*/
protected LogicalGraph buildPostLayoutGraph(LogicalGraph input, LGraph graph) {
DataSet<LVertex> vertices = graph.getVertices().flatMap(new LVertexFlattener(true, getK()));
DataSet<LEdge> edges = input.getEdges().map(LEdge::new);
graph.setEdges(edges);
// use a new applicator for all following layouting iterations. The new applicator will
// behave as if iteration x of n is actually iterations+x of n+POST_ITERATIONS
applicator = new FRForceApplicator(getWidth(), getHeight(), getK(), iterations + POST_ITERATIONS);
applicator.setPreviousIterations(iterations);
// do some more layouting iterations
IterativeDataSet<LVertex> loop = vertices.iterate(POST_ITERATIONS);
graph.setVertices(loop);
layout(graph);
vertices = loop.closeWith(graph.getVertices());
DataSet<EPGMVertex> gradoopVertices = vertices.join(input.getVertices()).where(LVertex.ID_POSITION).equalTo("id").with(new LVertexEPGMVertexJoinFunction());
return input.getFactory().fromDataSets(gradoopVertices, input.getEdges());
}
Aggregations