Search in sources :

Example 1 with LEdge

use of org.gradoop.flink.model.impl.operators.layouting.util.LEdge in project gradoop by dbs-leipzig.

the class VertexFusorTest method testCandidateGenerator.

@Test
public void testCandidateGenerator() throws Exception {
    LEdge dummyEdge = new LEdge();
    Tuple2<LEdge, Tuple2<LVertex, Boolean>> source = new Tuple2<>(dummyEdge, new Tuple2<>());
    Tuple2<LVertex, Boolean> target = new Tuple2<>();
    List<Tuple3<LVertex, LVertex, Double>> collectorList = new ArrayList<>();
    ListCollector<Tuple3<LVertex, LVertex, Double>> collector = new ListCollector<>(collectorList);
    VertexFusor.CandidateGenerator gen = new VertexFusor.CandidateGenerator(null, 0.5);
    source.f1.f1 = true;
    target.f1 = true;
    gen.join(source, target, collector);
    Assert.assertEquals(0, collectorList.size());
    source.f1.f1 = false;
    target.f1 = false;
    gen.join(source, target, collector);
    Assert.assertEquals(0, collectorList.size());
    source.f1.f1 = true;
    source.f1.f0 = new LVertex();
    target.f1 = false;
    target.f0 = new LVertex();
    gen.cf = (a, b) -> 0.6;
    gen.join(source, target, collector);
    Assert.assertEquals(1, collectorList.size());
    Assert.assertEquals(0.6, (double) collectorList.get(0).f2, 0.0000001);
    Assert.assertEquals(source.f1.f0, collectorList.get(0).f1);
    collectorList.clear();
    source.f1.f1 = false;
    target.f1 = true;
    gen.join(source, target, collector);
    Assert.assertEquals(1, collectorList.size());
    Assert.assertEquals(0.6, (double) collectorList.get(0).f2, 0.0000001);
    Assert.assertEquals(target.f0, collectorList.get(0).f1);
    collectorList.clear();
    gen.cf = (a, b) -> 0.4;
    gen.join(source, target, collector);
    Assert.assertEquals(0, collectorList.size());
}
Also used : LEdge(org.gradoop.flink.model.impl.operators.layouting.util.LEdge) ArrayList(java.util.ArrayList) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) ListCollector(org.apache.flink.api.common.functions.util.ListCollector) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 2 with LEdge

use of org.gradoop.flink.model.impl.operators.layouting.util.LEdge in project gradoop by dbs-leipzig.

the class FRLayouter 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((v) -> new LVertex(v));
    DataSet<LEdge> edges = gradoopEdges.map((e) -> new LEdge(e));
    IterativeDataSet<LVertex> loop = vertices.iterate(iterations);
    LGraph graph = new LGraph(loop, edges);
    layout(graph);
    vertices = loop.closeWith(graph.getVertices());
    gradoopVertices = vertices.join(gradoopVertices).where(LVertex.ID_POSITION).equalTo("id").with(new LVertexEPGMVertexJoinFunction());
    return g.getFactory().fromDataSets(gradoopVertices, gradoopEdges);
}
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) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) LGraph(org.gradoop.flink.model.impl.operators.layouting.util.LGraph) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex)

Example 3 with LEdge

use of org.gradoop.flink.model.impl.operators.layouting.util.LEdge 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);
}
Also used : CentroidUpdater(org.gradoop.flink.model.impl.operators.layouting.functions.CentroidUpdater) LGraph(org.gradoop.flink.model.impl.operators.layouting.util.LGraph) LVertexEPGMVertexJoinFunction(org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) IterativeDataSet(org.apache.flink.api.java.operators.IterativeDataSet) CentroidRepulsionForceMapper(org.gradoop.flink.model.impl.operators.layouting.functions.CentroidRepulsionForceMapper) FRRepulsionFunction(org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction) Centroid(org.gradoop.flink.model.impl.operators.layouting.util.Centroid) Id(org.gradoop.flink.model.impl.functions.epgm.Id) SimpleGraphElement(org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement) AverageVertexPositionsFunction(org.gradoop.flink.model.impl.operators.layouting.functions.AverageVertexPositionsFunction) DataSet(org.apache.flink.api.java.DataSet) Vector(org.gradoop.flink.model.impl.operators.layouting.util.Vector) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) LEdge(org.gradoop.flink.model.impl.operators.layouting.util.LEdge) Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) LogicalGraph(org.gradoop.flink.model.impl.epgm.LogicalGraph) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) 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) Centroid(org.gradoop.flink.model.impl.operators.layouting.util.Centroid) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) LVertexEPGMVertexJoinFunction(org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction)

Example 4 with LEdge

use of org.gradoop.flink.model.impl.operators.layouting.util.LEdge 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 5 with LEdge

use of org.gradoop.flink.model.impl.operators.layouting.util.LEdge 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

LEdge (org.gradoop.flink.model.impl.operators.layouting.util.LEdge)5 LVertex (org.gradoop.flink.model.impl.operators.layouting.util.LVertex)5 EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)4 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)3 LVertexEPGMVertexJoinFunction (org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction)3 LGraph (org.gradoop.flink.model.impl.operators.layouting.util.LGraph)3 FRForceApplicator (org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator)2 SimpleGraphElement (org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement)2 ArrayList (java.util.ArrayList)1 ListCollector (org.apache.flink.api.common.functions.util.ListCollector)1 DataSet (org.apache.flink.api.java.DataSet)1 IterativeDataSet (org.apache.flink.api.java.operators.IterativeDataSet)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)1 LogicalGraph (org.gradoop.flink.model.impl.epgm.LogicalGraph)1 Id (org.gradoop.flink.model.impl.functions.epgm.Id)1 AverageVertexPositionsFunction (org.gradoop.flink.model.impl.operators.layouting.functions.AverageVertexPositionsFunction)1 CentroidRepulsionForceMapper (org.gradoop.flink.model.impl.operators.layouting.functions.CentroidRepulsionForceMapper)1 CentroidUpdater (org.gradoop.flink.model.impl.operators.layouting.functions.CentroidUpdater)1 FRRepulsionFunction (org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction)1