Search in sources :

Example 1 with Force

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

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

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

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

the class FRAttractionFunctionTest method testAttractionFunction.

@Test
public void testAttractionFunction() throws Exception {
    FRAttractionFunction af = new FRAttractionFunction(10);
    LVertex v1 = getDummyVertex(1, 1);
    LVertex v2 = getDummyVertex(2, 3);
    LVertex v3 = getDummyVertex(7, 5);
    LVertex v4 = getDummyVertex(1, 1);
    List<Force> collectorList = new ArrayList<>();
    ListCollector<Force> collector = new ListCollector<>(collectorList);
    af.flatMap(new Tuple3<>(v1, v2, 1), collector);
    Vector vec12 = collectorList.get(0).getValue().copy();
    Vector vec21 = collectorList.get(1).getValue().copy();
    Assert.assertNotEquals(collectorList.get(0).getId(), collectorList.get(1).getId());
    collectorList.clear();
    af.flatMap(new Tuple3<>(v1, v3, 1), collector);
    Vector vec13 = collectorList.get(0).getValue().copy();
    collectorList.clear();
    af.flatMap(new Tuple3<>(v1, v4, 1), collector);
    Vector vec14 = collectorList.get(0).getValue().copy();
    collectorList.clear();
    af.flatMap(new Tuple3<>(v1, v1, 1), collector);
    Vector vec11 = collectorList.get(0).getValue().copy();
    collectorList.clear();
    v1 = getDummyVertex(1, 1);
    v3 = getDummyVertex(7, 5);
    af.flatMap(new Tuple3<>(v1, v3, 5), collector);
    Vector vec13f5 = collectorList.get(0).getValue().copy();
    collectorList.clear();
    Assert.assertEquals(vec12, vec21.mul(-1));
    Assert.assertTrue(vec12.getX() > 0 && vec12.getY() > 0);
    Assert.assertTrue(vec12.magnitude() < vec13.magnitude());
    Assert.assertEquals(vec14, new Vector());
    Assert.assertTrue(vec11.magnitude() == 0);
    Assert.assertEquals(vec13.mul(5), vec13f5);
}
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 5 with Force

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

the class FRLayouter method repulsionForces.

/**
 * Calculates the repulsive forces between the given vertices.
 *
 * @param vertices A dataset of vertices
 * @return Dataset of applied forces. May (and will) contain multiple forces for each vertex.
 */
protected DataSet<Force> repulsionForces(DataSet<LVertex> vertices) {
    vertices = vertices.map(new FRCellIdMapper(getMaxRepulsionDistance()));
    KeySelector<LVertex, Integer> selfselector = new FRCellIdSelector(FRCellIdSelector.NeighborType.SELF);
    FRRepulsionFunction repulsionFunction = new FRRepulsionFunction(getK(), getMaxRepulsionDistance());
    DataSet<Force> self = vertices.join(vertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.SELF)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> up = vertices.join(vertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UP)).equalTo(selfselector).with((FlatJoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> left = vertices.join(vertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.LEFT)).equalTo(selfselector).with((FlatJoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> uright = vertices.join(vertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UPRIGHT)).equalTo(selfselector).with((FlatJoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> uleft = vertices.join(vertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UPLEFT)).equalTo(selfselector).with((FlatJoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    return self.union(up).union(left).union(uright).union(uleft);
}
Also used : Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) FRRepulsionFunction(org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction) FRCellIdSelector(org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdSelector) FRCellIdMapper(org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdMapper) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex)

Aggregations

Force (org.gradoop.flink.model.impl.operators.layouting.util.Force)11 LVertex (org.gradoop.flink.model.impl.operators.layouting.util.LVertex)8 Vector (org.gradoop.flink.model.impl.operators.layouting.util.Vector)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Centroid (org.gradoop.flink.model.impl.operators.layouting.util.Centroid)4 ListCollector (org.apache.flink.api.common.functions.util.ListCollector)3 FRCellIdMapper (org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdMapper)2 FRCellIdSelector (org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdSelector)2 FRRepulsionFunction (org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 FilterFunction (org.apache.flink.api.common.functions.FilterFunction)1 JoinFunction (org.apache.flink.api.common.functions.JoinFunction)1 DataSet (org.apache.flink.api.java.DataSet)1 KeySelector (org.apache.flink.api.java.functions.KeySelector)1