Commit 1ca1a44e authored by Julian Zobel's avatar Julian Zobel
Browse files

Global Oracle provides knowledge on attraction points

Remodelled attraction points generators to a common abstract class and interface
parent d8bfa8aa
......@@ -27,7 +27,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import de.tud.kom.p2psim.api.churn.ChurnGenerator;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.network.SimNetworkComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
......@@ -36,7 +35,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
......@@ -69,7 +68,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
protected long timeBetweenMoveOperations;
protected IMapVisualization mapVisualization;
protected IAttractionGenerator attractionGenerator;
protected IAttractionProvider attractionGenerator;
protected AttractionPointViz attractionpointVisualization;
protected boolean initialized = false;
......@@ -106,6 +105,8 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
}
if (attractionpointVisualization != null) {
attractionpointVisualization.setAttractionPoints(new LinkedList<>(attractionGenerator.getAttractionPoints()));
VisualizationInjector.injectComponent(attractionpointVisualization);
}
......@@ -363,7 +364,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
this.attractionpointVisualization = viz;
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
public void setIAttractionGenerator(IAttractionProvider attractionGenerator) {
if (attractionGenerator == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
......
......@@ -21,7 +21,6 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointImpl;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
......
......@@ -38,7 +38,7 @@ import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy.AttractionAssignmentListener;
......@@ -104,7 +104,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
protected IAttractionAssigmentStrategy attractionAssigment;
protected IAttractionGenerator attractionGenerator;
protected IAttractionProvider attractionProvider;
protected LocalMovementStrategy localMovementStrategy;
......@@ -175,6 +175,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
.setScaleFactor(timeBetweenMoveOperation / (double) Time.SECOND);
attractionAssigment.addAttractionAssignmentListener(this);
attractionAssigment.setAttractionProvider(attractionProvider);
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
......@@ -373,12 +374,12 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
if (attractionGenerator == null) {
public void setIAttractionProvider(IAttractionProvider attractionProvider) {
if (attractionProvider == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
"AttractionProvider is missing in ModularMovementModel!");
}
this.attractionGenerator = attractionGenerator;
this.attractionProvider = attractionProvider;
}
public void setLocalMovementStrategy(LocalMovementStrategy localMovementStrategy) {
......@@ -418,7 +419,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
* @return
*/
public List<IAttractionPoint> getAttractionPoints() {
return new Vector<IAttractionPoint>(IAttractionGenerator.attractionPoints);
return new Vector<IAttractionPoint>(attractionProvider.getAttractionPoints());
}
public void setAttractionPointViz(AttractionPointViz viz) {
......
......@@ -43,7 +43,7 @@ import com.graphhopper.util.shapes.GHPoint3D;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.local.AbstractLocalMovementStrategy;
import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
......@@ -304,7 +304,7 @@ public class ModularMovementModelViz extends JComponent
{
Composite gc = g2.getComposite();
for (IAttractionPoint aPoint : IAttractionGenerator.attractionPoints) {
for (IAttractionPoint aPoint : movementModel.getAttractionPoints()) {
Point point = ((PositionVector) aPoint).asPoint();
// draw border
g2.setColor(Color.BLACK);
......
......@@ -30,7 +30,7 @@ import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.MovementGroupContainer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupencounter.IGroupEncounterBehavior;
......
......@@ -22,32 +22,48 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.oracle.GlobalOracle;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Interface for {@link IAttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public interface IAttractionGenerator {
static LinkedList<IAttractionPoint> attractionPoints = new LinkedList<>();
public class AbstractAttractionProvider implements IAttractionProvider {
public List<IAttractionPoint> getAttractionPoints();
private LinkedList<AttractionPoint> attractionPoints = new LinkedList<>();
protected PositionVector worldDimension;
public AbstractAttractionProvider() {
this.worldDimension = Binder.getComponentOrNull(Topology.class).getWorldDimensions();
}
public List<AttractionPoint> getAttractionPoints() {
return new LinkedList<AttractionPoint>(attractionPoints);
}
protected void clearAttractionPoints() {
attractionPoints.clear();
}
protected boolean hasAttractionPoint(AttractionPoint ap) {
return attractionPoints.contains(ap);
}
/**
* Remove an {@link IAttractionPoint} from the list
* @param ap
*/
default void removeAttractionPoint(IAttractionPoint ap) {
public void removeAttractionPoint(AttractionPoint ap) {
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
Monitor.getOrNull(AttractionPointMonitor.class).removedAttractionPoint(ap);
}
GlobalOracle.removeAttractionPoint(ap);
attractionPoints.remove(ap);
}
......@@ -55,18 +71,19 @@ public interface IAttractionGenerator {
* Add an {@link IAttractionPoint} to the list
* @param ap
*/
default void addAttractionPoint(IAttractionPoint ap) {
public void addAttractionPoint(AttractionPoint ap) {
if(ap == null) {
Monitor.log(IAttractionGenerator.class, Level.ERROR, "IAttractionGenerator: Tried to add NULL as Attraction Point");
Monitor.log(IAttractionProvider.class, Level.ERROR, "IAttractionGenerator: Tried to add NULL as Attraction Point");
return;
}
}
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
Monitor.getOrNull(AttractionPointMonitor.class).addedAttractionPoint(ap);
}
GlobalOracle.addAttractionPoint(ap);
attractionPoints.add(ap);
}
}
......@@ -41,17 +41,15 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @version 1.1, 26.10.2018 - since the class was very similar to {@link BasicAttractionPoint}, made this class an extension
* @version 1.2, 24.01.2020 - added pause time interval, weight, and radius exclusively to this class, because {@link BasicAttractionPoint} should be just a named point.
*/
public class AttractionPointImpl extends BasicAttractionPoint {
protected static Random rnd = Randoms.getRandom(IAttractionPoint.class);
protected static Map<String, AttractionPointImpl> instances = new LinkedHashMap<>();
public class AttractionPoint extends BasicAttractionPoint {
protected static Map<String, AttractionPoint> instances = new LinkedHashMap<>();
protected long pauseTimeMin = -1;
protected long pauseTimeMax = -1;
protected double weight = 0;
protected double radius = 0;
public AttractionPointImpl(String name, PositionVector posVec) {
public AttractionPoint(String name, PositionVector posVec) {
super(name, posVec);
if (instances.containsKey(name)) {
......@@ -64,7 +62,7 @@ public class AttractionPointImpl extends BasicAttractionPoint {
}
}
public AttractionPointImpl(String name, PositionVector posVec, double weight, double radius, long pauseTimeMin, long pauseTimeMax) {
public AttractionPoint(String name, PositionVector posVec, double weight, double radius, long pauseTimeMin, long pauseTimeMax) {
this(name, posVec);
assert weight >= 0 && weight <= 1.0;
......@@ -77,7 +75,7 @@ public class AttractionPointImpl extends BasicAttractionPoint {
@Override
public IAttractionPoint clone(String newName) {
return new AttractionPointImpl(name, this, weight, radius, pauseTimeMin, pauseTimeMax);
return new AttractionPoint(name, this, weight, radius, pauseTimeMin, pauseTimeMax);
}
@Override
......@@ -100,7 +98,7 @@ public class AttractionPointImpl extends BasicAttractionPoint {
return true;
if (getClass() != obj.getClass())
return false;
AttractionPointImpl other = (AttractionPointImpl) obj;
AttractionPoint other = (AttractionPoint) obj;
if (name == null) {
if (other.name != null)
return false;
......
......@@ -56,10 +56,15 @@ public class AttractionPointViz extends JComponent
public static LinkedList<LinkedList<SimHost>> clusters = new LinkedList<LinkedList<SimHost>>();
public static LinkedList<Color> colors = new LinkedList<Color>();
public LinkedList<IAttractionPoint> aps;
public AttractionPointViz() {
init();
}
public void setAttractionPoints(LinkedList<IAttractionPoint> aps) {
this.aps = aps;
}
protected void init() {
setBounds(0, 0, VisualizationInjector.getWorldX(),
......@@ -141,9 +146,13 @@ public class AttractionPointViz extends JComponent
*/
protected void drawAttractionPoints(Graphics2D g2)
{
if(aps == null || aps.size() == 0) {
return;
}
Composite gc = g2.getComposite();
for (IAttractionPoint aPoint : IAttractionGenerator.attractionPoints) {
for (IAttractionPoint aPoint : aps) {
Point point = ((PositionVector) aPoint).asPoint();
// draw border
g2.setColor(Color.BLACK);
......
......@@ -19,8 +19,6 @@
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* For simple scenarios: add attraction points by specifying a coordinate.
......@@ -28,16 +26,10 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @author Bjoern Richerzhagen
* @version 1.0, Dec 11, 2015
*/
public class ConfigAttractionGenerator implements IAttractionGenerator {
public class ConfigAttractionGenerator extends AbstractAttractionProvider {
@Override
public List<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
public void setAttractionPoint(IAttractionPoint point) {
attractionPoints.add(point);
public void setAttractionPoint(AttractionPoint point) {
addAttractionPoint(point);
}
}
......@@ -21,17 +21,8 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
......@@ -40,16 +31,9 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Julian Zobel
* @version 1.0, April 2019
*/
public class ConfigDynamicAttractionGenerator implements IAttractionGenerator {
public class ConfigDynamicAttractionGenerator extends AbstractAttractionProvider {
private LinkedList<TemporalAttractionPoint> allAPs = new LinkedList<>();
@Override
public List<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
public void setAttractionPoint(TemporalAttractionPoint ap) {
allAPs.add(ap);
......@@ -62,21 +46,17 @@ public class ConfigDynamicAttractionGenerator implements IAttractionGenerator {
}, null, 0);
}
private void placeAP(TemporalAttractionPoint ap) {
attractionPoints.add(ap);
void placeAP(TemporalAttractionPoint ap) {
addAttractionPoint(ap);
Event.scheduleWithDelay(ap.getRemovalTime(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
removeAP(ap);
removeAttractionPoint(ap);
}
}, null, 0);
}
private void removeAP(TemporalAttractionPoint ap) {
attractionPoints.remove(ap);
}
}
......@@ -39,9 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Nils Richerzhagen
* @version 1.0, 16.07.2014
*/
public class CsvAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions;
public class CsvAttractionGenerator extends AbstractAttractionProvider {
private String file;
......@@ -55,8 +53,7 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
*/
@XMLConfigurableConstructor({ "placementFile" })
public CsvAttractionGenerator(String placementFile) {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
super();
this.file = placementFile;
readData();
......@@ -67,11 +64,11 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if (attractionPoints == null) {
public List<AttractionPoint> getAttractionPoints() {
if (super.getAttractionPoints().isEmpty()) {
readData();
}
return attractionPoints;
return super.getAttractionPoints();
}
private void readData() {
......@@ -91,14 +88,14 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
Double x = Double.parseDouble(parts[0]);
Double y = Double.parseDouble(parts[1]);
if (x > worldDimensions.getX()
|| y > worldDimensions.getY() || x < 0
if (x > worldDimension.getX()
|| y > worldDimension.getY() || x < 0
|| y < 0) {
System.err.println("Skipped entry " + x + ";"
+ y);
continue;
}
IAttractionPoint ap = new AttractionPointImpl("AP"+i, new PositionVector(x, y));
AttractionPoint ap = new AttractionPoint("AP"+i, new PositionVector(x, y));
ap.setRadius(radius);
addAttractionPoint(ap);
......@@ -117,15 +114,15 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
Double y = Double.parseDouble(parts[1]);
Double r = Double.parseDouble(parts[2]);
if (x > worldDimensions.getX()
|| y > worldDimensions.getY() || x < 0
if (x > worldDimension.getX()
|| y > worldDimension.getY() || x < 0
|| y < 0) {
System.err.println("Skipped entry " + x + ";"
+ y);
continue;
}
IAttractionPoint ap = new AttractionPointImpl("AP"+i, new PositionVector(x, y));
AttractionPoint ap = new AttractionPoint("AP"+i, new PositionVector(x, y));
ap.setRadius(r);
addAttractionPoint(ap);
......
......@@ -21,42 +21,32 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* Generates the given number of {@link IAttractionPoint}s and sets the
* position randomly within the world dimensions.
* Attraction Generator, providing 4 equidistant attraction points, i.e., in a square
*
* @author Julian Zobel
* @version 1.0, Nov 2018
*/
public class EquidistantSquareAttractionGenerator implements IAttractionGenerator {
public class EquidistantSquareAttractionGenerator extends AbstractAttractionProvider {
private PositionVector worldDimension;
private double squareSize;
@XMLConfigurableConstructor({ "squareSize" })
public EquidistantSquareAttractionGenerator(double squareSize) {
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
this.squareSize = squareSize;
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.isEmpty())
public List<AttractionPoint> getAttractionPoints() {
if(super.getAttractionPoints().isEmpty())
createAttractionPoints();
return attractionPoints;
return super.getAttractionPoints();
}
private void createAttractionPoints() {
......@@ -64,21 +54,17 @@ public class EquidistantSquareAttractionGenerator implements IAttractionGenerato
double x = worldDimension.getX() / 2;
double y = worldDimension.getY() / 2;
PositionVector p1 = new PositionVector(x - squareSize, y - squareSize);
IAttractionPoint ap1 = new AttractionPointImpl("AP1", p1);
attractionPoints.add(ap1);
PositionVector p1 = new PositionVector(x - squareSize, y - squareSize);
this.addAttractionPoint(new AttractionPoint("AP1", p1));
PositionVector p2 = new PositionVector(x - squareSize, y + squareSize);
IAttractionPoint ap2 = new AttractionPointImpl("AP2", p2);
attractionPoints.add(ap2);
this.addAttractionPoint(new AttractionPoint("AP2", p2));
PositionVector p3 = new PositionVector(x + squareSize, y - squareSize);
IAttractionPoint ap3 = new AttractionPointImpl("AP3", p3);
attractionPoints.add(ap3);
this.addAttractionPoint(new AttractionPoint("AP3", p3));
PositionVector p4 = new PositionVector(x + squareSize, y + squareSize);
IAttractionPoint ap4 = new AttractionPointImpl("AP4", p4);
attractionPoints.add(ap4);
this.addAttractionPoint(new AttractionPoint("AP4", p4));
}
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Interface for {@link IAttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public interface IAttractionProvider {
public List<AttractionPoint> getAttractionPoints();
}
\ No newline at end of file
......@@ -23,16 +23,14 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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.component.sensor.location.IAttractionPoint;
import de.tud.kom.p2psim.impl.util.oracle.GlobalOracle;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -52,115 +50,117 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*
*
*/
public class JSONAttractionGenerator implements IAttractionGenerator {
public class JSONAttractionGenerator extends AbstractAttractionProvider {
private int numberOfAttractionPoints;
private String placementJsonFile;
protected int numberOfAttractionPoints;
protected String placementJsonFile = "";
private double maximumRadius = -1; // Values >= 0, or -1 if radius taken from file
protected 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]:
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
*/
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public JSONAttractionGenerator(int numberOfAttractionPoints) {
@XMLConfigurableConstructor({"numberOfAttractionPoints", "maximumRadius", "placementJsonFile"})
public JSONAttractionGenerator(int numberOfAttractionPoints, double maximumRadius, String placementJsonFile) {
this.numberOfAttractionPoints = numberOfAttractionPoints;
this.maximumRadius = maximumRadius;
this.placementJsonFile = placementJsonFile;
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.size() == 0) {
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if(allPOI != null) {
int limit = 0;
if(numberOfAttractionPoints == 0 || numberOfAttractionPoints > allPOI.length()) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
AttractionPointImpl ap;
// check that the point is within the simulation boundaries
if(GPSCalculation.isWithinGPSBoundaries(lat, lon)) {
// initialize the attraction point with basic information, will be filled now...
ap = new AttractionPointImpl(barname, GPSCalculation.transformGPSWindowToOwnWorld(lat, lon));
attractionPoints.add(ap);
// the following setters are allowed to fail
// AP weight
if(allPOI.getJSONObject(i).getJSONObject("tags").has("weight")) {
ap.setWeight(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("weight"));
}
// AP radius
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMin") && allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMax")) {
ap.setPauseTime( allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMin"), allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMax"));
}
System.out.println(ap);
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
System.out.println(e);
}
}
}
public List<AttractionPoint> getAttractionPoints() {
if(super.getAttractionPoints().size() == 0) {
createAttractionPoints();
}
return attractionPoints;
return super.getAttractionPoints();
}
protected JSONArray getPOIArray() {
assert !placementJsonFile.equals("");
public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile;
//System.out.println(placementJsonFile);
if(attractionPoints.isEmpty()) {
this.getAttractionPoints();
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return allPOI;
}
/**
* Set a maximum radius that an attraction point can have. Minimum is 10 meters.
* @param radius
*/
public void setMaximumRadius(double radius) {
this.maximumRadius = radius;
}
private void createAttractionPoints() {
assert super.getAttractionPoints().size() == 0;
JSONArray allPOI = getPOIArray();
if(allPOI == null) {
throw new UnsupportedOperationException("[JSONAttractionGenerator] POI Data Array cannot be NULL.");
}
int limit = 0;
if(numberOfAttractionPoints == 0 || numberOfAttractionPoints > allPOI.length()) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
AttractionPoint ap;
// check that the point is within the simulation boundaries
if(GPSCalculation.isWithinGPSBoundaries(lat, lon)) {
// initialize the attraction point with basic information, will be filled now...
ap = new AttractionPoint(barname, GPSCalculation.transformGPSWindowToOwnWorld(lat, lon));
// the following setters are allowed to fail
// AP weight
if(allPOI.getJSONObject(i).getJSONObject("tags").has("weight")) {
ap.setWeight(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("weight"));
}
// AP radius
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMin") && allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMax")) {
ap.setPauseTime( allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMin"), allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMax"));
}
addAttractionPoint(ap);
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
System.out.println(e);
}
}
}
}
......@@ -21,26 +21,18 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Generates attraction points out of real data from osm
......@@ -49,150 +41,58 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @author Martin Hellwig
* @version 1.0, 02.07.2015
*/
public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions;
public class OnlineJSONAttractionGenerator extends JSONAttractionGenerator {
private List<IAttractionPoint> attractionPoints;
private int maxNumberOfAttractionPoints;
private String placementJsonFile;
private String placementJsonPath;
private String amenity;
private double latLeft; //Values from -90 to 90; always smaller than latRight
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
public OnlineJSONAttractionGenerator() {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPoints = new LinkedList<IAttractionPoint>();
latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft();
lonRight = GPSCalculation.getLonRight();
}
@XMLConfigurableConstructor({"numberOfAttractionPoints", "maximumRadius", "placementJsonPath", "amenity"})
public OnlineJSONAttractionGenerator(int numberOfAttractionPoints, double maximumRadius,
String placementJsonPath, String amenity) {
/**
* Projects the gps coordinates in the given gps window to the world-coordinates given in world-dimensions
* @param lat
* @param lon
* @return The projected position in world-dimensions
*/
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft);
//Invert the y value, because in Java Swing we start drawing in the upper left corner instead in the lower left one
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLeft)/(latRight - latLeft);
return new PositionVector(x, y);
}
public void setNumberOfAttractionPoints(int numberOfAttractionPoints) {
this.maxNumberOfAttractionPoints = numberOfAttractionPoints;
}
super(numberOfAttractionPoints, maximumRadius, placementJsonPath +
"pois" +
GPSCalculation.getLatCenter() +
GPSCalculation.getLonCenter() +
GPSCalculation.getZoom() +
amenity + ".json");
this.amenity = amenity;
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.size() == 0) {
placementJsonFile = placementJsonPath +
"pois" +
GPSCalculation.getLatCenter() +
GPSCalculation.getLonCenter() +
GPSCalculation.getZoom() +
amenity + ".json";
//Check if the file with same properties (same location) already exists
File f = new File(placementJsonFile);
if(!f.exists()) {
String poiString = "";
JSONArray allPOI = null;
InputStream in;
try {
in = new URL( "http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=" + amenity + "%5D%28" + latLeft + "%2C" + lonLeft + "%2C" + latRight + "%2C" + lonRight + "%29%3Bout%3B" ).openStream();
poiString = IOUtils.toString(in);
//Save the json data in file
PrintWriter out = new PrintWriter(placementJsonFile);
out.print(poiString);
out.close();
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
if(lat > latLeft && lat < latRight &&
lon > lonLeft && lon < lonRight) {
attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
}
}
}
protected JSONArray getPOIArray() {
//Check if the file with same properties (same location) already exists
File f = new File(placementJsonFile);
if(!f.exists()) {
String poiString = "";
JSONArray allPOI = null;
InputStream in;
try {
in = new URL( "http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=" + amenity + "%5D%28"
+ GPSCalculation.getLatUpper() + "%2C" + GPSCalculation.getLonLeft() + "%2C"
+ GPSCalculation.getLatLower() + "%2C" + GPSCalculation.getLonRight() + "%29%3Bout%3B" ).openStream();
poiString = IOUtils.toString(in);
//Save the json data in file
PrintWriter out = new PrintWriter(placementJsonFile);
out.print(poiString);
out.close();
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else {
//File already exists, now we have to parse this file
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
}
}
}
}
}
if(maxNumberOfAttractionPoints == 0) maxNumberOfAttractionPoints = Integer.MAX_VALUE;
List<IAttractionPoint> result = new LinkedList<IAttractionPoint>();
for (int i = 0; (i < attractionPoints.size() && i < maxNumberOfAttractionPoints); i++) {
result.add(attractionPoints.get(i));
return allPOI;
}
return result;
}
public void setAmenity(String amenity) {
this.amenity = amenity;
}
public void setPlacementJsonPath(String placementJsonPath) {
this.placementJsonPath = placementJsonPath;
else {
return super.getPOIArray();
}
}
}
......@@ -44,12 +44,10 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Christoph Muenker, Julian Zobel
* @version 1.21, 12 2018
*/
public class RandomAttractionGenerator implements IAttractionGenerator {
public class RandomAttractionGenerator extends AbstractAttractionProvider {
private Random rand;
private PositionVector worldDimension;
private int numberOfAttractionPoints;
private boolean numberOfAPsSet = false;
......@@ -62,9 +60,9 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
@XMLConfigurableConstructor({"numberOfAttractionPoints", "maximumRadius", "minimumRadius", "minimumDistance"})
public RandomAttractionGenerator(int numberOfAttractionPoints, double maximumRadius, double minimumRadius, double minimumDistance) {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
super();
this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
if (numberOfAttractionPoints <= 0) {
throw new ConfigurationException(
"NumberOfAttractionPoints should be at least 1!");
......@@ -74,25 +72,23 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
this.maximumRadius = maximumRadius;
this.minimumRadius = minimumRadius;
this.minimumDistance = minimumDistance;
attractionPoints.clear();
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
public List<AttractionPoint> getAttractionPoints() {
if (!numberOfAPsSet) {
throw new ConfigurationException(
"Number of Attraction Points is not set in RandomAttractionGenerator!");
}
if(attractionPoints.isEmpty())
if(super.getAttractionPoints().isEmpty())
createAttractionPoints();
return attractionPoints;
return super.getAttractionPoints();
}
private void createAttractionPoints() {
List<IAttractionPoint> result = new LinkedList<IAttractionPoint>();
List<AttractionPoint> result = new LinkedList<AttractionPoint>();
// make a break counter to prevent more than 10 iterations and an infinity loop in general.
int c = 0;
......@@ -130,15 +126,13 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
radius = minimumRadius;
}
IAttractionPoint aPoint = new AttractionPointImpl("AP-"+i, posVec);
AttractionPoint aPoint = new AttractionPoint("AP-"+i, posVec);
aPoint.setRadius(radius);
c = 0;
result.add(aPoint);
}
attractionPoints.clear();
for (IAttractionPoint ap : result) {
for (AttractionPoint ap : result) {
addAttractionPoint(ap);
}
}
......
......@@ -20,18 +20,15 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import java.util.Random;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -46,12 +43,10 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Julian Zobel
* @version 1.0, March 2019
*/
public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
public class RandomDynamicAttractionGenerator extends AbstractAttractionProvider {
private Random rand;
private PositionVector worldDimension;
private int minNumberOfAttractionPoints;
private int maxNumberOfAttractionPoints;
......@@ -70,9 +65,7 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
double minimumDistance) {
this.rand = Randoms.getRandom(RandomDynamicAttractionGenerator.class);
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
if (minNumberOfAttractionPoints <= 0) {
throw new ConfigurationException(
"NumberOfAttractionPoints should be at least 1!");
......@@ -91,26 +84,15 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
this.minDynamicIntervall = minDynamicIntervall;
this.maxDynamicIntervall = maxDynamicIntervall;
attractionPoints.clear();
updateAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
/**
*
* @return an integer representing a randomly chosen number of attraction points within the allowed range of numbers
*/
private int randomNumberOfAttractionPoints() {
return minNumberOfAttractionPoints + rand.nextInt((maxNumberOfAttractionPoints - minNumberOfAttractionPoints) + 1);
}
private void scheduleDynamicEvent(IAttractionPoint attractionPoint) {
private void scheduleDynamicEvent(AttractionPoint attractionPoint) {
long r = (long) (rand.nextDouble() * (maxDynamicIntervall - minDynamicIntervall)) + minDynamicIntervall;
......@@ -118,7 +100,7 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
@Override
public void eventOccurred(Object content, int type) {
// maybe was already removed...
if(attractionPoints.contains(attractionPoint)) {
if(hasAttractionPoint(attractionPoint)) {
removeAttractionPoint(attractionPoint);
updateAttractionPoints();
}
......@@ -128,29 +110,30 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
protected void updateAttractionPoints() {
int numberOfAttractionPoints = randomNumberOfAttractionPoints();
int currentSize = getAttractionPoints().size();
// do nothing if this is the required amount of attraction points
if(numberOfAttractionPoints == attractionPoints.size()) {
if(numberOfAttractionPoints == currentSize) {
return;
}
// remove until this number fits
else if(numberOfAttractionPoints < attractionPoints.size()) {
int deltaAP = attractionPoints.size() - numberOfAttractionPoints;
else if(numberOfAttractionPoints < currentSize) {
int deltaAP = currentSize - numberOfAttractionPoints;
for(int i = 0; i < deltaAP; i++) {
int random = rand.nextInt(attractionPoints.size());
removeAttractionPoint(attractionPoints.get(random));
int random = rand.nextInt(currentSize);
removeAttractionPoint(getAttractionPoints().get(random));
}
return;
}
// add more attraction points until it fits
else {
int deltaAP = numberOfAttractionPoints - attractionPoints.size();
int deltaAP = numberOfAttractionPoints - currentSize;
for(int i = 0; i < deltaAP; i++) {
IAttractionPoint newAP = createAttractionPoint();
AttractionPoint newAP = createAttractionPoint();
scheduleDynamicEvent(newAP);
addAttractionPoint(newAP);
}
......@@ -162,7 +145,7 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
*
* @return
*/
private IAttractionPoint createAttractionPoint() {
private AttractionPoint createAttractionPoint() {
// make a break counter to prevent more than 100 iterations and an infinity loop in general.
int c = 100;
......@@ -181,7 +164,7 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
}
// if within world dimensions, continue checking against other attraction points
for (IAttractionPoint ap : attractionPoints) {
for (AttractionPoint ap : getAttractionPoints()) {
// if this point is closer than the given minimum distance to another point, or the radii of the points would overlap,
// or if the radius would exceed the simulation area
// then discard this attraction point and create a new one
......@@ -195,12 +178,12 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
radius = 0;
}
IAttractionPoint aPoint = new AttractionPointImpl("AP-" + rand.nextInt(), posVec);
AttractionPoint aPoint = new AttractionPoint("AP-" + rand.nextInt(), posVec);
aPoint.setRadius(radius);
return aPoint;
}
IAttractionPoint ap = new AttractionPointImpl("AP-ERROR", new PositionVector(worldDimension.getX() / 2, worldDimension.getY() / 2));
AttractionPoint ap = new AttractionPoint("AP-ERROR", new PositionVector(worldDimension.getX() / 2, worldDimension.getY() / 2));
ap.setRadius(0);
ap.setWeight(0);
......@@ -208,13 +191,10 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
return ap;
}
private PositionVector createPosVec() {
double x = rand.nextDouble() * worldDimension.getX();
double y = rand.nextDouble() * worldDimension.getY();
return new PositionVector(x, y);
}
}
}
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class TemporalAttractionPoint extends BasicAttractionPoint {
public class TemporalAttractionPoint extends AttractionPoint {
private long placementTime;
private long removalTime;
......
......@@ -20,33 +20,21 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* Generates the given number of {@link IAttractionPoint}s and sets the
* position randomly within the world dimensions.
*
* @author Julian Zobel
* @version 1.0, Nov 2018
*/
public class TwoPointFixedAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimension;
public class TwoPointFixedAttractionGenerator extends AbstractAttractionProvider {
private double x1, x2, y1, y2;
@XMLConfigurableConstructor({ "x1", "y1", "x2", "y2"})
public TwoPointFixedAttractionGenerator(double x1, double y1, double x2, double y2) {
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
super();
this.x1 = x1;
this.y1 = y1;
......@@ -55,27 +43,19 @@ public class TwoPointFixedAttractionGenerator implements IAttractionGenerator {
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.isEmpty())
createAttractionPoints();
return attractionPoints;
}
private void createAttractionPoints() {
PositionVector p1 = new PositionVector(x1, y1);
IAttractionPoint ap1 = new AttractionPointImpl("AP1", p1);
AttractionPoint ap1 = new AttractionPoint("AP1", p1);
ap1.setRadius(100);
attractionPoints.add(ap1);
addAttractionPoint(ap1);
PositionVector p2 = new PositionVector(x2, y2);
IAttractionPoint ap2 = new AttractionPointImpl("AP2", p2);
AttractionPoint ap2 = new AttractionPoint("AP2", p2);
ap2.setRadius(100);
attractionPoints.add(ap2);
addAttractionPoint(ap2);
}
......
......@@ -30,7 +30,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ISocialGroupMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.SocialGroupMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.BasicAttractionPoint;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.hostcount.HostAtAttractionPointCounter;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.MovementGroupContainer;
......@@ -293,7 +293,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
IAttractionPoint result = null;
long maxDuration = 0;
for(IAttractionPoint ap : IAttractionGenerator.attractionPoints) {
for(IAttractionPoint ap : movementModel.getAllAttractionPoints()) {
for(SimLocationActuator host : HostAtAttractionPointCounter.getHostsOfAttractionPoint(ap, movementModel.getAllLocationActuators())) {
INodeID id = host.getHost().getId();
long duration = stayDuration.get(id).getA();
......@@ -311,7 +311,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
protected IAttractionPoint getAttractionPointWithMostHosts() {
IAttractionPoint apCandidate = null;
int size = 0;
for(IAttractionPoint ap : IAttractionGenerator.attractionPoints) {
for(IAttractionPoint ap : movementModel.getAllAttractionPoints()) {
int numberOfHostsInAP = HostAtAttractionPointCounter.getHostCountOfAttractionPoint(ap, movementModel.getAllLocationActuators());
if(numberOfHostsInAP > size) {
apCandidate = ap;
......
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