Search in sources :

Example 1 with LVertex

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

the class FRForceApplicatorTest method testForceApplicator.

@Test
public void testForceApplicator() {
    FRForceApplicator fa = new FRForceApplicator(1000, 1000, 10, 25);
    Assert.assertEquals(707.1, fa.speedForIteration(0), 0.1);
    Assert.assertEquals(537.96, fa.speedForIteration(1), 0.1);
    Assert.assertEquals(1.0, fa.speedForIteration(24), 0.1);
    Vector pos = new Vector(950, 0);
    LVertex v = new LVertex();
    v.setPosition(pos);
    Force force = new Force(null, new Vector(0, 300));
    fa.apply(v, force, 200);
    Assert.assertEquals(pos, new Vector(950, 200));
    Force force2 = new Force(null, new Vector(1000, 1000));
    fa.apply(v, force2, 10000);
    Assert.assertEquals(pos, new Vector(999, 999));
    v.addSubVertex(GradoopId.get());
    v.setPosition(new Vector(100, 100));
    Force force3 = new Force(null, new Vector(50, 50));
    fa.apply(v, force3, 10000);
    Assert.assertEquals(new Vector(125, 125), v.getPosition());
    Assert.assertEquals(new Vector(50, 50), v.getForce());
}
Also used : Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) Vector(org.gradoop.flink.model.impl.operators.layouting.util.Vector) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) Test(org.junit.Test)

Example 2 with LVertex

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

the class FRRepulsionFunctionTest method testRepulseJoinFunction.

@Test
public void testRepulseJoinFunction() throws Exception {
    JoinFunction<LVertex, LVertex, Force> jf = new FRRepulsionFunction(1, 20);
    LVertex v1 = getDummyVertex(1, 1);
    LVertex v2 = getDummyVertex(2, 3);
    LVertex v3 = getDummyVertex(7, 5);
    LVertex v4 = getDummyVertex(1, 1);
    LVertex v5 = getDummyVertex(30, 30);
    Vector vec12 = jf.join(v1, v2).getValue().copy();
    Vector vec13 = jf.join(v1, v3).getValue().copy();
    Vector vec14 = jf.join(v1, v4).getValue().copy();
    Vector vec11 = jf.join(v1, v1).getValue().copy();
    Vector vec15 = jf.join(v1, v5).getValue().copy();
    Assert.assertTrue(vec12.getX() < 0 && vec12.getY() < 0);
    Assert.assertTrue(vec12.magnitude() > vec13.magnitude());
    Assert.assertTrue(vec14.magnitude() > 0);
    Assert.assertTrue(vec11.magnitude() == 0);
    Assert.assertTrue(vec15.magnitude() == 0);
}
Also used : Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) Vector(org.gradoop.flink.model.impl.operators.layouting.util.Vector) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) Test(org.junit.Test)

Example 3 with LVertex

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

the class FRRepulsionFunctionTest method testRepulseFlatJoin.

@Test
public void testRepulseFlatJoin() throws Exception {
    FRRepulsionFunction jf = new FRRepulsionFunction(1);
    LVertex v1 = getDummyVertex(1, 1);
    LVertex v2 = getDummyVertex(2, 3);
    Vector vec12join = jf.join(v1, v2).getValue().copy();
    v1 = getDummyVertex(1, 1);
    v2 = getDummyVertex(2, 3);
    List<Force> collectorList = new ArrayList<>();
    ListCollector<Force> collector = new ListCollector<>(collectorList);
    jf.join(v1, v2, collector);
    Vector vec12 = collectorList.get(0).getValue().copy();
    Vector vec21 = collectorList.get(1).getValue().copy();
    v1 = getDummyVertex(1, 1);
    v2 = getDummyVertex(2, 3);
    v1.setSubVertices(generateSubVertices(1));
    v2.setSubVertices(generateSubVertices(2));
    Vector vec12joinf6 = jf.join(v1, v2).getValue().copy();
    Assert.assertEquals(vec12join, vec12);
    Assert.assertEquals(vec12, vec21.mul(-1));
    Assert.assertNotEquals(collectorList.get(0).getId(), collectorList.get(1).getId());
    Assert.assertEquals(vec12join.mul(6), vec12joinf6);
}
Also used : ListCollector(org.apache.flink.api.common.functions.util.ListCollector) Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) ArrayList(java.util.ArrayList) Vector(org.gradoop.flink.model.impl.operators.layouting.util.Vector) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) Test(org.junit.Test)

Example 4 with LVertex

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

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

the class VertexFusorTest method testSuperVertexGenerator.

@Test
public void testSuperVertexGenerator() throws Exception {
    VertexFusor.SuperVertexGenerator gen = new VertexFusor.SuperVertexGenerator();
    LVertex receiver = new LVertex(GradoopId.get(), new Vector(10, 10), -1, generateSubVertices(4), new Vector(10, 10));
    LVertex donor1 = new LVertex(GradoopId.get(), new Vector(100, 100), -1, null, new Vector(10, 10));
    LVertex donor2 = new LVertex(GradoopId.get(), new Vector(1000, 1000), -1, generateSubVertices(2), new Vector(10, 10));
    LVertex donor3 = new LVertex(GradoopId.get(), new Vector(10000, 10000), -1, null, new Vector(10, 10));
    List<Tuple2<LVertex, LVertex>> vertices = new ArrayList<>();
    vertices.add(new Tuple2<>(donor1, receiver));
    vertices.add(new Tuple2<>(donor2, receiver));
    vertices.add(new Tuple2<>(donor3, receiver));
    List<LVertex> collectorList = new ArrayList<>();
    ListCollector<LVertex> collector = new ListCollector<>(collectorList);
    Vector expectedPosition = receiver.getPosition().mul(5).add(donor1.getPosition()).add(donor2.getPosition().mul(3)).add(donor3.getPosition()).div(10);
    gen.reduce(vertices, collector);
    Assert.assertEquals(1, collectorList.size());
    LVertex superVertex = collectorList.get(0);
    Assert.assertEquals(receiver.getId(), superVertex.getId());
    Assert.assertEquals(10, superVertex.getCount());
    Assert.assertEquals(expectedPosition, superVertex.getPosition());
}
Also used : ListCollector(org.apache.flink.api.common.functions.util.ListCollector) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ArrayList(java.util.ArrayList) Vector(org.gradoop.flink.model.impl.operators.layouting.util.Vector) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) Test(org.junit.Test)

Aggregations

LVertex (org.gradoop.flink.model.impl.operators.layouting.util.LVertex)18 Vector (org.gradoop.flink.model.impl.operators.layouting.util.Vector)11 Test (org.junit.Test)10 Force (org.gradoop.flink.model.impl.operators.layouting.util.Force)9 ArrayList (java.util.ArrayList)6 ListCollector (org.apache.flink.api.common.functions.util.ListCollector)5 LEdge (org.gradoop.flink.model.impl.operators.layouting.util.LEdge)5 EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)4 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)3 FRRepulsionFunction (org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction)3 LVertexEPGMVertexJoinFunction (org.gradoop.flink.model.impl.operators.layouting.functions.LVertexEPGMVertexJoinFunction)3 Centroid (org.gradoop.flink.model.impl.operators.layouting.util.Centroid)3 LGraph (org.gradoop.flink.model.impl.operators.layouting.util.LGraph)3 DataSet (org.apache.flink.api.java.DataSet)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 FRCellIdMapper (org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdMapper)2 FRCellIdSelector (org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdSelector)2 FRForceApplicator (org.gradoop.flink.model.impl.operators.layouting.functions.FRForceApplicator)2 SimpleGraphElement (org.gradoop.flink.model.impl.operators.layouting.util.SimpleGraphElement)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1