Commit 2fdea5df authored by Julian Zobel's avatar Julian Zobel
Browse files

Fixed:

- JSON Attraction Generator: Now takes an upper limit int for only using the first n locations from the given JSON file.
- JSON Placement: Places nodes on *all* attraction points and not only the first.
parent 8d2e0e34
......@@ -114,7 +114,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
if(allPOI != null) {
int limit = 0;
if(numberOfAttractionPoints == 0) {
if(numberOfAttractionPoints == 0 || numberOfAttractionPoints > allPOI.length()) {
limit = allPOI.length();
}
else {
......
......@@ -23,7 +23,9 @@ package de.tud.kom.p2psim.impl.topology.placement;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import org.apache.commons.io.IOUtils;
......@@ -35,16 +37,25 @@ import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* Generates attraction points out of real data from OSM.
* Places a topology component based on JSON file attraction points
*
* @author Nils Richerzhagen
* @version 1.0, Feb 22, 2016
*
* FIX: Does only return the first element.
* Now components are placed on a randomly chosen attraction point.
*
* @author Julian Zobel
* @version 1.1, Nov 2018
*
*/
public class JSONPlacement implements PlacementModel {
private PositionVector worldDimensions;
private Random random = Randoms.getRandom(JSONPlacement.class);
private List<PositionVector> placements;
......@@ -60,7 +71,7 @@ public class JSONPlacement implements PlacementModel {
http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=bar%5D%2849%2E4813%2C8%2E5590%2C49%2E9088%2C8%2E7736%29%3Bout%3B
*/
public JSONPlacement() {
placements = new Vector<PositionVector>();
placements = new LinkedList<PositionVector>();
latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper();
......@@ -120,6 +131,8 @@ public class JSONPlacement implements PlacementModel {
public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile;
}
......@@ -128,12 +141,17 @@ public class JSONPlacement implements PlacementModel {
if(worldDimensions == null){
worldDimensions = comp.getTopology().getWorldDimensions();
}
getPlacements();
if(placements.isEmpty()) {
getPlacements();
}
}
@Override
public PositionVector place(TopologyComponent comp) {
return placements.remove(0);
int n = random.nextInt(placements.size());
return placements.get(n).clone();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment