Search in sources :

Example 1 with BubbleFitnessFunctor

use of org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor in project activityinfo by bedatadriven.

the class CoincidentPointsClusterTest method testRealData.

@Test
public void testRealData() throws Exception {
    // Define projection for the test case
    TiledMap map = new TiledMap(492, 690, new AiLatLng(2.293492496, 30.538372993), 9);
    // Read data
    BufferedReader in = new BufferedReader(new InputStreamReader(GraphTest.class.getResourceAsStream("/distribscolaire-points.csv")));
    double originalSum = 0;
    List<PointValue> points = new ArrayList<PointValue>();
    while (in.ready()) {
        String line = in.readLine();
        String[] columns = line.split(",");
        double lat = Double.parseDouble(columns[0]);
        double lng = Double.parseDouble(columns[1]);
        PointValue pv = new PointValue();
        pv.setPx(map.fromLatLngToPixel(new AiLatLng(lat, lng)));
        pv.setValue(Double.parseDouble(columns[2]));
        pv.setSymbol(new MapSymbol());
        pv.setSite(new SiteDTO());
        originalSum += pv.getValue();
        points.add(pv);
    }
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    // make sure nothing was lost in the merging of coincident points
    double nodeSum = 0;
    for (MarkerGraph.Node node : graph.getNodes()) {
        nodeSum += node.getPointValue().getValue();
    }
    Assert.assertEquals("values after construction of graph", originalSum, nodeSum, 0.001);
    saveGraphImage("clusterTest2", graph, 15);
    GeneticSolver solver = new GeneticSolver();
    List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
    // check to make sure all values were included
    double sumAfterClustering = 0;
    for (Cluster cluster : clusters) {
        sumAfterClustering += cluster.sumValues();
    }
    Assert.assertEquals(originalSum, sumAfterClustering, 0.001);
    Assert.assertEquals(15, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : InputStreamReader(java.io.InputStreamReader) MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BufferedReader(java.io.BufferedReader) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 2 with BubbleFitnessFunctor

use of org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor in project activityinfo by bedatadriven.

the class GeneticClusterer method cluster.

/*
     * Clusters points using a genetic algorithm to determine what nearby points
     * are logical candidates to cluster
     * 
     * @see
     * org.activityinfo.legacy.model.reports.model.clustering.Clustering#cluster(java
     * .util.List, org.activityinfo.server.report.generator.map.RadiiCalculator)
     */
@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
    List<Cluster> clusters;
    MarkerGraph graph = new MarkerGraph(points, intersectionCalculator);
    GeneticSolver solver = new GeneticSolver();
    clusters = solver.solve(graph, radiiCalculator, new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, radiiCalculator));
    return clusters;
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)

Example 3 with BubbleFitnessFunctor

use of org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor in project activityinfo by bedatadriven.

the class CoincidentPointsClusterTest method testSimpleData.

@Test
public void testSimpleData() throws Exception {
    List<PointValue> points = new ArrayList<PointValue>();
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 7.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 2.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 41.0, new Point(100, 100)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 9.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 39.0, new Point(100, 100)));
    double originalSum = 7 + 2 + 9 + 41 + 39;
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    GeneticSolver solver = new GeneticSolver();
    List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
    // check to make sure all values were included
    double sumAfterClustering = 0;
    for (Cluster cluster : clusters) {
        sumAfterClustering += cluster.sumValues();
    }
    Assert.assertEquals(originalSum, sumAfterClustering, 0.0001);
    Assert.assertEquals(2, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol) Point(org.activityinfo.legacy.shared.reports.content.Point) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Aggregations

BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)3 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)3 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)3 ArrayList (java.util.ArrayList)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)2 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)2 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Point (org.activityinfo.legacy.shared.reports.content.Point)1 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)1