Commit 0c80da45 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Removed deprecated `Position`-Interface

parent db566de9
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
package de.tud.kom.p2psim.impl.topology.movement.modular; package de.tud.kom.p2psim.impl.topology.movement.modular;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
...@@ -32,13 +30,13 @@ import java.util.Set; ...@@ -32,13 +30,13 @@ import java.util.Set;
import java.util.Vector; import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementListener; import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy; import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel; import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.CsvMovement; import de.tud.kom.p2psim.impl.topology.movement.CsvMovement;
import de.tud.kom.p2psim.impl.topology.movement.NoMovement; import de.tud.kom.p2psim.impl.topology.movement.NoMovement;
...@@ -49,6 +47,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modular.transition.FixedAssignme ...@@ -49,6 +47,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modular.transition.FixedAssignme
import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy; import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Either;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
...@@ -118,7 +117,8 @@ public class ModularMovementModel implements MovementModel, EventHandler { ...@@ -118,7 +117,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
private Random rand; private Random rand;
public ModularMovementModel() { public ModularMovementModel() {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
this.rand = Randoms.getRandom(ModularMovementModel.class); this.rand = Randoms.getRandom(ModularMovementModel.class);
// scheduling initalization! // scheduling initalization!
...@@ -146,14 +146,15 @@ public class ModularMovementModel implements MovementModel, EventHandler { ...@@ -146,14 +146,15 @@ public class ModularMovementModel implements MovementModel, EventHandler {
} }
// setWayPointModel // setWayPointModel
localMovementStrategy.setObstacleModel(Topology.getTopology() localMovementStrategy.setObstacleModel(Binder
.getObstacleModel()); .getComponentOrNull(Topology.class).getObstacleModel());
localMovementStrategy.setWaypointModel(Topology.getTopology() localMovementStrategy.setWaypointModel(Binder
.getWaypointModel()); .getComponentOrNull(Topology.class).getWaypointModel());
if (movementModel instanceof AbstractWaypointMovementModel) { if (movementModel instanceof AbstractWaypointMovementModel) {
AbstractWaypointMovementModel awmm = (AbstractWaypointMovementModel) movementModel; AbstractWaypointMovementModel awmm = (AbstractWaypointMovementModel) movementModel;
awmm.setWaypointModel(Topology.getTopology().getWaypointModel()); awmm.setWaypointModel(Binder.getComponentOrNull(Topology.class)
.getWaypointModel());
} }
List<AttractionPoint> attractionPoints = attractionGenerator List<AttractionPoint> attractionPoints = attractionGenerator
...@@ -194,7 +195,8 @@ public class ModularMovementModel implements MovementModel, EventHandler { ...@@ -194,7 +195,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
"AttractionGenerator is missing in ModularMovementModel!"); "AttractionGenerator is missing in ModularMovementModel!");
} }
if (movementModel instanceof AbstractWaypointMovementModel if (movementModel instanceof AbstractWaypointMovementModel
&& Topology.getTopology().getWaypointModel() == null) { && Binder.getComponentOrNull(Topology.class)
.getWaypointModel() == null) {
throw new ConfigurationException( throw new ConfigurationException(
"Missing WaypointModel for the ModuloarMovementModel.movementModel"); "Missing WaypointModel for the ModuloarMovementModel.movementModel");
} }
......
...@@ -26,8 +26,9 @@ import java.io.IOException; ...@@ -26,8 +26,9 @@ import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
...@@ -57,7 +58,8 @@ public class CsvAttractionGenerator implements AttractionGenerator { ...@@ -57,7 +58,8 @@ public class CsvAttractionGenerator implements AttractionGenerator {
*/ */
@XMLConfigurableConstructor({ "placementFile" }) @XMLConfigurableConstructor({ "placementFile" })
public CsvAttractionGenerator(String placementFile) { public CsvAttractionGenerator(String placementFile) {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPointsPositions = new LinkedList<PositionVector>(); attractionPointsPositions = new LinkedList<PositionVector>();
this.file = placementFile; this.file = placementFile;
} }
......
...@@ -25,8 +25,9 @@ import java.util.Random; ...@@ -25,8 +25,9 @@ import java.util.Random;
import java.util.Vector; import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
/** /**
...@@ -54,7 +55,8 @@ public class RandomAttractionGenerator implements AttractionGenerator { ...@@ -54,7 +55,8 @@ public class RandomAttractionGenerator implements AttractionGenerator {
public RandomAttractionGenerator() { public RandomAttractionGenerator() {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class); this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
this.worldDimension = Topology.getWorldDimension(); this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
} }
@Override @Override
......
...@@ -36,12 +36,13 @@ import java.util.Vector; ...@@ -36,12 +36,13 @@ import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent; import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.social.SocialView; import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoint; import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
...@@ -121,7 +122,8 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -121,7 +122,8 @@ public class SocialTransitionStrategy implements TransitionStrategy,
"SocialId is not set, to find the needed SocialView!"); "SocialId is not set, to find the needed SocialView!");
} }
socialView = Topology.getTopology().getSocialView(socialId); socialView = Binder.getComponentOrNull(Topology.class)
.getSocialView(socialId);
if (socialView == null) { if (socialView == null) {
throw new ConfigurationException( throw new ConfigurationException(
...@@ -133,7 +135,8 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -133,7 +135,8 @@ public class SocialTransitionStrategy implements TransitionStrategy,
"MinPauseTime should be smaller then maxPauseTime."); "MinPauseTime should be smaller then maxPauseTime.");
} }
worldDimension = Topology.getWorldDimension(); worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
init = true; init = true;
} }
} }
...@@ -163,8 +166,9 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -163,8 +166,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
// assignment.. // assignment..
AttractionPoint nearest = aPoints.iterator().next(); AttractionPoint nearest = aPoints.iterator().next();
for (AttractionPoint aPoint : aPoints) { for (AttractionPoint aPoint : aPoints) {
if (nearest.getRealPosition().getDistance(ms.getRealPosition()) > aPoint if (nearest.getRealPosition()
.getRealPosition().getDistance(ms.getRealPosition())) { .distanceTo(ms.getRealPosition()) > aPoint.getRealPosition()
.distanceTo(ms.getRealPosition())) {
nearest = aPoint; nearest = aPoint;
} }
} }
...@@ -242,7 +246,7 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -242,7 +246,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends, List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) { List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
double distance = ms.getRealPosition() double distance = ms.getRealPosition()
.getDistance(ap.getRealPosition()); .distanceTo(ap.getRealPosition());
double distanceScore = 1 - (distance / worldDimension.getLength()); double distanceScore = 1 - (distance / worldDimension.getLength());
double clusterScore = 0; double clusterScore = 0;
...@@ -354,8 +358,9 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -354,8 +358,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
AttractionPoint nearest = aps.iterator().next(); AttractionPoint nearest = aps.iterator().next();
for (AttractionPoint aPoint : aps) { for (AttractionPoint aPoint : aps) {
if (nearest.getRealPosition().getDistance(ms.getRealPosition()) > aPoint if (nearest.getRealPosition()
.getRealPosition().getDistance(ms.getRealPosition()) .distanceTo(ms.getRealPosition()) > aPoint.getRealPosition()
.distanceTo(ms.getRealPosition())
&& !assignments.get(ms).equals(aPoint)) { && !assignments.get(ms).equals(aPoint)) {
nearest = aPoint; nearest = aPoint;
} }
...@@ -368,8 +373,9 @@ public class SocialTransitionStrategy implements TransitionStrategy, ...@@ -368,8 +373,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
AttractionPoint nearest = fps.iterator().next(); AttractionPoint nearest = fps.iterator().next();
for (AttractionPoint aPoint : fps) { for (AttractionPoint aPoint : fps) {
if (nearest.getRealPosition().getDistance(ms.getRealPosition()) > aPoint if (nearest.getRealPosition()
.getRealPosition().getDistance(ms.getRealPosition()) .distanceTo(ms.getRealPosition()) > aPoint.getRealPosition()
.distanceTo(ms.getRealPosition())
&& !assignments.get(ms).equals(aPoint)) { && !assignments.get(ms).equals(aPoint)) {
nearest = aPoint; nearest = aPoint;
} }
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm; package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import de.tud.kom.p2psim.impl.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
/** /**
* *
...@@ -29,17 +30,20 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza ...@@ -29,17 +30,20 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
* @version 1.0, Nov 3, 2015 * @version 1.0, Nov 3, 2015
*/ */
public class GPSCalculation { public class GPSCalculation {
private static double latCenter; private static double latCenter;
private static double lonCenter; private static double lonCenter;
private static int zoom; private static int zoom;
private static double scaleFactor; private static double scaleFactor;
public GPSCalculation() { public GPSCalculation() {
} }
private void setScaleFactor() { private void setScaleFactor() {
//this.scaleFactor = Math.pow(2.0d, (13 - zoom)); // this.scaleFactor = Math.pow(2.0d, (13 - zoom));
/* /*
* BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this * BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this
* case, 1px == 1m) - this way, the world-size specified in the configs * case, 1px == 1m) - this way, the world-size specified in the configs
...@@ -49,47 +53,51 @@ public class GPSCalculation { ...@@ -49,47 +53,51 @@ public class GPSCalculation {
// 17: 2, 16: 1, 15: 0.5, 14: 0.25 // 17: 2, 16: 1, 15: 0.5, 14: 0.25
VisualizationInjector.setScale(Math.pow(2.0d, (zoom - 16))); VisualizationInjector.setScale(Math.pow(2.0d, (zoom - 16)));
} }
public static double getLatCenter() { public static double getLatCenter() {
return latCenter; return latCenter;
} }
public static double getLonCenter() { public static double getLonCenter() {
return lonCenter; return lonCenter;
} }
public static int getZoom() { public static int getZoom() {
return zoom; return zoom;
} }
public static double getLatUpper() { public static double getLatUpper() {
return latCenter + scaleFactor * 0.027613 return latCenter + scaleFactor * 0.027613 * Binder
* Topology.getWorldDimension().getX() / 1000; .getComponentOrNull(Topology.class).getWorldDimensions().getX()
/ 1000;
} }
public static double getLatLower() { public static double getLatLower() {
return latCenter - scaleFactor * 0.027613 return latCenter - scaleFactor * 0.027613 * Binder
* Topology.getWorldDimension().getX() / 1000; .getComponentOrNull(Topology.class).getWorldDimensions().getX()
/ 1000;
} }
public static double getLonLeft() { public static double getLonLeft() {
return lonCenter - scaleFactor * 0.0419232 return lonCenter - scaleFactor * 0.0419232 * Binder
* Topology.getWorldDimension().getY() / 1000; .getComponentOrNull(Topology.class).getWorldDimensions().getY()
/ 1000;
} }
public static double getLonRight() { public static double getLonRight() {
return lonCenter + scaleFactor * 0.0419232 return lonCenter + scaleFactor * 0.0419232 * Binder
* Topology.getWorldDimension().getY() / 1000; .getComponentOrNull(Topology.class).getWorldDimensions().getY()
/ 1000;
} }
public void setLatCenter(double latCenter) { public void setLatCenter(double latCenter) {
this.latCenter = latCenter; this.latCenter = latCenter;
} }
public void setLonCenter(double lonCenter) { public void setLonCenter(double lonCenter) {
this.lonCenter = lonCenter; this.lonCenter = lonCenter;
} }
public void setZoom(int zoom) { public void setZoom(int zoom) {
this.zoom = zoom; this.zoom = zoom;
setScaleFactor(); setScaleFactor();
......
...@@ -32,19 +32,21 @@ import java.util.Vector; ...@@ -32,19 +32,21 @@ import java.util.Vector;
import javax.swing.JComponent; import javax.swing.JComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementListener; import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy; import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology; import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization; import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy; import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Either;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
...@@ -113,7 +115,8 @@ public class ModularMovementModel implements MovementModel, EventHandler { ...@@ -113,7 +115,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
private Random rand; private Random rand;
public ModularMovementModel() { public ModularMovementModel() {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
this.rand = Randoms.getRandom(ModularMovementModel.class); this.rand = Randoms.getRandom(ModularMovementModel.class);
// scheduling initalization! // scheduling initalization!
...@@ -136,10 +139,10 @@ public class ModularMovementModel implements MovementModel, EventHandler { ...@@ -136,10 +139,10 @@ public class ModularMovementModel implements MovementModel, EventHandler {
checkConfiguration(); checkConfiguration();
// setWayPointModel // setWayPointModel
localMovementStrategy.setObstacleModel(Topology.getTopology() localMovementStrategy.setObstacleModel(Binder
.getObstacleModel()); .getComponentOrNull(Topology.class).getObstacleModel());
localMovementStrategy.setWaypointModel(Topology.getTopology() localMovementStrategy.setWaypointModel(Binder
.getWaypointModel()); .getComponentOrNull(Topology.class).getWaypointModel());
List<AttractionPoint> attractionPoints = attractionGenerator.getAttractionPoints(); List<AttractionPoint> attractionPoints = attractionGenerator.getAttractionPoints();
transition.setAttractionPoints(attractionPoints); transition.setAttractionPoints(attractionPoints);
......
...@@ -31,9 +31,10 @@ import org.json.JSONArray; ...@@ -31,9 +31,10 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tudarmstadt.maki.simonstrator.api.Binder;
/** /**
* Generates attraction points out of real data from osm * Generates attraction points out of real data from osm
...@@ -62,7 +63,8 @@ public class JSONAttractionGenerator implements IAttractionGenerator { ...@@ -62,7 +63,8 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
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 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 JSONAttractionGenerator() { public JSONAttractionGenerator() {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPoints = new LinkedList<AttractionPoint>(); attractionPoints = new LinkedList<AttractionPoint>();
latLeft = GPSCalculation.getLatLower(); latLeft = GPSCalculation.getLatLower();
......
...@@ -36,9 +36,10 @@ import org.json.JSONArray; ...@@ -36,9 +36,10 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tudarmstadt.maki.simonstrator.api.Binder;
/** /**
* Generates attraction points out of real data from osm * Generates attraction points out of real data from osm
...@@ -65,7 +66,8 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator { ...@@ -65,7 +66,8 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
private double lonRight; //Values from -180 to 180 private double lonRight; //Values from -180 to 180
public OnlineJSONAttractionGenerator() { public OnlineJSONAttractionGenerator() {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPoints = new LinkedList<AttractionPoint>(); attractionPoints = new LinkedList<AttractionPoint>();
latLeft = GPSCalculation.getLatLower(); latLeft = GPSCalculation.getLatLower();
......
...@@ -36,12 +36,14 @@ import java.util.Vector; ...@@ -36,12 +36,14 @@ import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent; import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.social.SocialView; import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology; import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
...@@ -121,7 +123,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -121,7 +123,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
"SocialId is not set, to find the needed SocialView!"); "SocialId is not set, to find the needed SocialView!");
} }
socialView = Topology.getTopology().getSocialView(socialId); socialView = Binder.getComponentOrNull(Topology.class)
.getSocialView(socialId);
if (socialView == null) { if (socialView == null) {
throw new ConfigurationException( throw new ConfigurationException(
...@@ -133,7 +136,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -133,7 +136,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
"MinPauseTime should be smaller then maxPauseTime."); "MinPauseTime should be smaller then maxPauseTime.");
} }
worldDimension = Topology.getWorldDimension(); worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
init = true; init = true;
} }
} }
...@@ -165,8 +169,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -165,8 +169,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
// assignment.. // assignment..
AttractionPoint nearest = aPoints.iterator().next(); AttractionPoint nearest = aPoints.iterator().next();
for (AttractionPoint aPoint : aPoints) { for (AttractionPoint aPoint : aPoints) {
if (nearest.getRealPosition().getDistance(ms.getRealPosition()) > aPoint if (nearest.getRealPosition()
.getRealPosition().getDistance(ms.getRealPosition())) { .distanceTo(ms.getRealPosition()) > aPoint.getRealPosition()
.distanceTo(ms.getRealPosition())) {
nearest = aPoint; nearest = aPoint;
} }
} }
...@@ -243,8 +248,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -243,8 +248,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private double score(MovementSupported ms, AttractionPoint ap, private double score(MovementSupported ms, AttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends, List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) { List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
double distance = ms.getRealPosition() double distance = ms.getRealPosition().distanceTo(ap.getRealPosition());
.getDistance(ap.getRealPosition());
double distanceScore = 1 - (distance / worldDimension.getLength()); double distanceScore = 1 - (distance / worldDimension.getLength());
double clusterScore = 0; double clusterScore = 0;
......
...@@ -150,7 +150,7 @@ public class PolygonObstacle extends AbstractObstacle { ...@@ -150,7 +150,7 @@ public class PolygonObstacle extends AbstractObstacle {
/* /*
* Adding a bit of greedy decisions, to not always use the poly-methods * Adding a bit of greedy decisions, to not always use the poly-methods
*/ */
double dist = a.getDistance(b); double dist = a.distanceTo(b);
if (a.getX() + dist < minX || a.getX() - dist > maxX if (a.getX() + dist < minX || a.getX() - dist > maxX
|| a.getY() + dist < minY || a.getY() - dist > maxY) { || a.getY() + dist < minY || a.getY() - dist > maxY) {
return false; return false;
......
...@@ -27,7 +27,6 @@ import java.util.List; ...@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.linklayer.LinkLayer; import de.tud.kom.p2psim.api.linklayer.LinkLayer;
import de.tud.kom.p2psim.api.linklayer.mac.Link; import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress; import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
...@@ -43,6 +42,7 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView; ...@@ -43,6 +42,7 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* To ease implementation of new {@link TopologyView}s, this class provides * To ease implementation of new {@link TopologyView}s, this class provides
...@@ -475,13 +475,13 @@ public abstract class AbstractTopologyView<L extends DefaultLink> implements ...@@ -475,13 +475,13 @@ public abstract class AbstractTopologyView<L extends DefaultLink> implements
} }
@Override @Override
public Position getPosition(MacAddress address) { public Location getPosition(MacAddress address) {
return getCachedPosition(address); return getCachedPosition(address);
} }
@Override @Override
public double getDistance(MacAddress addressA, MacAddress addressB) { public double getDistance(MacAddress addressA, MacAddress addressB) {
return getCachedPosition(addressA).getDistance( return getCachedPosition(addressA)
getCachedPosition(addressB)); .distanceTo(getCachedPosition(addressB));
} }
} }
...@@ -231,7 +231,7 @@ public class RangedTopologyView extends AbstractTopologyView<RangedLink> { ...@@ -231,7 +231,7 @@ public class RangedTopologyView extends AbstractTopologyView<RangedLink> {
@Override @Override
protected void updateOutdatedLink(RangedLink link) { protected void updateOutdatedLink(RangedLink link) {
link.updateNodeDistance(getCachedPosition(link.getSource()) link.updateNodeDistance(getCachedPosition(link.getSource())
.getDistance(getCachedPosition(link.getDestination()))); .distanceTo(getCachedPosition(link.getDestination())));
/* /*
* Update latency and drop rate - note: it depends on the actual * Update latency and drop rate - note: it depends on the actual
......
...@@ -55,18 +55,17 @@ import javax.swing.Timer; ...@@ -55,18 +55,17 @@ import javax.swing.Timer;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.linklayer.mac.Link; import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress; import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer; import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType; import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent; import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel; import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.ComponentToggler; import de.tud.kom.p2psim.impl.topology.views.visualization.ui.ComponentToggler;
...@@ -78,7 +77,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.world.StrongWaypointC ...@@ -78,7 +77,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.world.StrongWaypointC
import de.tud.kom.p2psim.impl.topology.views.visualization.world.TopologyComponentVis; import de.tud.kom.p2psim.impl.topology.views.visualization.world.TopologyComponentVis;
import de.tud.kom.p2psim.impl.topology.views.visualization.world.WeakWaypointComponentVis; import de.tud.kom.p2psim.impl.topology.views.visualization.world.WeakWaypointComponentVis;
import de.tud.kom.p2psim.impl.util.NotSupportedException; import de.tud.kom.p2psim.impl.util.NotSupportedException;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* A very basic visualization of a Topology (ie. positioning and movement), just * A very basic visualization of a Topology (ie. positioning and movement), just
...@@ -126,8 +127,10 @@ public class VisualizationTopologyView extends JFrame implements TopologyView, ...@@ -126,8 +127,10 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
* *
*/ */
public VisualizationTopologyView() { public VisualizationTopologyView() {
WORLD_X = (int) Topology.getWorldDimension().getX(); WORLD_X = (int) Binder.getComponentOrNull(Topology.class)
WORLD_Y = (int) Topology.getWorldDimension().getY(); .getWorldDimensions().getX();
WORLD_Y = (int) Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY();
worldPanel = new WorldPanel(); worldPanel = new WorldPanel();
visManager = new ComponentVisManager(worldPanel); visManager = new ComponentVisManager(worldPanel);
...@@ -668,7 +671,7 @@ public class VisualizationTopologyView extends JFrame implements TopologyView, ...@@ -668,7 +671,7 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
} }
@Override @Override
public Position getPosition(MacAddress address) { public Location getPosition(MacAddress address) {
throw new NotSupportedException(); throw new NotSupportedException();
} }
......
...@@ -179,7 +179,7 @@ public class SocialViewComponentVis extends JComponent implements ...@@ -179,7 +179,7 @@ public class SocialViewComponentVis extends JComponent implements
public void mouseClicked(int x, int y) { public void mouseClicked(int x, int y) {
List<SimHost> inNear = new Vector<SimHost>(); List<SimHost> inNear = new Vector<SimHost>();
for (Entry<SimHost, PositionVector> e : posVecs.entrySet()) { for (Entry<SimHost, PositionVector> e : posVecs.entrySet()) {
if (e.getValue().getDistance(new PositionVector(x, y)) < 4) { if (e.getValue().distanceTo(new PositionVector(x, y)) < 4) {
inNear.add(e.getKey()); inNear.add(e.getKey());
} }
} }
......
...@@ -26,7 +26,6 @@ import java.util.HashMap; ...@@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress; import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer; import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
...@@ -43,6 +42,9 @@ import de.tud.kom.p2psim.impl.topology.views.RangedLink; ...@@ -43,6 +42,9 @@ import de.tud.kom.p2psim.impl.topology.views.RangedLink;
import de.tud.kom.p2psim.impl.topology.views.RangedTopologyView; import de.tud.kom.p2psim.impl.topology.views.RangedTopologyView;
import de.tud.kom.p2psim.impl.topology.views.wifi.phy.InterferenceHelper; import de.tud.kom.p2psim.impl.topology.views.wifi.phy.InterferenceHelper;
import de.tudarmstadt.maki.simonstrator.api.Message; import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
...@@ -266,7 +268,7 @@ public class WifiTopologyView extends RangedTopologyView { ...@@ -266,7 +268,7 @@ public class WifiTopologyView extends RangedTopologyView {
* The {@link MacAddress} of the source, which stats this * The {@link MacAddress} of the source, which stats this
* transfer * transfer
*/ */
public void addTransfer(long start, long end, Position sourcePosition, public void addTransfer(long start, long end, Location sourcePosition,
double txPowerDbm, Message id, WifiMode dataMode, double txPowerDbm, Message id, WifiMode dataMode,
WifiPreamble preamble, SimHost host, MacAddress sourceAddress) { WifiPreamble preamble, SimHost host, MacAddress sourceAddress) {
interferenceHelper.addTransfer(start, end, sourcePosition, txPowerDbm, interferenceHelper.addTransfer(start, end, sourcePosition, txPowerDbm,
...@@ -293,7 +295,7 @@ public class WifiTopologyView extends RangedTopologyView { ...@@ -293,7 +295,7 @@ public class WifiTopologyView extends RangedTopologyView {
* The sourceAddress of this interference (It will be used the * The sourceAddress of this interference (It will be used the
* neighborhood of this peer, to inform about carrier sensing). * neighborhood of this peer, to inform about carrier sensing).
*/ */
public void addInterference(long start, long end, Position sourcePosition, public void addInterference(long start, long end, Location sourcePosition,
double txPowerDbm, WifiMode dataMode, MacAddress sourceAddress) { double txPowerDbm, WifiMode dataMode, MacAddress sourceAddress) {
interferenceHelper.addInterference(start, end, sourcePosition, interferenceHelper.addInterference(start, end, sourcePosition,
txPowerDbm, dataMode, sourceAddress); txPowerDbm, dataMode, sourceAddress);
...@@ -306,7 +308,7 @@ public class WifiTopologyView extends RangedTopologyView { ...@@ -306,7 +308,7 @@ public class WifiTopologyView extends RangedTopologyView {
* @param msg * @param msg
* The message which was added as interference (or rather as ID) * The message which was added as interference (or rather as ID)
* with * with
* {@link WifiTopologyView#addInterference(long, long, Position, double, WifiMode, MacAddress)} * {@link WifiTopologyView#addInterference(long, long, Location, double, WifiMode, MacAddress)}
* to the {@link InterferenceHelper}. * to the {@link InterferenceHelper}.
* @param pos * @param pos
* The position for that the PER should be calculated for this * The position for that the PER should be calculated for this
...@@ -314,7 +316,7 @@ public class WifiTopologyView extends RangedTopologyView { ...@@ -314,7 +316,7 @@ public class WifiTopologyView extends RangedTopologyView {
* @return The Packet Error Rate (PER) for the message at the given * @return The Packet Error Rate (PER) for the message at the given
* Position. * Position.
*/ */
public double calculatePer(Message msg, Position pos) { public double calculatePer(Message msg, Location pos) {
return interferenceHelper.calculatePer(msg, pos); return interferenceHelper.calculatePer(msg, pos);
} }
...@@ -375,8 +377,11 @@ public class WifiTopologyView extends RangedTopologyView { ...@@ -375,8 +377,11 @@ public class WifiTopologyView extends RangedTopologyView {
rxSensitivityDbm); rxSensitivityDbm);
double satRange = interferenceHelper.calculateMaximalRadius( double satRange = interferenceHelper.calculateMaximalRadius(
maxTxPowerDbm, satDbm); maxTxPowerDbm, satDbm);
// System.out.println("satRange: " + satRange + " csRange: " + csRange System.out.println("satRange: " + satRange + " csRange: " + csRange
// + " range: " + range); + " range: " + range);
Monitor.log(WifiTopologyView.class, Level.INFO,
"WiFi underlay ranges: satRange: " + satRange + " csRange: "
+ csRange + " range: " + range);
setRange(range); setRange(range);
setCSRange(csRange); setCSRange(csRange);
......
...@@ -28,7 +28,6 @@ import java.util.List; ...@@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress; import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.topology.views.wifi.phy.ErrorRateModel; import de.tud.kom.p2psim.api.topology.views.wifi.phy.ErrorRateModel;
...@@ -46,6 +45,7 @@ import de.tudarmstadt.maki.simonstrator.api.Message; ...@@ -46,6 +45,7 @@ import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* This class is the Interference Helper, which process for one * This class is the Interference Helper, which process for one
...@@ -176,13 +176,13 @@ public class InterferenceHelper implements EventHandler { ...@@ -176,13 +176,13 @@ public class InterferenceHelper implements EventHandler {
* @param end * @param end
* The end time of this interference in microseconds * The end time of this interference in microseconds
* @param sourcePosition * @param sourcePosition
* The {@link Position} of the source of this interference * The {@link Location} of the source of this interference
* @param txPowerDbm * @param txPowerDbm
* The signal power of this interference in dBm. * The signal power of this interference in dBm.
*/ */
@Deprecated @Deprecated
// because sourceAddress should be not null! // because sourceAddress should be not null!
public void addInterference(long start, long end, Position sourcePosition, public void addInterference(long start, long end, Location sourcePosition,
double txPowerDbm) { double txPowerDbm) {
addInterference(start, end, sourcePosition, txPowerDbm, null, null); addInterference(start, end, sourcePosition, txPowerDbm, null, null);
} }
...@@ -199,7 +199,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -199,7 +199,7 @@ public class InterferenceHelper implements EventHandler {
* @param end * @param end
* The end time of this interference in microseconds * The end time of this interference in microseconds
* @param sourcePosition * @param sourcePosition
* The {@link Position} of the source of this interference * The {@link Location} of the source of this interference
* @param txPowerDbm * @param txPowerDbm
* The signal power of this interference in dBm. * The signal power of this interference in dBm.
* @param dataMode * @param dataMode
...@@ -208,7 +208,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -208,7 +208,7 @@ public class InterferenceHelper implements EventHandler {
* The {@link MacAddress} of the node, which are the originator * The {@link MacAddress} of the node, which are the originator
* of this interference. * of this interference.
*/ */
public void addInterference(long start, long end, Position sourcePosition, public void addInterference(long start, long end, Location sourcePosition,
double txPowerDbm, WifiMode dataMode, MacAddress sourceAddress) { double txPowerDbm, WifiMode dataMode, MacAddress sourceAddress) {
addTransfer(start, end, sourcePosition, txPowerDbm, null, dataMode, addTransfer(start, end, sourcePosition, txPowerDbm, null, dataMode,
null, null, sourceAddress); null, null, sourceAddress);
...@@ -225,7 +225,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -225,7 +225,7 @@ public class InterferenceHelper implements EventHandler {
* @param end * @param end
* The end time of this transfer in microseconds * The end time of this transfer in microseconds
* @param sourcePosition * @param sourcePosition
* The {@link Position} of the source of this transfer * The {@link Location} of the source of this transfer
* @param txPowerDbm * @param txPowerDbm
* The signal power of this transfer in dBm. * The signal power of this transfer in dBm.
* @param id * @param id
...@@ -241,7 +241,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -241,7 +241,7 @@ public class InterferenceHelper implements EventHandler {
* The {@link MacAddress} of the node, which are the originator * The {@link MacAddress} of the node, which are the originator
* of this transfer. * of this transfer.
*/ */
public void addTransfer(long start, long end, Position sourcePosition, public void addTransfer(long start, long end, Location sourcePosition,
double txPowerDbm, Message id, WifiMode dataMode, double txPowerDbm, Message id, WifiMode dataMode,
WifiPreamble preamble, SimHost host, MacAddress sourceAddress) { WifiPreamble preamble, SimHost host, MacAddress sourceAddress) {
if (start < Time.getCurrentTime()) { if (start < Time.getCurrentTime()) {
...@@ -252,8 +252,8 @@ public class InterferenceHelper implements EventHandler { ...@@ -252,8 +252,8 @@ public class InterferenceHelper implements EventHandler {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The start time is equal or greater than the end time!"); "The start time is equal or greater than the end time!");
} }
Interference interference = new Interference(start, end, Interference interference = new Interference(start, end, sourcePosition,
sourcePosition.clone(), txPowerDbm, id, dataMode, preamble, txPowerDbm, id, dataMode, preamble,
host, sourceAddress); host, sourceAddress);
addInterference(interference); addInterference(interference);
...@@ -336,7 +336,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -336,7 +336,7 @@ public class InterferenceHelper implements EventHandler {
/** /**
* Calculates the Packet Error Rate for this ID (the Message) and the given * Calculates the Packet Error Rate for this ID (the Message) and the given
* {@link Position}. The position is used to calculate the receive power and * {@link Location}. The position is used to calculate the receive power and
* the resulting SNR (Signal to noise Ratio).<br> * the resulting SNR (Signal to noise Ratio).<br>
* The transfer information will be got with the message. In this * The transfer information will be got with the message. In this
* information will be stored all interferences, which has influence for the * information will be stored all interferences, which has influence for the
...@@ -354,7 +354,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -354,7 +354,7 @@ public class InterferenceHelper implements EventHandler {
* @return The Packet Error Rate for this Message at the given * @return The Packet Error Rate for this Message at the given
* {@link Position}. * {@link Position}.
*/ */
public double calculatePer(Message id, Position rxPos) { public double calculatePer(Message id, Location rxPos) {
Interference transfer = transfers.get(id); Interference transfer = transfers.get(id);
if (transfer == null) { if (transfer == null) {
Monitor.log( Monitor.log(
...@@ -520,7 +520,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -520,7 +520,7 @@ public class InterferenceHelper implements EventHandler {
/** /**
* Calculates the actually Interference noise in Watt for a host. The host * Calculates the actually Interference noise in Watt for a host. The host
* will be used, to use his {@link Position}, and to ignore interferences * will be used, to use his {@link Location}, and to ignore interferences
* from him. * from him.
* *
* @param host * @param host
...@@ -536,15 +536,15 @@ public class InterferenceHelper implements EventHandler { ...@@ -536,15 +536,15 @@ public class InterferenceHelper implements EventHandler {
/** /**
* Calculates the actually interference noise in Watt at the given * Calculates the actually interference noise in Watt at the given
* {@link Position}. The output of can be different to the method * {@link Location}. The output of can be different to the method
* {@link InterferenceHelper#calculateNoiseInterferenceW(SimHost)}, because no * {@link InterferenceHelper#calculateNoiseInterferenceW(SimHost)}, because
* interference will be leave out. * no interference will be leave out.
* *
* @param point * @param point
* The position for that the interference noise is requested * The position for that the interference noise is requested
* @return The actually interference noise in Watt at the given Position. * @return The actually interference noise in Watt at the given Position.
*/ */
public double calculateNoiseInterferenceW(Position point) { public double calculateNoiseInterferenceW(Location point) {
return calculateNoiseInterferenceW(null, point); return calculateNoiseInterferenceW(null, point);
} }
...@@ -562,7 +562,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -562,7 +562,7 @@ public class InterferenceHelper implements EventHandler {
* @return The actually interference noise in Watt at the given Position * @return The actually interference noise in Watt at the given Position
* without the interferences of the host. * without the interferences of the host.
*/ */
public double calculateNoiseInterferenceW(SimHost host, Position point) { public double calculateNoiseInterferenceW(SimHost host, Location point) {
double noiseInterferenceW = 0; double noiseInterferenceW = 0;
for (Interference i : interferences) { for (Interference i : interferences) {
if (i.getStartTime() <= Time.getCurrentTime() if (i.getStartTime() <= Time.getCurrentTime()
...@@ -680,7 +680,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -680,7 +680,7 @@ public class InterferenceHelper implements EventHandler {
private final NIChangeTime niChangeEnd; private final NIChangeTime niChangeEnd;
private final Position sourcePosition; private final Location sourcePosition;
private final double txPowerDbm; private final double txPowerDbm;
...@@ -701,7 +701,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -701,7 +701,7 @@ public class InterferenceHelper implements EventHandler {
private List<InterferenceHelper.NIChangeTime> niChangeList = new Vector<InterferenceHelper.NIChangeTime>(); private List<InterferenceHelper.NIChangeTime> niChangeList = new Vector<InterferenceHelper.NIChangeTime>();
public Interference(long startTime, long endTime, public Interference(long startTime, long endTime,
Position sourcePosition, double txPowerDbm, Message id, Location sourcePosition, double txPowerDbm, Message id,
WifiMode dataMode, WifiPreamble preamble, SimHost host, WifiMode dataMode, WifiPreamble preamble, SimHost host,
MacAddress sourceAddress) { MacAddress sourceAddress) {
this.niChangeStart = new NIChangeTime(startTime, false, this); this.niChangeStart = new NIChangeTime(startTime, false, this);
...@@ -733,7 +733,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -733,7 +733,7 @@ public class InterferenceHelper implements EventHandler {
return niChangeEnd.getTime(); return niChangeEnd.getTime();
} }
public Position getSourcePosition() { public Location getSourcePosition() {
return sourcePosition; return sourcePosition;
} }
...@@ -757,20 +757,21 @@ public class InterferenceHelper implements EventHandler { ...@@ -757,20 +757,21 @@ public class InterferenceHelper implements EventHandler {
return host; return host;
} }
public double getRxPowerDbm(Position pos) { public double getRxPowerDbm(Location pos) {
return getLossModel().getRxPowerDbm(getTxPowerDbm(), return getLossModel().getRxPowerDbm(getTxPowerDbm(),
sourcePosition.getDistance(pos)) sourcePosition.distanceTo(pos))
+ getRxGainDbm(); + getRxGainDbm();
} }
public double getRxPowerW(Position pos) { public double getRxPowerW(Location pos) {
double rxPowerdbm = getRxPowerDbm(pos); double rxPowerdbm = getRxPowerDbm(pos);
return PropagationLossModel.dbmToW(rxPowerdbm); return PropagationLossModel.dbmToW(rxPowerdbm);
} }
public void addInterference(Interference interference) { public void addInterference(Interference interference) {
if (!isUnknown()) { if (!isUnknown()) {
double distance = this.sourcePosition.getDistance(interference double distance = this.sourcePosition
.distanceTo(interference
.getSourcePosition()); .getSourcePosition());
double maxRadius = calculateMaximalSatRadius(interference double maxRadius = calculateMaximalSatRadius(interference
.getTxPowerDbm()); .getTxPowerDbm());
...@@ -874,7 +875,7 @@ public class InterferenceHelper implements EventHandler { ...@@ -874,7 +875,7 @@ public class InterferenceHelper implements EventHandler {
* @return It is positive, if an interference start, and negative if the * @return It is positive, if an interference start, and negative if the
* interference ends. * interference ends.
*/ */
public double getRxPowerWChange(Position rxPos) { public double getRxPowerWChange(Location rxPos) {
double change = this.getInterference().getRxPowerW(rxPos); double change = this.getInterference().getRxPowerW(rxPos);
if (this.isEndOfTransmission()) { if (this.isEndOfTransmission()) {
change *= -1; change *= -1;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
package de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss; package de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel; import de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* The Friis Propagation Loss Model: * The Friis Propagation Loss Model:
...@@ -81,8 +81,8 @@ public class FriisPropagationLossModel extends PropagationLossModel { ...@@ -81,8 +81,8 @@ public class FriisPropagationLossModel extends PropagationLossModel {
private double minDistance = 0.5d; private double minDistance = 0.5d;
@Override @Override
public double getRxPowerDbm(double txPowerDbm, Position a, Position b) { public double getRxPowerDbm(double txPowerDbm, Location a, Location b) {
double distance = a.getDistance(b); double distance = a.distanceTo(b);
return getRxPowerDbm(txPowerDbm, distance); return getRxPowerDbm(txPowerDbm, distance);
} }
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
package de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss; package de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel; import de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* *
...@@ -78,8 +78,8 @@ public class LogDistancePropagationLossModel extends PropagationLossModel { ...@@ -78,8 +78,8 @@ public class LogDistancePropagationLossModel extends PropagationLossModel {
* referenceDistance / lambda); * referenceDistance / lambda);
@Override @Override
public double getRxPowerDbm(double txPowerDbm, Position a, Position b) { public double getRxPowerDbm(double txPowerDbm, Location a, Location b) {
double distance = a.getDistance(b); double distance = a.distanceTo(b);
return getRxPowerDbm(txPowerDbm, distance); return getRxPowerDbm(txPowerDbm, distance);
} }
......
/* /*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package de.tud.kom.p2psim.impl.topology.waypoints; package de.tud.kom.p2psim.impl.topology.waypoints;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.jgrapht.alg.DijkstraShortestPath; import org.jgrapht.alg.DijkstraShortestPath;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.scenario.Configurator; import de.tud.kom.p2psim.api.scenario.Configurator;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel; import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener;
import de.tud.kom.p2psim.api.util.geo.maps.Map; import de.tud.kom.p2psim.api.util.geo.maps.Map;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After; import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure; import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph; import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.Tuple; import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener; import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener;
import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader; import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader;
import de.tud.kom.p2psim.impl.util.structures.KdTree; import de.tud.kom.p2psim.impl.util.structures.KdTree;
import de.tud.kom.p2psim.impl.util.structures.KdTree.Entry; import de.tud.kom.p2psim.impl.util.structures.KdTree.Entry;
import de.tud.kom.p2psim.impl.util.structures.WaypointKdTree; import de.tud.kom.p2psim.impl.util.structures.WaypointKdTree;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/** /**
* The abstract way point model manages a graph for the map data and holds * The abstract way point model manages a graph for the map data and holds
* additional information for the fast retrieval of way points. * additional information for the fast retrieval of way points.
* *
* @author Fabio Zöllner * @author Fabio Zöllner
* @version 1.0, 09.04.2012 * @version 1.0, 09.04.2012
*/ */
public abstract class AbstractWaypointModel implements WaypointModel { public abstract class AbstractWaypointModel implements WaypointModel {
private PositionVector worldDimensions; private PositionVector worldDimensions;
private Map map; private Map map;
// private DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph; // private DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph;
private ArrayList<WaypointModelListener> listeners = new ArrayList<WaypointModelListener>(); private ArrayList<WaypointModelListener> listeners = new ArrayList<WaypointModelListener>();
// k-d tree for fast retrieval of nearby waypoints // k-d tree for fast retrieval of nearby waypoints
private KdTree<Waypoint> kdTree = new WaypointKdTree(2); private KdTree<Waypoint> kdTree = new WaypointKdTree(2);
private ObstacleModel obstacleModel = null; private ObstacleModel obstacleModel = null;
// Determines if the loaded model should be scaled or truncated to fit the given world size // Determines if the loaded model should be scaled or truncated to fit the given world size
private boolean scaleModel = true; private boolean scaleModel = true;
private String mapName = ""; private String mapName = "";
public AbstractWaypointModel() { public AbstractWaypointModel() {
// //
} }
@Configure() @Configure()
@After(optional={ObstacleModel.class}) @After(optional={ObstacleModel.class})
public void _configure(Configurator configurator) { public void _configure(Configurator configurator) {
MapLoader mapLoader = (MapLoader)configurator.getConfigurable(MapLoader.class.getSimpleName()); MapLoader mapLoader = (MapLoader)configurator.getConfigurable(MapLoader.class.getSimpleName());
if (mapLoader == null) { if (mapLoader == null) {
throw new ConfigurationException("No MapLoader was configured. Unable to retrieve the map '" + mapName + "'."); throw new ConfigurationException("No MapLoader was configured. Unable to retrieve the map '" + mapName + "'.");
} }
Map map = mapLoader.getMap(mapName); Map map = mapLoader.getMap(mapName);
if (map == null) { if (map == null) {
throw new ConfigurationException("Couldn't retrieve the map '" + mapName + "' from the MapLoader. Make sure the map is configured."); throw new ConfigurationException("Couldn't retrieve the map '" + mapName + "' from the MapLoader. Make sure the map is configured.");
} }
this.map = map; this.map = map;
map.addMapChangeListener(new MapChangeListener() { map.addMapChangeListener(new MapChangeListener() {
@Override @Override
public void mapChanged(MapEvent event) { public void mapChanged(MapEvent event) {
if (event instanceof PathEvent) { if (event instanceof PathEvent) {
notifyAddedPath(((PathEvent)event).getPath()); notifyAddedPath(((PathEvent)event).getPath());
} else if (event instanceof WaypointEvent) { } else if (event instanceof WaypointEvent) {
notifyAddedWaypoint(((WaypointEvent)event).getWaypoint()); notifyAddedWaypoint(((WaypointEvent)event).getWaypoint());
} else { } else {
notifyModifiedWaypoints(); notifyModifiedWaypoints();
} }
} }
}); });
Monitor.log(AbstractWaypointModel.class, Level.INFO, Monitor.log(AbstractWaypointModel.class, Level.INFO,
"The '" + map.getName() + "' " + map.getClass().getSimpleName() "The '" + map.getName() + "' " + map.getClass().getSimpleName()
+ " has dimensions of " + map.getDimensions().getX() + " has dimensions of " + map.getDimensions().getX()
+ "x" + map.getDimensions().getY() + "."); + "x" + map.getDimensions().getY() + ".");
PositionVector mapBorder = map.getDimensions().clone(); PositionVector mapBorder = map.getDimensions().clone();
mapBorder.divide(getWorldDimensions()); mapBorder.divide(getWorldDimensions());
if (mapBorder.getEntry(0) != 1 || mapBorder.getEntry(1) != 1) { if (mapBorder.getEntry(0) != 1 || mapBorder.getEntry(1) != 1) {
Monitor.log( Monitor.log(
AbstractWaypointModel.class, AbstractWaypointModel.class,
Level.WARN, Level.WARN,
"You specified WORLD to be " "You specified WORLD to be "
+ getWorldDimensions().toString() + getWorldDimensions().toString()
+ " and used an OSM Map with " + " and used an OSM Map with "
+ map.getDimensions() + map.getDimensions()
+ ", resulting in wrong scaling."); + ", resulting in wrong scaling.");
} }
init(); init();
} }
public abstract void init(); public abstract void init();
public Map getMap() { public Map getMap() {
return map; return map;
} }
public void setMap(String mapName) { public void setMap(String mapName) {
this.mapName = mapName; this.mapName = mapName;
} }
public void setScale(boolean shouldScale) { public void setScale(boolean shouldScale) {
this.scaleModel = shouldScale; this.scaleModel = shouldScale;
} }
public boolean isScaled() { public boolean isScaled() {
return scaleModel; return scaleModel;
} }
@Override @Override
public double getScaleFactor() { public double getScaleFactor() {
if (!this.scaleModel) { if (!this.scaleModel) {
return 1; return 1;
} }
double mapX = getMap().getDimensions().getX(); double mapX = getMap().getDimensions().getX();
double mapY = getMap().getDimensions().getY(); double mapY = getMap().getDimensions().getY();
double worldX = getWorldDimensions().getX(); double worldX = getWorldDimensions().getX();
double worldY = getWorldDimensions().getY(); double worldY = getWorldDimensions().getY();
double factor = Math.abs((worldX + worldY) / (mapX + mapY)); double factor = Math.abs((worldX + worldY) / (mapX + mapY));
return factor; return factor;
} }
@Override @Override
public void setObstacleModel(ObstacleModel model) { public void setObstacleModel(ObstacleModel model) {
obstacleModel = model; obstacleModel = model;
} }
public PositionVector getWorldDimensions() { public PositionVector getWorldDimensions() {
return worldDimensions; return worldDimensions;
} }
@Override @Override
public void setWorldDimensions(PositionVector worldDimensions) { public void setWorldDimensions(PositionVector worldDimensions) {
this.worldDimensions = worldDimensions; this.worldDimensions = worldDimensions;
} }
@Override @Override
public Collection<Waypoint> getWaypoints(Class type) { public Collection<Waypoint> getWaypoints(Class type) {
return map.getWaypoints(type); return map.getWaypoints(type);
} }
@Override @Override
public Waypoint getClosestWaypoint(PositionVector position) { public Waypoint getClosestWaypoint(PositionVector position) {
return getClosestWaypoint(position, Waypoint.class); return getClosestWaypoint(position, Waypoint.class);
} }
@Override @Override
public Waypoint getClosestWaypoint(PositionVector position, Class type) { public Waypoint getClosestWaypoint(PositionVector position, Class type) {
double distance = -1; double distance = -1;
Waypoint waypoint = null; Waypoint waypoint = null;
for (Waypoint w : map.getGraph().vertexSet()) { for (Waypoint w : map.getGraph().vertexSet()) {
if (!w.getClass().equals(type)) if (!w.getClass().equals(type))
continue; continue;
double d = position.getDistance(w.getPosition()); double d = position.distanceTo(w.getPosition());
if (distance > d || distance == -1) { if (distance > d || distance == -1) {
distance = d; distance = d;
waypoint = w; waypoint = w;
} }
} }
return waypoint; return waypoint;
} }
public Waypoint getClosestWaypointKd(PositionVector position, Class type) { public Waypoint getClosestWaypointKd(PositionVector position, Class type) {
List<Entry<Waypoint>> waypoints = kdTree.nearestNeighbor( List<Entry<Waypoint>> waypoints = kdTree.nearestNeighbor(
position.asDoubleArray(), 1, false); position.asDoubleArray(), 1, false);
if (waypoints.isEmpty()) if (waypoints.isEmpty())
return null; return null;
return waypoints.get(0).value; return waypoints.get(0).value;
} }
@Override @Override
public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint) { public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint) {
return getConnectedWaypoints(waypoint, Waypoint.class); return getConnectedWaypoints(waypoint, Waypoint.class);
} }
@Override @Override
public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint, public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint,
Class type) { Class type) {
Set<Path> paths = map.getGraph().edgesOf(waypoint); Set<Path> paths = map.getGraph().edgesOf(waypoint);
ArrayList<Tuple<Waypoint, Path>> waypointsAndPaths = new ArrayList<Tuple<Waypoint, Path>>(); ArrayList<Tuple<Waypoint, Path>> waypointsAndPaths = new ArrayList<Tuple<Waypoint, Path>>();
for (Path p : paths) { for (Path p : paths) {
Waypoint destinationWaypoint = null; Waypoint destinationWaypoint = null;
if (p.getSource().equals(waypoint)) if (p.getSource().equals(waypoint))
destinationWaypoint = p.getTarget(); destinationWaypoint = p.getTarget();
else if (p.getTarget().equals(waypoint)) else if (p.getTarget().equals(waypoint))
destinationWaypoint = p.getSource(); destinationWaypoint = p.getSource();
if (destinationWaypoint.getClass().equals(type)) if (destinationWaypoint.getClass().equals(type))
waypointsAndPaths.add(new Tuple<Waypoint, Path>( waypointsAndPaths.add(new Tuple<Waypoint, Path>(
destinationWaypoint, p)); destinationWaypoint, p));
} }
return waypointsAndPaths; return waypointsAndPaths;
} }
@Override @Override
public int getNumberOfWaypoints(Class type) { public int getNumberOfWaypoints(Class type) {
Collection<Waypoint> wpList = map.getWaypoints(type); Collection<Waypoint> wpList = map.getWaypoints(type);
if (wpList == null) if (wpList == null)
return -1; return -1;
return wpList.size(); return wpList.size();
} }
@Override @Override
public void addListener(WaypointModelListener listener) { public void addListener(WaypointModelListener listener) {
this.listeners.add(listener); this.listeners.add(listener);
} }
@Override @Override
public void removeListener(WaypointModelListener listener) { public void removeListener(WaypointModelListener listener) {
this.listeners.remove(listener); this.listeners.remove(listener);
} }
private void notifyAddedWaypoint(Waypoint waypoint) { private void notifyAddedWaypoint(Waypoint waypoint) {
for (WaypointModelListener l : listeners) { for (WaypointModelListener l : listeners) {
l.addedWaypoint(waypoint); l.addedWaypoint(waypoint);
} }
} }
private void notifyModifiedWaypoints() { private void notifyModifiedWaypoints() {
for (WaypointModelListener l : listeners) { for (WaypointModelListener l : listeners) {
l.modifiedWaypoints(); l.modifiedWaypoints();
} }
} }
private void notifyAddedPath(Path path) { private void notifyAddedPath(Path path) {
for (WaypointModelListener l : listeners) { for (WaypointModelListener l : listeners) {
l.addedPath(path); l.addedPath(path);
} }
} }
@Override @Override
public PositionVector getMetricDimensions() { public PositionVector getMetricDimensions() {
return worldDimensions; return worldDimensions;
} }
@Override @Override
public abstract void generateWaypoints(); public abstract void generateWaypoints();
@Override @Override
public Set<Waypoint> getWaypoints() { public Set<Waypoint> getWaypoints() {
if (map != null) { if (map != null) {
return map.getGraph().vertexSet(); return map.getGraph().vertexSet();
} else { } else {
return Sets.newHashSet(); return Sets.newHashSet();
} }
} }
@Override @Override
public Set<Path> getPaths() { public Set<Path> getPaths() {
return map.getGraph().getAllEdges(); return map.getGraph().getAllEdges();
} }
@Override @Override
public List<Path> getShortestPath(Waypoint start, Waypoint end) { public List<Path> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, Path> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, Path>( DijkstraShortestPath<Waypoint, Path> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, Path>(
map.getGraph(), start, end); map.getGraph(), start, end);
List<Path> paths = dijkstrashortestpath.getPathEdgeList(); List<Path> paths = dijkstrashortestpath.getPathEdgeList();
return dijkstrashortestpath.getPathEdgeList(); return dijkstrashortestpath.getPathEdgeList();
} }
@Override @Override
public int getNumberOfWaypoints() { public int getNumberOfWaypoints() {
return map.getGraph().vertexSet().size(); return map.getGraph().vertexSet().size();
} }
@Override @Override
public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph() { public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph() {
if (map == null) if (map == null)
return null; return null;
return map.getGraph(); return map.getGraph();
} }
public void addWaypoint(Waypoint wp) { public void addWaypoint(Waypoint wp) {
map.addWaypoint(wp); map.addWaypoint(wp);
} }
} }
/* /*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package de.tud.kom.p2psim.impl.topology.waypoints.graph; package de.tud.kom.p2psim.impl.topology.waypoints.graph;
import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.DefaultWeightedEdge;
/** /**
* Represents a simple weighted path between * Represents a simple weighted path between
* two way points. * two way points.
* *
* @author Fabio Zöllner * @author Fabio Zöllner
* @version 1.0, 27.03.2012 * @version 1.0, 27.03.2012
*/ */
public class Path extends DefaultWeightedEdge { public class Path extends DefaultWeightedEdge {
private Waypoint source; private Waypoint source;
private Waypoint target; private Waypoint target;
private double weight = 1; private double weight = 1;
public Path(Waypoint source, Waypoint target) { public Path(Waypoint source, Waypoint target) {
this.source = source; this.source = source;
this.target = target; this.target = target;
double d = source.getPosition().getDistance(target.getPosition()); double d = source.getPosition().distanceTo(target.getPosition());
weight = Math.abs(1 - (1 / d)); weight = Math.abs(1 - (1 / d));
} }
@Override @Override
protected double getWeight() { protected double getWeight() {
return weight; return weight;
} }
public Waypoint getSource() { public Waypoint getSource() {
return source; return source;
} }
public Waypoint getTarget() { public Waypoint getTarget() {
return target; return target;
} }
public Waypoint getOtherEnd(Waypoint wp) { public Waypoint getOtherEnd(Waypoint wp) {
if (source.equals(wp)) if (source.equals(wp))
return target; return target;
return source; return source;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Path other = (Path) obj; Path other = (Path) obj;
if (getWeight() != other.getWeight() || if (getWeight() != other.getWeight() ||
!source.equals(other.getSource()) || !source.equals(other.getSource()) ||
!target.equals(other.getTarget())) !target.equals(other.getTarget()))
return false; return false;
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
return "Path[From: " + source + ", To: " + target + ", Weight: " + weight + "]"; return "Path[From: " + source + ", To: " + target + ", Weight: " + weight + "]";
} }
} }
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