Commit 7d94ced8 authored by Julian Zobel's avatar Julian Zobel
Browse files

Added a minimum and maximum radius for random and json attraction point generators

parent 2b8932a2
......@@ -94,8 +94,12 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
assert localMovementStrategy instanceof RealWorldStreetsMovement: "ModularMultiTypeMovementModel can only be used with RealWorldStreetsMovement!";
Either<PositionVector, Boolean> either;
if(movementTypes.containsKey(ms)) either = ((RealWorldStreetsMovement) localMovementStrategy).nextPosition(ms, destination, movementTypes.get(ms));
else either = localMovementStrategy.nextPosition(ms, destination);
if(movementTypes.containsKey(ms)) {
either = ((RealWorldStreetsMovement) localMovementStrategy).nextPosition(ms, destination, movementTypes.get(ms));
}
else {
either = localMovementStrategy.nextPosition(ms, destination);
}
if (either.hasLeft()) {
ms.updateCurrentLocation(either.getLeft());
......
......@@ -25,6 +25,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
......@@ -35,6 +36,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
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.Binder;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......@@ -49,10 +51,16 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Julian Zobel
* @version 1.1, November 2018
*
* You now can set an upper limit for the radius.
* @author Julian Zobel
* @version 1.2, January 2019
*
*
*/
public class JSONAttractionGenerator implements IAttractionGenerator {
private Random rand = Randoms.getRandom(JSONAttractionGenerator.class);
private PositionVector worldDimensions;
private int numberOfAttractionPoints;
......@@ -61,7 +69,8 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180
private double maximumRadius = -1; // Values >= 0, or -1 if radius taken from file
/**
* You have to set a json-file, which has set some POIs
* Sample-query for "bar"-POIs in Darmstadt (Bounding Box from [49.4813, 8.5590] to [49.9088, 8,7736]:
......@@ -133,7 +142,17 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
attractionPoints.add(ap);
// the following is allowed to fail.
ap.setWeight(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("weight"));
ap.setRadius(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius"));
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
}
}
catch (JSONException e) {
......@@ -145,7 +164,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
return attractionPoints;
}
public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile;
//System.out.println(placementJsonFile);
......@@ -153,4 +172,12 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
this.getAttractionPoints();
}
}
/**
* Set a maximum radius that an attraction point can have. Minimum is 10 meters.
* @param radius
*/
public void setMaximumRadius(double radius) {
this.maximumRadius = radius;
}
}
......@@ -60,6 +60,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private double maximumRadius = 100;
private double minimumRadius = 10;
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
......@@ -99,7 +101,7 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
// set the radius of this attraction point
// minimum radius is 10 meters
double radius = Math.max(10, rand.nextDouble() * maximumRadius);
double radius = Math.max(minimumRadius, rand.nextDouble() * maximumRadius);
if(c < 20)
{
......@@ -152,4 +154,12 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
public void setMaximumRadius(double radius) {
this.maximumRadius = radius;
}
/**
* Set a maximum radius that an attraction point can have. Minimum is 10 meters.
* @param radius
*/
public void setMinimumRadius(double radius) {
this.minimumRadius = radius;
}
}
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