@Test public void testRepulsionForceCalculator() { List<Centroid> centroids = new ArrayList<>(); centroids.add(new Centroid(new Vector(3, 3), 0)); centroids.add(new Centroid(new Vector(7, 7), 0)); List<Vector> center = new ArrayList<>(); center.add(new Vector(5, 5)); FRRepulsionFunction rf = new FRRepulsionFunction(10); CentroidRepulsionForceMapper calc = new CentroidRepulsionForceMapper(rf); calc.centroids = centroids; calc.center = center; LVertex vertex = new LVertex(GradoopId.get(), new Vector(1, 1)); Force f = calc.map(vertex).copy(); Assert.assertEquals(f.getId(), vertex.getId()); Assert.assertTrue(f.getValue().getX() < 0 && f.getValue().getY() < 0); centroids.add(new Centroid(new Vector(-1, -1), 0)); Force f2 = calc.map(vertex).copy(); Assert.assertTrue(f2.getValue().magnitude() < f.getValue().magnitude()); }
@Override public Force map(LVertex vertex) { forceSumVect.reset(); for (Centroid c : centroids) { centroidVertex.setId(c.getId()); centroidVertex.setPosition(c.getPosition().copy()); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); } centroidVertex.setPosition(center.get(0)); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); sumForce.set(vertex.getId(), forceSumVect); return sumForce; }
CentroidRepulsionForceMapper extends RichMapFunction<LVertex, Force> { @Override public Force map(LVertex vertex) { forceSumVect.reset(); for (Centroid c : centroids) { centroidVertex.setId(c.getId()); centroidVertex.setPosition(c.getPosition().copy()); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); } centroidVertex.setPosition(center.get(0)); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); sumForce.set(vertex.getId(), forceSumVect); return sumForce; } }
CentroidRepulsionForceMapper extends RichMapFunction<LVertex, Force> { @Override public Force map(LVertex vertex) { forceSumVect.reset(); for (Centroid c : centroids) { centroidVertex.setId(c.getId()); centroidVertex.setPosition(c.getPosition().copy()); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); } centroidVertex.setPosition(center.get(0)); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); sumForce.set(vertex.getId(), forceSumVect); return sumForce; } CentroidRepulsionForceMapper(FRRepulsionFunction rf); }
CentroidRepulsionForceMapper extends RichMapFunction<LVertex, Force> { @Override public Force map(LVertex vertex) { forceSumVect.reset(); for (Centroid c : centroids) { centroidVertex.setId(c.getId()); centroidVertex.setPosition(c.getPosition().copy()); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); } centroidVertex.setPosition(center.get(0)); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); sumForce.set(vertex.getId(), forceSumVect); return sumForce; } CentroidRepulsionForceMapper(FRRepulsionFunction rf); @Override void open(Configuration parameters); @Override Force map(LVertex vertex); }
CentroidRepulsionForceMapper extends RichMapFunction<LVertex, Force> { @Override public Force map(LVertex vertex) { forceSumVect.reset(); for (Centroid c : centroids) { centroidVertex.setId(c.getId()); centroidVertex.setPosition(c.getPosition().copy()); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); } centroidVertex.setPosition(center.get(0)); forceSumVect.mAdd(rf.join(vertex, centroidVertex).getValue()); sumForce.set(vertex.getId(), forceSumVect); return sumForce; } CentroidRepulsionForceMapper(FRRepulsionFunction rf); @Override void open(Configuration parameters); @Override Force map(LVertex vertex);  }