@Test public void testCentroidUpdater() { List<Centroid> centroids = new ArrayList<>(); centroids.add(new Centroid(new Vector(3, 3), 0)); centroids.add(new Centroid(new Vector(7, 7), 0)); CentroidUpdater upd = new CentroidUpdater(1000, CentroidFRLayouter.MIN_MASS_FACTOR, CentroidFRLayouter.MAX_MASS_FACTOR); upd.centroids = centroids; LVertex vertex = new LVertex(GradoopId.get(), new Vector(4, 4)); LVertex vertex2 = new LVertex(GradoopId.get(), new Vector(100, 5)); LVertex vertex3 = new LVertex(GradoopId.get(), new Vector(0, 0)); Assert.assertEquals(centroids.get(0).getId(), upd.map(vertex).getId()); Assert.assertEquals(centroids.get(1).getId(), upd.map(vertex2).getId()); Assert.assertEquals(centroids.get(0).getId(), upd.map(vertex3).getId()); List<Force> forces = new ArrayList<>(); forces.add(new Force(null, new Vector(10, 10))); forces.add(new Force(null, new Vector(20, 20))); forces.add(new Force(null, new Vector(30, 30))); List<Centroid> collectorList = new ArrayList<>(); ListCollector<Centroid> collector = new ListCollector<>(collectorList); upd.calculateNewCentroidPosition(forces, collector); Assert.assertEquals(1, collectorList.size()); Assert.assertEquals(new Vector(20, 20), collectorList.get(0).getPosition()); Assert.assertEquals(3, collectorList.get(0).getCount()); Centroid toFew = new Centroid(new Vector(), 2); Centroid toMany = new Centroid(new Vector(), 100); Centroid ok = new Centroid(new Vector(), 30); collectorList.clear(); upd.removeOrSplitCentroids(toFew, collector); Assert.assertEquals(0, collectorList.size()); upd.removeOrSplitCentroids(toMany, collector); Assert.assertEquals(2, collectorList.size()); Assert.assertEquals(50, collectorList.get(0).getCount()); Assert.assertEquals(50, collectorList.get(1).getCount()); collectorList.clear(); upd.removeOrSplitCentroids(ok, collector); Assert.assertEquals(1, collectorList.size()); Assert.assertEquals(30, collectorList.get(0).getCount()); Assert.assertEquals(ok.getId(), collectorList.get(0).getId()); }
public CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor) { this.vertexCount = vertexCount; this.minMassFactor = minMassFactor; this.maxMassFactor = maxMassFactor; }
CentroidUpdater extends RichMapFunction<LVertex, Force> { public CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor) { this.vertexCount = vertexCount; this.minMassFactor = minMassFactor; this.maxMassFactor = maxMassFactor; } }
CentroidUpdater extends RichMapFunction<LVertex, Force> { public CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor) { this.vertexCount = vertexCount; this.minMassFactor = minMassFactor; this.maxMassFactor = maxMassFactor; } CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor); }
CentroidUpdater extends RichMapFunction<LVertex, Force> { public CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor) { this.vertexCount = vertexCount; this.minMassFactor = minMassFactor; this.maxMassFactor = maxMassFactor; } CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor); @Override void open(Configuration parameters); DataSet<Centroid> updateCentroids(DataSet<Centroid> centroids, DataSet<LVertex> vertices); Force map(LVertex vertex); }
CentroidUpdater extends RichMapFunction<LVertex, Force> { public CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor) { this.vertexCount = vertexCount; this.minMassFactor = minMassFactor; this.maxMassFactor = maxMassFactor; } CentroidUpdater(int vertexCount, double minMassFactor, double maxMassFactor); @Override void open(Configuration parameters); DataSet<Centroid> updateCentroids(DataSet<Centroid> centroids, DataSet<LVertex> vertices); Force map(LVertex vertex);  }