Search in sources :

Example 1 with FRRepulsionFunction

use of org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction 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)

Example 2 with FRRepulsionFunction

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

the class SamplingFRLayouter method repulsionForces.

@Override
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());
    final double samplingRateF = this.samplingRate;
    DataSet<LVertex> sampledVertices = vertices.filter((FilterFunction<LVertex>) lVertex -> ThreadLocalRandom.current().nextDouble(1) < samplingRateF);
    DataSet<Force> self = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.SELF)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> up = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UP)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> down = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.DOWN)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> left = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.LEFT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> right = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.RIGHT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> uright = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UPRIGHT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> dright = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.DOWNRIGHT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> uleft = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.UPLEFT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    DataSet<Force> dleft = vertices.join(sampledVertices).where(new FRCellIdSelector(FRCellIdSelector.NeighborType.DOWNLEFT)).equalTo(selfselector).with((JoinFunction<LVertex, LVertex, Force>) repulsionFunction);
    return self.union(up).union(left).union(uright).union(uleft).union(down).union(right).union(dright).union(dleft).map(f -> {
        f.getValue().mDiv(samplingRateF);
        return f;
    });
}
Also used : FilterFunction(org.apache.flink.api.common.functions.FilterFunction) DataSet(org.apache.flink.api.java.DataSet) KeySelector(org.apache.flink.api.java.functions.KeySelector) FRCellIdSelector(org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdSelector) LVertex(org.gradoop.flink.model.impl.operators.layouting.util.LVertex) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Force(org.gradoop.flink.model.impl.operators.layouting.util.Force) FRRepulsionFunction(org.gradoop.flink.model.impl.operators.layouting.functions.FRRepulsionFunction) FRCellIdMapper(org.gradoop.flink.model.impl.operators.layouting.functions.FRCellIdMapper) JoinFunction(org.apache.flink.api.common.functions.JoinFunction) 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

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 Force (org.gradoop.flink.model.impl.operators.layouting.util.Force)2 LVertex (org.gradoop.flink.model.impl.operators.layouting.util.LVertex)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