Search in sources :

Example 1 with FRForceApplicator

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);
}
Also used : FRForceApplicator(org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator)

Example 2 with FRForceApplicator

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");
    }
}
Also used : LEdge(org.gradoop.flink.model.impl.operators.layouting.util.LEdge) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) SimpleGraphElement(org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement) LGraph(org.gradoop.flink.model.impl.operators.layouting.util.LGraph) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) VertexFusor(org.gradoop.flink.model.impl.operators.layouting.functions.VertexFusor) FRForceApplicator(org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator)

Example 3 with FRForceApplicator

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());
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) LVertexEPGMVertexJoinFunction(org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction) LEdge(org.gradoop.flink.model.impl.operators.layouting.util.LEdge) LVertexFlattener(org.gradoop.flink.model.impl.operators.layouting.functions.LVertexFlattener) FRForceApplicator(org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex)

Aggregations

FRForceApplicator (org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator)3 EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)2 LEdge (org.gradoop.flink.model.impl.operators.layouting.util.LEdge)2 LVertex (org.gradoop.flink.model.impl.operators.layouting.util.LVertex)2 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)1 LVertexEPGMVertexJoinFunction (org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction)1 LVertexFlattener (org.gradoop.flink.model.impl.operators.layouting.functions.LVertexFlattener)1 VertexFusor (org.gradoop.flink.model.impl.operators.layouting.functions.VertexFusor)1 LGraph (org.gradoop.flink.model.impl.operators.layouting.util.LGraph)1 SimpleGraphElement (org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement)1