diff --git a/src/de/tud/kom/p2psim/api/transport/TransProtocol.java b/src/de/tud/kom/p2psim/api/transport/TransProtocol.java index 62d82c94f0fbc11411ac4635682e64b8893d14b9..4db367d40bb009c40e7a616d15d88253e72b680c 100644 --- a/src/de/tud/kom/p2psim/api/transport/TransProtocol.java +++ b/src/de/tud/kom/p2psim/api/transport/TransProtocol.java @@ -19,73 +19,61 @@ */ - -package de.tud.kom.p2psim.api.transport; - -/** - * Instances of this type describe the service properties chosen for message - * transmission. - * - * @author Sebastian Kaune - * @author Konstantin Pussep - * @version 3.0, 11/29/2007 - * - */ -public enum TransProtocol { - /** - * User Datagram Protocol - */ - UDP(false, false, 8), - /** - * Transmission Control Protocol - */ - TCP(true, true, 20), + +package de.tud.kom.p2psim.api.transport; + +/** + * Instances of this type describe the service properties chosen for message + * transmission. + * + * @author Sebastian Kaune + * @author Konstantin Pussep + * @version 3.0, 11/29/2007 + * + */ +public enum TransProtocol { /** - * Mobile Communication, one hop (this will be changed to UDP/TCP on the - * BaseStation or one of its backbone nodes). Only available, if an - * UMTS-transceiver is configured in the LinkLayer. TODO check Header Size + * User Datagram Protocol */ - UMTS(true, true, 20), + UDP(false, false, 8), /** - * Bluetooth (this will only allow one-hop communication to short-ranged - * neighbors). Only available, if a BT-transceiver is configured in the - * LinkLayer. TODO check Header Size + * Transmission Control Protocol */ - BLUETOOTH(true, true, 20); - - private boolean isConOriented; - + TCP(true, true, 20); + + private boolean isConOriented; + private boolean isReliable; - private int headerSize; - + private int headerSize; + private TransProtocol(boolean isConOriented, boolean isReliable, - int headerSize) { - this.isConOriented = isConOriented; + int headerSize) { + this.isConOriented = isConOriented; this.isReliable = isReliable; - this.headerSize = headerSize; - } - - /** - * If the used service is connection-oriented the in-order delivery of - * messages is guaranteed. - * - * @return whether the applied service should be connection-oriented - */ - public boolean isConnectionOriented() { - return this.isConOriented; - } - - /** - * Whether the used connection is reliable, i.e. the network wrapper tries - * to deliver the message in case of loss or and if the message cannot be - * delivered an exception is reported to the upper layer. - * - * @return whether the applied service should be reliable - */ - public boolean isReliable() { - return this.isReliable; - } + this.headerSize = headerSize; + } + + /** + * If the used service is connection-oriented the in-order delivery of + * messages is guaranteed. + * + * @return whether the applied service should be connection-oriented + */ + public boolean isConnectionOriented() { + return this.isConOriented; + } + + /** + * Whether the used connection is reliable, i.e. the network wrapper tries + * to deliver the message in case of loss or and if the message cannot be + * delivered an exception is reported to the upper layer. + * + * @return whether the applied service should be reliable + */ + public boolean isReliable() { + return this.isReliable; + } /** * Size of the headers of this TransMessage in byte. @@ -95,5 +83,5 @@ public enum TransProtocol { public int getHeaderSize() { return this.headerSize; } - -} + +} diff --git a/src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputSiS.java b/src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputSiS.java index a4c10810dff19797442f738f3e9884758a63244f..a85c2121f84a1798d9efb2531bffae74eae37e6f 100644 --- a/src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputSiS.java +++ b/src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputSiS.java @@ -40,7 +40,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes; -import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AbstractAggregation; +import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AggregationDouble; /** * Metric output acting as a bridge to the SiS @@ -86,7 +86,7 @@ public class MetricOutputSiS extends AbstractOutput { if (sisType == null) { // register type SiSTypes.registerType(metric.getName(), Double.class, - new AbstractAggregation.AggregationDouble()); + new AggregationDouble()); sisType = SiSTypes.getType(metric.getName(), Double.class); assert sisType != null; } diff --git a/src/de/tud/kom/p2psim/impl/churn/MaxPeerCountChurnGenerator.java b/src/de/tud/kom/p2psim/impl/churn/MaxPeerCountChurnGenerator.java index 9ef4a3414cc13ae3288f6aea9f3a9d2af7c72e52..ee8c4fe92bf4f92276194611ea1abefb7cece3d9 100644 --- a/src/de/tud/kom/p2psim/impl/churn/MaxPeerCountChurnGenerator.java +++ b/src/de/tud/kom/p2psim/impl/churn/MaxPeerCountChurnGenerator.java @@ -99,7 +99,7 @@ public class MaxPeerCountChurnGenerator private PriorityQueue offlineHostsSortedByOfflineTime; - private Random rnd = Randoms.getRandom(new Object()); + private Random rnd = Randoms.getRandom(MaxPeerCountChurnGenerator.class); /** * Comparator used to sort client infos by offline time diff --git a/src/de/tud/kom/p2psim/impl/topology/DefaultTopologyComponent.java b/src/de/tud/kom/p2psim/impl/topology/DefaultTopologyComponent.java index bc554b50c2eb333f420a66256aa39cf70a482b24..67d8f8c0952c218c0a14691066b860e42c8020f8 100644 --- a/src/de/tud/kom/p2psim/impl/topology/DefaultTopologyComponent.java +++ b/src/de/tud/kom/p2psim/impl/topology/DefaultTopologyComponent.java @@ -38,7 +38,12 @@ import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.impl.simengine.Simulator; -import de.tudarmstadt.maki.simonstrator.api.*; +import de.tudarmstadt.maki.simonstrator.api.Event; +import de.tudarmstadt.maki.simonstrator.api.EventHandler; +import de.tudarmstadt.maki.simonstrator.api.Graphs; +import de.tudarmstadt.maki.simonstrator.api.Host; +import de.tudarmstadt.maki.simonstrator.api.Oracle; +import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph; import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge; import de.tudarmstadt.maki.simonstrator.api.common.graph.INode; @@ -170,6 +175,12 @@ public class DefaultTopologyComponent implements TopologyComponent { DefaultTopologyComponent.this, getTopologyID(NetInterfaceName.WIFI, true), DefaultTopologyComponent.class); + + new SiSTopologyProvider(sis, + SiSTypes.NEIGHBORS_WIFI_LOCAL, + DefaultTopologyComponent.this, + getTopologyID(NetInterfaceName.WIFI, true), + DefaultTopologyComponent.class); } } }, null, 0); @@ -257,8 +268,18 @@ public class DefaultTopologyComponent implements TopologyComponent { @Override public void updateCurrentLocation(Location location) { position.set(location); - NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Current Location", location); - NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Distance to target", location.distanceTo(movementModel.getTargetLocation(this))); + /* + * FIXME utilization of the NodeDebugMonitor leads to huge performance drop. + */ +// NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Current Location", location); +// try { +// NodeDebugMonitor.update(this.getClass(), getHost().getId(), +// "Distance to target", +// location.distanceTo(movementModel.getTargetLocation(this))); +// } catch (UnsupportedOperationException e) { +// // This is not supported by the movement model (which may happen see +// // MovementModel.java - thus catch and ignore) +// } // notify "non-request" listeners for (LocationListener locationListener : listeners) { locationListener.onLocationChanged(getHost(), getLastLocation()); @@ -269,8 +290,7 @@ public class DefaultTopologyComponent implements TopologyComponent { public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) throws UnsupportedOperationException { movementModel.changeTargetLocation(this, targetAttractionPoint); - - NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Target Location", targetAttractionPoint); +// NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Target Location", targetAttractionPoint); } @Override diff --git a/src/de/tud/kom/p2psim/impl/topology/PositionVector.java b/src/de/tud/kom/p2psim/impl/topology/PositionVector.java index a8fbfdc09d7e7b6acffefa0fa6e0094de17769de..7b0740c851f0b160dc9e145420608b09c615082f 100644 --- a/src/de/tud/kom/p2psim/impl/topology/PositionVector.java +++ b/src/de/tud/kom/p2psim/impl/topology/PositionVector.java @@ -23,8 +23,6 @@ package de.tud.kom.p2psim.impl.topology; import java.awt.Point; import java.util.Arrays; -import org.aopalliance.aop.AspectException; - import com.vividsolutions.jts.geom.Coordinate; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/AbstractLocalMovementStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/AbstractLocalMovementStrategy.java index 410993b11f5cb0cea87629fe0fea346f912efa23..7e56254940a1d3ec363dce1d822c964e7e1f8142 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/local/AbstractLocalMovementStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/local/AbstractLocalMovementStrategy.java @@ -26,6 +26,7 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.util.Either; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor; public abstract class AbstractLocalMovementStrategy implements LocalMovementStrategy { @@ -34,6 +35,8 @@ public abstract class AbstractLocalMovementStrategy implements protected ObstacleModel obstacleModel; + private static boolean calculateRouteSegments = false; + private double scaleFactor = 1; public double getMovementSpeed(SimLocationActuator ms) { @@ -57,6 +60,37 @@ public abstract class AbstractLocalMovementStrategy implements this.obstacleModel = model; } + protected boolean isCalculateRouteSegments() { + return calculateRouteSegments; + } + + /** + * For the visualization: programmatically enable route segment + * calculations. + */ + public static void setCalculationOfRouteSegments(boolean setting) { + calculateRouteSegments = setting; + } + + /** + * For the visualization: programmatically check route segment + * calculation. + */ + public static boolean isCalculatingRouteSegments() { + return calculateRouteSegments; + } + + /** + * If you intend to use the {@link RouteSensor} and operate on a per-segment + * basis, set this to true. If you DO NOT use the respective segment data, + * set it to false, as this option consumes significant resources. + * + * @param calculateRouteSegments + */ + public void setCalculateRouteSegments(boolean calculateRouteSegments) { + this.calculateRouteSegments = calculateRouteSegments; + } + @Override public abstract Either nextPosition( SimLocationActuator comp, PositionVector destination); diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/OnlineMapQuestMovement.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/OnlineMapQuestMovement.java index a733fa121c2dd84d0eb8875ae010d14a83c9d668..e243d3d1947e6a225d992dbcca0e1d00b094ee98 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/local/OnlineMapQuestMovement.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/local/OnlineMapQuestMovement.java @@ -53,7 +53,7 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy { private PositionVector worldDimensions; - private static HashMap movementPoints = new HashMap<>(); + private static HashMap movementPoints = new HashMap<>(); private String movementType; // {Fastest, Shortest, Pedestrian, Bicycle} private String mapQuestKey; @@ -82,8 +82,8 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy { newPosition = destination.clone(); } else { //if not set already for this node or new destination is different than last one - PointList pointList; - if(!movementPoints.containsKey(comp.hashCode()) || destination.distanceTo(movementPoints.get(comp.hashCode()).getDestination()) > 1.0) { + RouteImpl trajectory = movementPoints.get(comp); + if(trajectory == null || destination.distanceTo(trajectory.getDestination()) > 1.0) { double[] startPosition = transformOwnWorldWindowToGPS(comp.getRealPosition().getX(), comp.getRealPosition().getY()); double[] destinationPosition = transformOwnWorldWindowToGPS(destination.getX(), destination.getY()); @@ -110,7 +110,7 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy { } //read in all waypoints - pointList = new PointList(); + PointList pointList = new PointList(); if(allDirections != null) { for(int i = 0; i < allDirections.length(); i++) { try { @@ -123,25 +123,12 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy { } } } - movementPoints.put(comp.hashCode(), new RealWorldMovementPoints(comp.getRealPosition(), destination, pointList, 0)); - } - else { - pointList = movementPoints.get(comp.hashCode()).getPointList(); + trajectory = new RouteImpl(comp.getRealPosition(), destination, pointList); + movementPoints.put(comp, trajectory); } - int actualIndex = movementPoints.get(comp.hashCode()).getActualIndex(); - int i = 0; - for(GHPoint3D temp : pointList) { - if(i==actualIndex) { - PositionVector nextPoint = transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon()); - newPosition = comp.getRealPosition().moveStep(nextPoint, getMovementSpeed(comp)); - - if(nextPoint.distanceTo(comp.getRealPosition()) < maxDistanceNextPoint) actualIndex++; - } - i++; - } + newPosition = trajectory.updateCurrentLocation(comp, getMovementSpeed(comp), 1.0); - movementPoints.put(comp.hashCode(), new RealWorldMovementPoints(movementPoints.get(comp.hashCode()).getStart(), destination, pointList, actualIndex)); } return new Left(newPosition); } @@ -159,18 +146,6 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy { return gps_coordinates; } - /** - * 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); - double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLeft)/(latRight - latLeft); - return new PositionVector(x, y); - } - public void setMovementType(String movementType) { this.movementType = movementType; } diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldMovementPoints.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldMovementPoints.java deleted file mode 100644 index 6b3c844c108ef2787bac9c19ec0a9f62cd456a26..0000000000000000000000000000000000000000 --- a/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldMovementPoints.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 . - * - */ - -package de.tud.kom.p2psim.impl.topology.movement.local; - -import com.graphhopper.util.PointList; - -import de.tud.kom.p2psim.impl.topology.PositionVector; - -public class RealWorldMovementPoints { - - private PositionVector start; - private PositionVector destination; - private PointList pointList; - private int actualIndex; - - public RealWorldMovementPoints(PositionVector start, PositionVector destination, PointList pointList, int actualIndex) { - this.start = start; - this.destination = destination; - this.pointList = pointList; - this.actualIndex = actualIndex; - } - - public PositionVector getStart() { - return start; - } - public void setStart(PositionVector start) { - this.start = start; - } - public PositionVector getDestination() { - return destination; - } - public void setDestination(PositionVector destination) { - this.destination = destination; - } - public PointList getPointList() { - return pointList; - } - public void setPointList(PointList pointList) { - this.pointList = pointList; - } - public int getActualIndex() { - return this.actualIndex; - } -} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java index 8ef7a653bc514dcafc6eba5e2e8c1b79b43b2fc1..5b92aba878aca6661c2562c7b01568b9def6b3cf 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java @@ -20,27 +20,37 @@ package de.tud.kom.p2psim.impl.topology.movement.local; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; + import com.graphhopper.GHRequest; import com.graphhopper.GHResponse; import com.graphhopper.GraphHopper; +import com.graphhopper.routing.util.EdgeFilter; import com.graphhopper.routing.util.EncodingManager; +import com.graphhopper.storage.index.LocationIndex; +import com.graphhopper.storage.index.QueryResult; +import com.graphhopper.util.DistanceCalc2D; +import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.util.PointList; import com.graphhopper.util.shapes.GHPoint; -import com.graphhopper.util.shapes.GHPoint3D; + import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; -import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView; +import de.tud.kom.p2psim.impl.topology.movement.modularosm.RouteSensorComponent; import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Left; import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; - -import java.util.HashMap; -import java.util.Locale; -import java.util.UUID; +import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; /** * This movement strategy uses the data from osm and navigates the nodes throught streets to the destination @@ -53,21 +63,24 @@ import java.util.UUID; */ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { - private PositionVector worldDimensions; + private static PositionVector worldDimensions; private GraphHopper hopper; + private LocationIndex index; private boolean init = false; - private static HashMap movementPoints = new HashMap<>(); - + private static HashMap currentRoutes = new HashMap<>(); + + private Map routeSensorComponents = new LinkedHashMap<>(); + private String osmFileLocation; //use pbf-format, because osm-format causes problems (xml-problems) private String graphFolderFiles; private String movementType; //car, bike or foot private String defaultMovement; private String navigationalType; //fastest, - private double latLower; //Values from -90 to 90; always smaller than latUpper - private double latUpper; //Values from -90 to 90 - private double lonLeft; //Values from -180 to 180; Always smaller than lonRight - private double lonRight; //Values from -180 to 180 + private static double latLower; //Values from -90 to 90; always smaller than latUpper + private static double latUpper; //Values from -90 to 90 + private static double lonLeft; //Values from -180 to 180; Always smaller than lonRight + private static double lonRight; //Values from -180 to 180 private boolean uniqueFolders; /** @@ -77,12 +90,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { private double tolerance = 1; public RealWorldStreetsMovement() { - this.worldDimensions = Binder.getComponentOrNull(Topology.class) + worldDimensions = Binder.getComponentOrNull(Topology.class) .getWorldDimensions(); latLower = GPSCalculation.getLatLower(); latUpper = GPSCalculation.getLatUpper(); lonLeft = GPSCalculation.getLonLeft(); lonRight = GPSCalculation.getLonRight(); + } private void init() { @@ -102,29 +116,48 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { } hopper.setEncodingManager(new EncodingManager(movementType)); hopper.importOrLoad(); + index = hopper.getLocationIndex(); init = true; } - public Either nextPosition(SimLocationActuator comp, PositionVector destination) - { + @Override + public Either nextPosition( + SimLocationActuator comp, PositionVector destination) { return nextPosition(comp, destination, defaultMovement); } public Either nextPosition(SimLocationActuator comp, PositionVector destination, String movementType) { - if(movementType == null || movementType.equals("") || !this.movementType.contains(movementType)) + if (movementType == null || movementType.equals("") + || !this.movementType.contains(movementType)) { throw new AssertionError("Invalid movement type: " + movementType); + } + + if (!init) { + init(); + } + + RouteSensorComponent routeSensor = routeSensorComponents.get(comp); + if (routeSensor == null) { + try { + routeSensorComponents.put(comp, comp.getHost() + .getComponent(RouteSensorComponent.class)); + routeSensor = routeSensorComponents.get(comp); + } catch (ComponentNotAvailableException e) { + throw new AssertionError( + "The movement model needs to provide RouteSensorComponents."); + } + } - if(!init) init(); PositionVector newPosition = null; - if (destination.distanceTo(comp.getRealPosition()) > getMovementSpeed(comp)) - { + if (destination + .distanceTo(comp.getRealPosition()) > getMovementSpeed(comp)) { //if not set already for this node or new destination is different than last one - PointList pointList; - if(!movementPoints.containsKey(comp) || destination.distanceTo(movementPoints.get(comp).getDestination()) > 1.0) { + RouteImpl trajectory = currentRoutes.get(comp); + if(trajectory == null || destination.distanceTo(trajectory.getDestination()) > 1.0) { double[] startPosition = transformOwnWorldWindowToGPS(comp.getRealPosition().getX(), comp.getRealPosition().getY()); double[] destinationPosition = transformOwnWorldWindowToGPS(destination.getX(), destination.getY()); GHRequest req = new GHRequest(startPosition[0], startPosition[1], destinationPosition[0], destinationPosition[1]). @@ -138,41 +171,79 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { "%f,%f), destination (%f,%f) and type %s failed with error: %s.", comp.getHost().getId().valueAsString(),startPosition[0], startPosition[1], destinationPosition[0], destinationPosition[1], movementType, rsp.getErrors()); - pointList = new PointList(); + PointList pointList = new PointList(); pointList.add(new GHPoint(destinationPosition[0], destinationPosition[1])); - movementPoints.put(comp, new RealWorldMovementPoints(comp.getRealPosition(), destination, pointList, 0)); - } - else { - pointList = rsp.getBest().getPoints(); - movementPoints.put(comp, new RealWorldMovementPoints(comp.getRealPosition(), destination, pointList, 0)); + trajectory = new RouteImpl(comp.getRealPosition(), destination, pointList); + currentRoutes.put(comp, trajectory); + + } else { + PointList pointList = rsp.getBest().getPoints(); + + if (isCalculateRouteSegments()) { + /* + * Obtain segment IDs along the route. + */ + trajectory = new RouteImpl(comp.getRealPosition(), + destination, pointList, + routeSensor.getSegmentListeners(), routeSensor, + calculateSegments(pointList)); + } else { + trajectory = new RouteImpl(comp.getRealPosition(), + destination, pointList); + } + currentRoutes.put(comp, trajectory); } + routeSensor.setNewRoute(trajectory); } - else { - pointList = movementPoints.get(comp).getPointList(); + newPosition = trajectory.updateCurrentLocation(comp, getMovementSpeed(comp), tolerance); + + if (trajectory.reachedDestination()) { + routeSensor.reachedDestination(); } - - int actualIndex = movementPoints.get(comp).getActualIndex(); - int i = 0; - for(GHPoint3D temp : pointList) { - if(i==actualIndex) { - PositionVector nextPoint = transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon()); - newPosition = comp.getRealPosition().moveStep(nextPoint, getMovementSpeed(comp)); - - if (nextPoint - .distanceTo(comp.getRealPosition()) < tolerance) { - actualIndex++; + } + return new Left(newPosition); + } + + /** + * Calculate the route segments along the given point list. + * + * @return + */ + private List calculateSegments(PointList pointList) { + int ptIdx = 0; + int prevEdgeId = -1; + List segments = new LinkedList<>(); + RouteSegmentImpl lastSegment = null; + for (GHPoint point : pointList) { + QueryResult qr = index.findClosest(point.getLat(), point.getLon(), + EdgeFilter.ALL_EDGES); + EdgeIteratorState nearEdge = qr.getClosestEdge(); + if (nearEdge != null) { + int edgeId = nearEdge.getEdge(); + if (edgeId != prevEdgeId) { + if (lastSegment != null) { + lastSegment.addRouteLocation( + transformGPSWindowToOwnWorld(point.getLat(), + point.getLon())); } + lastSegment = new RouteSegmentImpl(Integer.toString(edgeId), + ptIdx, transformGPSWindowToOwnWorld(point.getLat(), + point.getLon())); + segments.add(lastSegment); + } else { + lastSegment.addRouteLocation(transformGPSWindowToOwnWorld( + point.getLat(), point.getLon())); } - i++; } - - movementPoints.put(comp, new RealWorldMovementPoints(movementPoints.get(comp).getStart(), destination, pointList, actualIndex)); + ptIdx++; } - return new Left(newPosition); + return segments; } - + /** - * Projects the world coordinates in the given gps window to the gps-coordinates + * Projects the world coordinates in the given gps window to the + * gps-coordinates + * * @param x * @param y * @return The projected position in gps-coordinates (lat, long) @@ -190,8 +261,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { * @param lon * @return The projected position in world-dimensions */ - private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) { - VisualizationTopologyView.VisualizationInjector.getWorldX(); + public static PositionVector transformGPSWindowToOwnWorld(double lat, double lon) { double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft); double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLower)/(latUpper - latLower); x = Math.max(0, x); @@ -200,6 +270,59 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { y = Math.min(worldDimensions.getY(), y); return new PositionVector(x, y); } + + /** + * Returns a list of points representing the current route of the component. Points are + * in x / y values of the own world. + * @param ms the component + * @return list of movement points. + */ + public List getMovementPoints(SimLocationActuator ms) + { + List positions = new LinkedList<>(); + PointList pointList = currentRoutes.get(ms).getPointList(); + + pointList.forEach(p -> positions.add(new PositionVector(transformGPSWindowToOwnWorld(p.getLat(), p.getLon())))); + + return positions; + } + + /** + * Calculates the length of a route in meters. + * @param start Starting position in own world coordinates (x / y) + * @param destination Destination on own world coordinates (x / y) + * @return the length of the route in meters. + */ + public double calculateRouteLength(PositionVector start, PositionVector destination) + { + PointList pointList; + double[] startPosition = transformOwnWorldWindowToGPS(start.getX(), start.getY()); + double[] destinationPosition = transformOwnWorldWindowToGPS(destination.getX(), destination.getY()); + GHRequest req = new GHRequest(startPosition[0], startPosition[1], destinationPosition[0], destinationPosition[1]). + setWeighting(navigationalType). + setVehicle(movementType). + setLocale(Locale.GERMANY); + GHResponse rsp = hopper.route(req); + + //If the requested point is not in the map data, return -1 + if(rsp.hasErrors()) { + return -1; + } + else { + pointList = rsp.getBest().getPoints(); + return pointList.calcDistance(new DistanceCalc2D()); + } + } + + /** + * Calculates the length of the current route of the SimLocationActuator. + * @param ms the component + * @return the length of the current route + */ + public double getCurrentRouteLength(SimLocationActuator ms) + { + return currentRoutes.get(ms).getPointList().calcDistance(new DistanceCalc2D()); + } public void setOsmFileLocation(String osmFileLocation) { this.osmFileLocation = osmFileLocation; diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteImpl.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..4f973e54197a170522d562ee514d1fd9d56d0241 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteImpl.java @@ -0,0 +1,238 @@ +/* + * 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 . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.local; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import com.graphhopper.util.PointList; +import com.graphhopper.util.shapes.GHPoint3D; + +import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; +import de.tud.kom.p2psim.impl.topology.PositionVector; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor.RouteSegmentListener; + +/** + * This class contains one trajectory from a start to a destination. It saves + * the respective points (coordinates) along the path with a given movement + * speed and also (if enabled) the assigned IDs of the roads and walkways that + * are traversed. + * + * TODO add segment handling + * + * Segment handling is only done if there is a segment listener registered for + * the respective client. + * + * @author Bjoern Richerzhagen + * @version 1.0, Aug 9, 2017 + */ +public class RouteImpl implements Route { + + private final RouteSensor sensor; + + private PositionVector start; + + private PositionVector destination; + + private PointList pointList; + + private final List positionsList; + + private final List routeSegments; + + private final Set segmentListeners; + + private int currentIndex; + + private int currentSegmentIndex; + + private int routeLength; + + private int routeSegmentsLength; + + private boolean reachedTarget; + + /** + * + * @param start + * @param destination + * @param pointList + * @param segmentListeners + * @param routeSegments + */ + public RouteImpl(PositionVector start, + PositionVector destination, PointList pointList, + Set segmentListeners, RouteSensor sensor, + List routeSegments) { + this.sensor = sensor; + this.start = start; + this.destination = destination; + this.pointList = pointList; + this.positionsList = new LinkedList<>(); + // Create Position vectors ONCE + for (GHPoint3D temp : pointList) { + positionsList + .add(RealWorldStreetsMovement.transformGPSWindowToOwnWorld( + temp.getLat(), temp.getLon())); + } + routeLength = positionsList.size(); + this.segmentListeners = segmentListeners; + this.routeSegments = routeSegments; + this.routeSegmentsLength = routeSegments.size(); + } + + /** + * + * @param start + * @param destination + * @param pointList + */ + public RouteImpl(PositionVector start, + PositionVector destination, PointList pointList) { + this(start, destination, pointList, Collections.emptySet(), null, + Collections.emptyList()); + } + + public PositionVector getStart() { + return start; + } + + public PositionVector getDestination() { + return destination; + } + + @Override + public Location getTargetLocation() { + return destination; + } + + @Override + public boolean hasSegmentInformation() { + return routeSegmentsLength != 0; + } + + @Override + public RouteSegment getCurrentSegment() { + if (!hasSegmentInformation()) { + throw new UnsupportedOperationException( + "To access segments within a Route, you need to enable the respective functionality in the local movement strategy (usually: calculateRouteSegments=true)"); + } + return routeSegments.get(currentSegmentIndex); + } + + @Override + public List getSegmentsAhead() { + if (!hasSegmentInformation()) { + throw new UnsupportedOperationException( + "To access segments within a Route, you need to enable the respective functionality in the local movement strategy (usually: calculateRouteSegments=true)"); + } + return Collections.unmodifiableList(routeSegments + .subList(currentSegmentIndex, routeSegmentsLength)); + } + + @Override + public List getSegmentsBehind() { + if (!hasSegmentInformation()) { + throw new UnsupportedOperationException( + "To access segments within a Route, you need to enable the respective functionality in the local movement strategy (usually: calculateRouteSegments=true)"); + } + return Collections.unmodifiableList(routeSegments + .subList(0, currentSegmentIndex)); + } + + /** + * Update the internal location with the given movement speed + * + * @param speed + * @param realPosition + * @return + */ + public PositionVector updateCurrentLocation(SimLocationActuator comp, + double speed, double tolerance) { + List sublist = positionsList.subList(currentIndex, + routeLength); + PositionVector newPosition = null; + for (PositionVector candidate : sublist) { + newPosition = comp.getRealPosition().moveStep(candidate, speed); + if (candidate.distanceTo(comp.getRealPosition()) < tolerance) { + currentIndex++; + } else { + break; + } + } + + /* + * Segment handling (also inform listeners!) + */ + if (routeSegmentsLength > 0 + && routeSegmentsLength > currentSegmentIndex) { + List segmentSublist = routeSegments + .subList(currentSegmentIndex + 1, routeSegmentsLength); + for (RouteSegmentImpl candidate : segmentSublist) { + if (candidate.getFromRouteIndex() >= currentIndex) { + break; + } + currentSegmentIndex++; + segmentListeners.forEach(l -> l.onChangedRouteSegment(sensor, + this, routeSegments.get(currentSegmentIndex - 1), + candidate)); + } + } + + /* + * Reached target flag + */ + if (currentIndex >= routeLength) { + reachedTarget = true; + } + + return newPosition; + } + + /** + * True, if the trajectory is done and the node reached the target.s + * + * @return + */ + public boolean reachedDestination() { + return reachedTarget; + } + + @Override + public String toString() { + return "\n\tfrom " + start.toString() + " to " + destination.toString() + + "\n\tstep: " + currentIndex + " length: " + routeLength; + } + + public PointList getPointList() { + return pointList; + } + + public int getCurrentIndex() { + return this.currentIndex; + } + +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteSegmentImpl.java b/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteSegmentImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..92087144136a2116a41ee9e912d17f6d5e0351fa --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/local/RouteSegmentImpl.java @@ -0,0 +1,76 @@ +/* + * 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 . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.local; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route.RouteSegment; + +/** + * Implementation of a {@link RouteSegment} + * + * @author Bjoern Richerzhagen + * @version 1.0, Aug 10, 2017 + */ +public class RouteSegmentImpl implements RouteSegment { + + private final String id; + + private final int fromRouteIndex; + + private final List routeLocations; + + /** + * The segment and associated points (via their index) + * + * @param id + * @param fromRouteIndex + */ + public RouteSegmentImpl(String id, int fromRouteIndex, + Location startLocation) { + this.id = id; + this.fromRouteIndex = fromRouteIndex; + this.routeLocations = new LinkedList<>(); + this.routeLocations.add(startLocation); + } + + public void addRouteLocation(Location location) { + this.routeLocations.add(location); + } + + @Override + public String getSegmentId() { + return id; + } + + @Override + public List getSegmentLocations() { + return Collections.unmodifiableList(routeLocations); + } + + public int getFromRouteIndex() { + return fromRouteIndex; + } + +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java index aa8601c061fec4c4cfc5aa434f716a440579e9e4..6a16929d3e42349241b2937180eee9aefe7029ae 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java @@ -95,6 +95,16 @@ public class GPSCalculation { { return metersPerPixel; } + + public static double getWorldDimensionsX() { + return Binder.getComponentOrNull(Topology.class) + .getWorldDimensions().getX(); + } + + public static double getWorldDimensionsY() { + return Binder.getComponentOrNull(Topology.class) + .getWorldDimensions().getY(); + } public static double getLatUpper() { return latCenter + ((Binder.getComponentOrNull(Topology.class) diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java index 67004a75be2888d0386ab063bc13dac0592d075c..9a05d1bd4f3a175db8cb8f2b963c26ebe25e46fc 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java @@ -24,13 +24,10 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import java.util.Set; import java.util.Vector; -import javax.swing.JComponent; - import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.movement.MovementModel; @@ -52,7 +49,6 @@ import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; -import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationActuator; /** * Modular Movement Model uses different models/strategies to create a movement @@ -117,6 +113,8 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac private Map currentTarget = new LinkedHashMap<>(); + private Map routeSensorComponents = new LinkedHashMap<>(); + private boolean initialized = false; private long timeBetweenMoveOperation = Simulator.SECOND_UNIT; @@ -128,9 +126,6 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac .getWorldDimensions(); this.rand = Randoms.getRandom(ModularMovementModel.class); - // Setting this model as default to prevent older code from braking. See Changelog. - modelVisualisation = new ModularMovementModelViz(this); - // scheduling initalization! Event.scheduleImmediately(this, null, EVENT_INIT); } @@ -142,6 +137,9 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac public void initialize() { if (!initialized) { + if (modelVisualisation == null) { + modelVisualisation = new ModularMovementModelViz(this); + } VisualizationInjector.injectComponent(modelVisualisation); if (mapVisualization != null) { VisualizationInjector.injectComponent(mapVisualization); @@ -224,8 +222,11 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac @Override public void addComponent(SimLocationActuator comp) { moveableHosts.add(comp); + if (!routeSensorComponents.containsKey(comp)) { + routeSensorComponents.put(comp, new RouteSensorComponent(comp)); + } } - + public Set getAllLocationActuators() { return moveableHosts; } diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModelViz.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModelViz.java index 2af5ac35f6a895e6facb99969dfd423580914282..d2f9534792899d22d437bb06bf21cd6ff218243a 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModelViz.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModelViz.java @@ -21,12 +21,16 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm; import java.awt.AlphaComposite; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.RenderingHints; +import java.awt.Stroke; import java.awt.geom.Point2D; +import java.util.LinkedHashMap; +import java.util.Map; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; @@ -36,10 +40,20 @@ import javax.swing.event.ChangeListener; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.impl.topology.PositionVector; +import de.tud.kom.p2psim.impl.topology.movement.local.AbstractLocalMovementStrategy; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent; +import de.tud.kom.p2psim.impl.topology.views.visualization.world.NodeVisInteractionListener; +import de.tudarmstadt.maki.simonstrator.api.Host; +import de.tudarmstadt.maki.simonstrator.api.Oracle; +import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; +import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route.RouteSegment; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor; /** * Visualization Component of the Attraction Points in the Modular Movement @@ -50,7 +64,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction * @version 1.0, 02.07.2015 */ public class ModularMovementModelViz extends JComponent - implements VisualizationComponent { + implements VisualizationComponent, NodeVisInteractionListener { protected ModularMovementModel movementModel; @@ -58,29 +72,35 @@ public class ModularMovementModelViz extends JComponent protected boolean showNodePositions = true; + protected boolean showTrajectories = false; + + protected boolean setupCalculatesTrajectories = false; + private JMenu menu; + private Map trajectoryVisualizations = new LinkedHashMap<>(); + private final static int NODE_PAD = 2; private final static int ATTR_PAD = 5; private static Color COLOR_ATTR_POINT = Color.decode("#4A7B9D"); - public ModularMovementModelViz() - { + public ModularMovementModelViz() { init(); } - protected void init() - { + protected void init() { setBounds(0, 0, VisualizationInjector.getWorldX(), VisualizationInjector.getWorldY()); + VisualizationInjector.addInteractionListener(this); setOpaque(true); setVisible(true); menu = new JMenu("Mobility Model"); menu.add(createCheckboxAp()); menu.add(createCheckboxNodePositions()); + menu.add(createCheckboxTrajectories()); } public ModularMovementModelViz(ModularMovementModel model) { @@ -114,6 +134,28 @@ public class ModularMovementModelViz extends JComponent return checkBox; } + private JCheckBoxMenuItem createCheckboxTrajectories() { + setupCalculatesTrajectories = AbstractLocalMovementStrategy.isCalculatingRouteSegments(); + final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem( + "show node trajectories", showTrajectories); + checkBox.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + showTrajectories = checkBox.isSelected(); + if (!setupCalculatesTrajectories) { + AbstractLocalMovementStrategy + .setCalculationOfRouteSegments(showTrajectories); + } + VisualizationInjector.invalidate(); + } + }); + if (!setupCalculatesTrajectories) { + AbstractLocalMovementStrategy + .setCalculationOfRouteSegments(showTrajectories); + } + return checkBox; + } + @Override public void paint(Graphics g) { super.paintComponent(g); @@ -131,6 +173,73 @@ public class ModularMovementModelViz extends JComponent drawNodePosition(g2, comp); } } + + if (showTrajectories) { + for (TrajectoryVis tVis : trajectoryVisualizations.values()) { + tVis.drawTrajectory(g2); + } + } + } + + @Override + public void onHostClick(long hostID, boolean isActive) { + if (isActive) { + Host h = Oracle.getHostByID(INodeID.get(hostID)); + try { + RouteSensor routeSensor = h.getComponent(RouteSensor.class); + trajectoryVisualizations.put(hostID, + new TrajectoryVis(routeSensor)); + } catch (ComponentNotAvailableException e) { + // ignore. + } + + } else { + trajectoryVisualizations.remove(hostID); + } + } + + /** + * Visualizes the movement trajectory of a given node. + * + * @author Bjoern Richerzhagen + * @version 1.0, Aug 10, 2017 + */ + private class TrajectoryVis { + + private final RouteSensor routeSensor; + + public TrajectoryVis(RouteSensor routeSensor) { + this.routeSensor = routeSensor; + } + + public void drawTrajectory(Graphics2D g2) { + Route rt = routeSensor.getRoute(); + if (!rt.hasSegmentInformation()) { + return; + } + for (RouteSegment segment : rt.getSegmentsAhead()) { + Location lastLoc = null; + for (Location loc : segment.getSegmentLocations()) { + if (lastLoc == null) { + lastLoc = loc; + continue; + } + g2.setColor(Color.MAGENTA); + g2.setStroke(new BasicStroke(3.0f)); + g2.drawLine( + VisualizationInjector + .scaleValue(lastLoc.getLongitude()), + VisualizationInjector + .scaleValue(lastLoc.getLatitude()), + VisualizationInjector + .scaleValue(loc.getLongitude()), + VisualizationInjector + .scaleValue(loc.getLatitude())); + lastLoc = loc; + } + } + } + } /** @@ -166,7 +275,7 @@ public class ModularMovementModelViz extends JComponent VisualizationInjector.scaleValue(point.y) - ATTR_PAD, ATTR_PAD * 2 + 1, ATTR_PAD * 2 + 1); g2.setColor(COLOR_ATTR_POINT); - int radius = (int) aPoint.getRadius() + ATTR_PAD; + int radius = VisualizationInjector.scaleValue(aPoint.getRadius()) + ATTR_PAD; g2.drawOval(VisualizationInjector.scaleValue(point.x) - radius, VisualizationInjector.scaleValue(point.y) - radius, radius * 2 + 1, radius * 2 + 1); diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMultiTypeMovementModel.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMultiTypeMovementModel.java index 2450c3916ae871ce55154989b0b4444a81116580..0990f3742f610635bcbb1755f80a59b3dfbc250d 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMultiTypeMovementModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMultiTypeMovementModel.java @@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm; import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.impl.topology.PositionVector; +import de.tud.kom.p2psim.impl.topology.movement.local.RouteImpl; import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement; import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy; import de.tud.kom.p2psim.impl.util.Either; @@ -13,6 +14,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction import java.util.HashMap; import java.util.LinkedList; +import java.util.List; /** * This class is meant to be used with the RealWorldStreetsMovement @@ -187,6 +189,22 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel Monitor.log(ModularMultiTypeMovementModel.class, Monitor.Level.DEBUG, String.format("Client %s changed his transition strategy from %s to %s", ms.getHost().getId().toString(), usedStrategy.getClass(), newStrategy.getClass())); } + /** + * Returns a list of points representing the current route of the component. Points are + * in x / y values of the own world. + * @param ms the component + * @return list of movement points. + */ + public List getMovementPoints(SimLocationActuator ms) + { + return ((RealWorldStreetsMovement) localMovementStrategy).getMovementPoints(ms); + } + + public RealWorldStreetsMovement getMovementStrategy() + { + return (RealWorldStreetsMovement) localMovementStrategy; + } + /** * Sets the default {@link ITransitionStrategy} for the specified {@link SimLocationActuator}. * @param ms The SimLocationActuator diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/MultiTypeMovementListener.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/MultiTypeMovementListener.java index 7dde3a983c15ab0717dca846839d97228085240b..b4337304518bbc6aba534f2a8749f319af51d816 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/MultiTypeMovementListener.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/MultiTypeMovementListener.java @@ -3,7 +3,10 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; /** - * Created by Clemens on 13.03.2017. + * Listener for the {@link ModularMultiTypeMovementModel} to get + * informed about important changes in the movement. + * + * @author Clemens Krug */ public interface MultiTypeMovementListener { diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/RouteSensorComponent.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/RouteSensorComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..fd065d218eca5c396c2ab40df71c86d35d24e176 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/RouteSensorComponent.java @@ -0,0 +1,120 @@ +/* + * 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 . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.modularosm; + +import java.util.LinkedHashSet; +import java.util.Set; + +import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; +import de.tudarmstadt.maki.simonstrator.api.Host; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor; + +/** + * The OSM-based models provide an implementation of the {@link RouteSensor}, + * which is added as a new host component. It is created by supporting mobility + * models, registers itself with the host container and can then be retrieved + * via the host container from w.g., a local movement strategy. + * + * @author Bjoern Richerzhagen + * @version 1.0, Aug 10, 2017 + */ +public class RouteSensorComponent implements RouteSensor { + + private final SimLocationActuator actuator; + + private Route currentRoute; + + private final Set listeners; + + private final Set segmentListeners; + + public RouteSensorComponent(SimLocationActuator actuator) { + this.actuator = actuator; + this.listeners = new LinkedHashSet<>(); + this.segmentListeners = new LinkedHashSet<>(); + actuator.getHost().registerComponent(RouteSensorComponent.this); + } + + @Override + public void initialize() { + // + } + + @Override + public void shutdown() { + // + } + + public SimLocationActuator getActuator() { + return actuator; + } + + @Override + public Host getHost() { + return actuator.getHost(); + } + + @Override + public Route getRoute() { + return currentRoute; + } + + @Override + public void addRouteListener(RouteListener listener) { + listeners.add(listener); + } + + @Override + public void removeRouteListener(RouteListener listener) { + listeners.remove(listener); + } + + @Override + public void addRouteSegmentListener(RouteSegmentListener listener) { + segmentListeners.add(listener); + } + + @Override + public void removeRouteSegmentListener(RouteSegmentListener listener) { + segmentListeners.remove(listener); + } + + /* + * The following methods are used by the mobility models. + */ + + public void setNewRoute(Route newRoute) { + // notifies listeners + listeners.forEach(l -> l.onChangedRoute(this, currentRoute, newRoute)); + currentRoute = newRoute; + } + + public void reachedDestination() { + // notifies listeners + listeners.forEach(l -> l.onReachedDestination(this, currentRoute)); + } + + public Set getSegmentListeners() { + return segmentListeners; + } + +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/RandomInAreaTransitionStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/RandomInAreaTransitionStrategy.java index f7a1d20d8f07f037ea0d3f723a2f620685c50283..c7779868086ed094bd49afc31a9cd1b934711276 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/RandomInAreaTransitionStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/RandomInAreaTransitionStrategy.java @@ -1,5 +1,14 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; + import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.impl.topology.PositionVector; @@ -10,8 +19,6 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; -import java.util.*; - /** * This {@link ITransitionStrategy} makes clients move around randomly in a specified area. You can specify the target * area center via the {@link #updateTargetAttractionPoint(SimLocationActuator, AttractionPoint)} method. The client will then start @@ -23,7 +30,8 @@ import java.util.*; public class RandomInAreaTransitionStrategy implements ITransitionStrategy { - private Random random; + private final Random random = Randoms + .getRandom(RandomInAreaTransitionStrategy.class); private LinkedHashSet aPoints = new LinkedHashSet<>(); @@ -45,11 +53,6 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy */ private int defaultRadius; - public RandomInAreaTransitionStrategy() - { - random = Randoms.getRandom(this.getClass()); - } - @Override public AttractionPoint getAssignment(SimLocationActuator comp) { diff --git a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java index 374552ffeffd19aac51a90afc08d644d4fe6f91f..15ce6e3004a5aa31997de0388836bfbcb08f9026 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java @@ -20,6 +20,7 @@ package de.tud.kom.p2psim.impl.topology.views; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -43,7 +44,6 @@ import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.component.sensor.handover.HandoverSensor; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; -import edu.emory.mathcs.backport.java.util.Arrays; /** * This topology view offers a topology for mobile apps - mobile clients diff --git a/src/de/tud/kom/p2psim/impl/transport/modular/ITransProtocol.java b/src/de/tud/kom/p2psim/impl/transport/modular/ITransProtocol.java index e419823ae5db7dd1fde8be21464832e542057600..b88ab8d7eba0dcc6a122cac874535366c568b78d 100644 --- a/src/de/tud/kom/p2psim/impl/transport/modular/ITransProtocol.java +++ b/src/de/tud/kom/p2psim/impl/transport/modular/ITransProtocol.java @@ -21,6 +21,7 @@ package de.tud.kom.p2psim.impl.transport.modular; import de.tud.kom.p2psim.api.transport.TransMessage; +import de.tud.kom.p2psim.api.transport.TransProtocol; import de.tudarmstadt.maki.simonstrator.api.Message; import de.tudarmstadt.maki.simonstrator.api.component.network.NetID; import de.tudarmstadt.maki.simonstrator.api.component.transport.TransInfo; @@ -63,5 +64,11 @@ public interface ITransProtocol { * @return */ public int getHeaderSize(); + + /** + * Protocol type of this instance. + * @return + */ + public TransProtocol getProtocol(); } diff --git a/src/de/tud/kom/p2psim/impl/transport/modular/ModularTransLayer.java b/src/de/tud/kom/p2psim/impl/transport/modular/ModularTransLayer.java index ee0dbeed3dd1f40fa222bd6caf049d0f51e2f136..3e66bdc4e47ab6d950a397b381dfdb07297c35b0 100644 --- a/src/de/tud/kom/p2psim/impl/transport/modular/ModularTransLayer.java +++ b/src/de/tud/kom/p2psim/impl/transport/modular/ModularTransLayer.java @@ -253,7 +253,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, @Override public void setTransportMessageListener(TransMessageListener listener) { this.listener = listener; - addTransMsgListener(listener, localPort); + addTransMsgListener(transport.getProtocol(), listener, localPort); } /* @@ -265,7 +265,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, Monitor.log(ModularTransLayer.class, Level.DEBUG, "Trying tor remove a non-existing transport message listener."); return; } - removeTransMsgListener(listener, localPort); + removeTransMsgListener(transport.getProtocol(), localPort); listener = null; } @@ -403,18 +403,18 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, } - protected void addTransMsgListener(TransMessageListener receiver, int port) { + protected void addTransMsgListener(TransProtocol protocol, TransMessageListener receiver, int port) { PortListener pl = portListeners.get(port); if (pl == null) { pl = new PortListener(); portListeners.put(port, pl); } - pl.addListener(receiver); + pl.setListener(protocol, receiver); } - protected void removeTransMsgListener(TransMessageListener listener, int port) { + protected void removeTransMsgListener(TransProtocol protocol, int port) { PortListener pl = portListeners.get(port); - pl.removeListener(listener); + pl.removeListener(protocol); if (pl.isEmpty()) { portListeners.remove(port); } @@ -445,15 +445,12 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, * Notify the Protocol of a received Message */ TransMessage receivedMessage = null; - Class protocol = null; if (msg.getProtocol() == TransProtocol.TCP) { receivedMessage = tcp.get(nme.getReceiver()).receive(msg, senderInfo); - protocol = UDP.class; } else if (msg.getProtocol() == TransProtocol.UDP) { receivedMessage = udp.get(nme.getReceiver()).receive(msg, senderInfo); - protocol = TCPMessageBased.class; } else { throw new AssertionError("No Protocol " + msg.getProtocol()); } @@ -519,10 +516,10 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, } } // deliver real message - pl.dispatch(pMsg.getPayload(), protocol, senderInfo, + pl.dispatch(pMsg.getPayload(), msg.getProtocol(), senderInfo, receivedMessage.getCommId()); } else { - pl.dispatch(receivedMessage.getPayload(), protocol, + pl.dispatch(receivedMessage.getPayload(), msg.getProtocol(), senderInfo, receivedMessage.getCommId()); } } else { @@ -547,27 +544,34 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, */ public class PortListener { - private List transListeners; + private Map transListeners; public PortListener() { - transListeners = new LinkedList(); + transListeners = new LinkedHashMap(); } - public void addListener(TransMessageListener listener) { - if (!transListeners.contains(listener)) { - transListeners.add(listener); + public void setListener(TransProtocol protocol, TransMessageListener listener) { + if (transListeners.containsKey(protocol)) { + Monitor.log(ModularTransLayer.class, Level.WARN, "Overwriting an existing TransMessageListener for protocol %s.", protocol.toString()); } + transListeners.put(protocol, listener); } - public void removeListener(TransMessageListener listener) { - transListeners.remove(listener); + public void removeListener(TransProtocol protocol) { + if (!transListeners.containsKey(protocol)) { + Monitor.log(ModularTransLayer.class, Level.WARN, "Trying to delete an non-existing TransMessageListener for protocol %s.", protocol.toString()); + } + transListeners.remove(protocol); } public void dispatch(Message msg, - Class protocol, TransInfo sender, int commId) { - for (TransMessageListener listener : transListeners) { - listener.messageArrived(msg, sender, commId); + TransProtocol protocol, TransInfo sender, int commId) { + if (transListeners.containsKey(protocol)) { + transListeners.get(protocol).messageArrived(msg, sender, commId); + } else { + Monitor.log(ModularTransLayer.class, Level.WARN, "Message arrived, but no TransMessageListener active for %s.", protocol.toString()); } + } public boolean isEmpty() { diff --git a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocol.java b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocol.java index 8bf39d16024c823b99ccb3977d72945894c75651..a52e31facb8c8e8a4a1dda71bfc31650d5ce0461 100644 --- a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocol.java +++ b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocol.java @@ -129,6 +129,11 @@ public class TransmissionControlProtocol extends AbstractTransProtocol { public int getHeaderSize() { return 20; } + + @Override + public TransProtocol getProtocol() { + return TransProtocol.TCP; + } @Override public void send(Message msg, NetID receiverNet, int receiverPort, diff --git a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocolDummy.java b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocolDummy.java index 63379b0ff6eaa43fcc4ba14637442843b45a09d0..4324d2c4468c494f69518890a56b05268af8707d 100644 --- a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocolDummy.java +++ b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocolDummy.java @@ -65,5 +65,10 @@ public class TransmissionControlProtocolDummy extends AbstractTransProtocol { public int getHeaderSize() { return TransProtocol.TCP.getHeaderSize(); } + + @Override + public TransProtocol getProtocol() { + return TransProtocol.TCP; + } } diff --git a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/UserDatagramProtocol.java b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/UserDatagramProtocol.java index 890ae6ad9b65c31cc56fe127c001c6362ebb3130..0379c1bcb41ae9c601785b1f3a23b2f15349483d 100644 --- a/src/de/tud/kom/p2psim/impl/transport/modular/protocol/UserDatagramProtocol.java +++ b/src/de/tud/kom/p2psim/impl/transport/modular/protocol/UserDatagramProtocol.java @@ -24,6 +24,7 @@ import de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason; import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.network.NetProtocol; import de.tud.kom.p2psim.api.network.SimNetInterface; +import de.tud.kom.p2psim.api.transport.TransProtocol; import de.tud.kom.p2psim.impl.transport.UDPMessage; import de.tud.kom.p2psim.impl.transport.modular.AbstractTransProtocol; import de.tudarmstadt.maki.simonstrator.api.Message; @@ -65,4 +66,9 @@ public class UserDatagramProtocol extends AbstractTransProtocol { return 8; } + @Override + public TransProtocol getProtocol() { + return TransProtocol.UDP; + } + } diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/CustomDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/CustomDistribution.java index fbdeeb7904f9c8f52d87c0021c49d520538f1cdb..cf41cc4ad350cd9226f2d6d82624aaf47b5b19c2 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/CustomDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/CustomDistribution.java @@ -27,7 +27,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; */ public class CustomDistribution implements Distribution { - private Random rand = Randoms.getRandom(this); + private Random rand = Randoms.getRandom(CustomDistribution.class); private String csvFile = ""; diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/ExponentialDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/ExponentialDistribution.java index 6e07202790bb62c9bc6964cdf5df050ea2a68d1c..b1d87e68c9507727bf84864c759c31c25bacbaf6 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/ExponentialDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/ExponentialDistribution.java @@ -50,7 +50,8 @@ public class ExponentialDistribution implements Distribution { if (distr == null) throw new ConfigurationException("Mu was not set for exponential distribution " + this); - double random = Randoms.getRandom(this).nextDouble(); + double random = Randoms.getRandom(ExponentialDistribution.class) + .nextDouble(); double result; try { diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/LimitedNormalDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/LimitedNormalDistribution.java index 55538861994678a78c39d88aa9e12d08da406dcf..2682540bf505df551018f085be82da36bec0ed7a 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/LimitedNormalDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/LimitedNormalDistribution.java @@ -132,7 +132,9 @@ public class LimitedNormalDistribution implements Distribution { } public double returnValue() { - double random = pmin + Randoms.getRandom(this).nextDouble() * pfactor; + double random = pmin + + Randoms.getRandom(LimitedNormalDistribution.class) + .nextDouble() * pfactor; double result; try { diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/LognormalDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/LognormalDistribution.java index 4035d7086bc2d30080a7003243d1db5110cfbc61..94fe50e4a3cf91ee0e6aca18db038d0d54641db5 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/LognormalDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/LognormalDistribution.java @@ -22,10 +22,10 @@ package de.tud.kom.p2psim.impl.util.stat.distributions; -import umontreal.iro.lecuyer.probdist.LognormalDist; import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.util.Distribution; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; +import umontreal.iro.lecuyer.probdist.LognormalDist; public class LognormalDistribution implements Distribution { @@ -48,7 +48,8 @@ public class LognormalDistribution implements Distribution { } public double returnValue() { - double random = Randoms.getRandom(this).nextDouble(); + double random = Randoms.getRandom(LognormalDistribution.class) + .nextDouble(); double result = 0; try { diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/MixedLogNormalDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/MixedLogNormalDistribution.java index 02f703fa3ec360f009a5a645b4ee2d0b2ccd28e3..e7f4c7d922ffb44122a27c29ab151f5a0469e8d7 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/MixedLogNormalDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/MixedLogNormalDistribution.java @@ -22,10 +22,10 @@ package de.tud.kom.p2psim.impl.util.stat.distributions; -import umontreal.iro.lecuyer.probdist.LognormalDist; import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.util.Distribution; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; +import umontreal.iro.lecuyer.probdist.LognormalDist; public class MixedLogNormalDistribution implements Distribution { @@ -65,7 +65,8 @@ public class MixedLogNormalDistribution implements Distribution { } public double returnValue() { - double random = Randoms.getRandom(this).nextDouble(); + double random = Randoms.getRandom(MixedLogNormalDistribution.class) + .nextDouble(); double result = 0; try { result = weight1 * distr1.inverseF(random) + weight2 diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/NormalDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/NormalDistribution.java index 1ee47eff96f91712549275c78e52fce2e88ed270..3b1ed15d2742fec1504d2b5f312d20b177096d7c 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/NormalDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/NormalDistribution.java @@ -35,7 +35,7 @@ public class NormalDistribution implements Distribution { private NormalDistributionImpl normal; - private Random randomGen = Randoms.getRandom(this); + private Random randomGen = Randoms.getRandom(NormalDistribution.class); private double mu; diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/PoissonDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/PoissonDistribution.java index 6bd6716fe9cc90272820671d57452237647ca9a0..9705f80b1b236b0f65beff7265d877492085fe05 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/PoissonDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/PoissonDistribution.java @@ -42,7 +42,7 @@ public class PoissonDistribution implements Distribution { // returns the x-value for a random value in the cdf public double returnValue() { - double random = Randoms.getRandom(this) + double random = Randoms.getRandom(PoissonDistribution.class) .nextDouble(); int result; diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/UniformDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/UniformDistribution.java index 6ad985f204a6cdfea2b57cb7c3a468f7e566e7ba..e9a6d08582eda9980e19bfbc5e92558950034c3f 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/UniformDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/UniformDistribution.java @@ -50,7 +50,8 @@ public class UniformDistribution implements Distribution { */ public double returnValue() { - return min + factor * Randoms.getRandom(this).nextDouble(); + return min + factor + * Randoms.getRandom(UniformDistribution.class).nextDouble(); } /** diff --git a/src/de/tud/kom/p2psim/impl/util/stat/distributions/ZipfDistribution.java b/src/de/tud/kom/p2psim/impl/util/stat/distributions/ZipfDistribution.java index a6bdb286a08788ef37be720b2b6b2dc6a34a5b17..e72765e8b1d190e456d65104ffa67bd553b22b0b 100644 --- a/src/de/tud/kom/p2psim/impl/util/stat/distributions/ZipfDistribution.java +++ b/src/de/tud/kom/p2psim/impl/util/stat/distributions/ZipfDistribution.java @@ -66,7 +66,8 @@ public class ZipfDistribution implements Distribution { // rank = 1 ... maximum_Number_Of_Ranks => 1/rank = 0..1 return 1 / (Math - .pow(1 / (Randoms.getRandom(this).nextDouble() * harmonicNormFactor), + .pow(1 / (Randoms.getRandom(ZipfDistribution.class).nextDouble() + * harmonicNormFactor), 1 / zipfExponent)); }