Commit 288e94c4 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

MovementModel and Location updates

- deprecated MovementSupported
- used LocationSensor and LocationActuator
- decoupled nested listener structures used within the old models
parent 0001f6eb
......@@ -21,10 +21,8 @@
package de.tud.kom.p2psim.api.topology;
import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.topology.UnderlayTopologyProvider;
/**
......@@ -35,8 +33,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.topology.UnderlayTopologyP
* @author Bjoern Richerzhagen
* @version 1.0, 21.02.2012
*/
public interface TopologyComponent extends SimHostComponent, MovementSupported,
MovementListener, UnderlayTopologyProvider, LocationSensor {
public interface TopologyComponent extends SimHostComponent,
UnderlayTopologyProvider, SimLocationActuator {
/**
* Returns the Topology-Object that provides access to {@link TopologyView}s
......
......@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.api.topology.movement;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
/**
* All interested parties can register themselves as a {@link MovementListener}
......@@ -29,7 +30,9 @@ package de.tud.kom.p2psim.api.topology.movement;
*
* @author Bjoern Richerzhagen
* @version 1.0, 03.03.2012
* @deprecated replaced with {@link LocationListener}s
*/
@Deprecated
public interface MovementListener {
/**
......
......@@ -33,25 +33,12 @@ import de.tud.kom.p2psim.api.topology.TopologyComponent;
public interface MovementModel {
/**
* Add a {@link MovementSupported} component to this movement model
* Register all {@link SimLocationActuator}s that are controlled by this
* movement model.
*
* @param comp
*/
public void addComponent(MovementSupported comp);
/**
* Adds a {@link MovementListener} to this {@link MovementModel}
*
* @param listener
*/
public void addMovementListener(MovementListener listener);
/**
* removes a listener
*
* @param listener
*/
public void removeMovementListener(MovementListener listener);
public void addComponent(SimLocationActuator actuator);
/**
* If you want to trigger the movement periodically, set this to a time
......
......@@ -21,6 +21,8 @@
package de.tud.kom.p2psim.api.topology.movement;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
/**
* Identifier for Components or Applications that support movement. If for
......@@ -29,7 +31,11 @@ import de.tud.kom.p2psim.impl.topology.PositionVector;
*
* @author Bjoern Richerzhagen
* @version 1.0, 04/25/2011
* @deprecated we will try to clean up this interface in favor of
* {@link LocationSensor} or {@link SimLocationSensor} and
* {@link LocationActuator}
*/
@Deprecated
public interface MovementSupported {
/**
......@@ -76,24 +82,6 @@ public interface MovementSupported {
*/
public void removeMovementListener(MovementListener listener);
/**
* Adds a {@link PositionListener} to this movementSupported. If the Host
* reaches the Position, which is given through the listener, then will be
* triggered the listener
*
* @param listener
* The listener, which will be triggered.
*/
public void addPositionListener(PositionListener listener);
/**
* Removes the Listener from this MovementSupported Object.
*
* @param listener
* The listener, which should be removed.
*/
public void removePositionListener(PositionListener listener);
/**
* Gets the minimum movement speed of this movable component.
*
......
......@@ -21,34 +21,60 @@
package de.tud.kom.p2psim.api.topology.movement;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
/**
* This is the Listener for a Position. The method reached Position will be
* called, if the given Position and radius is reached. This mean, the position
* of the host is in the radius of the specified Position.
* A version of {@link LocationSensor} that provides access to the underlying
* {@link PositionVector} data.
*
* @author Christoph Muenker
* @version 1.0, 28.06.2013
* @author Bjoern Richerzhagen
* @version 1.0, Jun 14, 2016
*/
public interface PositionListener {
public interface SimLocationActuator extends LocationActuator {
/**
* Specified the Position, which is listen
* Generic position, this allows us to use the GNP or other models that
* support the Position-Interface. This call does not consume any energy,
* even if a Positioning-Device is specified in the EnergyModel. It should
* not be used inside an Application, as the more sophisticated way is to
* add a GPS-Component to the EnergyModel and call getEstimatedPosition()
*
* @return The position, to which is listen
* <b>This is used in high-performance calculations inside the TopologyViews
* and should therefore NOT return copies but the object instance to prevent
* fetching the object after each movement!</b>
*
* @return
*/
public PositionVector getRealPosition();
/**
* Gets the minimum movement speed of this movable component.
*
* @return The minimum movement speed
*/
public double getMinMovementSpeed();
/**
* Gets the maximum movement speed of this movable component.
*
* @return The maximum movement speed
*/
public PositionVector getPosition();
public double getMaxMovementSpeed();
/**
* Specified the radius, for to the position, at when the listener should be
* called.
* Gets the currently set movement speed for that node. Initialized with a
* random value between min and max. Use setMovementSpeed() to lateron
* change the value.
*
* @return the radius
* @return
*/
public double getRadius();
public double getMovementSpeed();
/**
* Will be called, if the specified position is reached.
* Allows to set the movement speed in meter per second. Should be between
* min and max speed, but this is not enforced.
*/
public void reachedPosition();
public void setMovementSpeed(double speed);
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.api.topology.movement.local;
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.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.Either;
/**
* This interface provides method definitions for the implementation of a local
* movement strategy used by the abstract waypoint movement model.
*
* @author Fabio Zöllner
* @version 1.0, 09.04.2012
*/
public interface LocalMovementStrategy {
public double getMovementSpeed(MovementSupported ms);
public void setWaypointModel(WaypointModel model);
public void setObstacleModel(ObstacleModel model);
public void setScaleFactor(double scaleFactor);
/**
* This method is called by the abstract waypoint movement model to
* determine the next position on the way to the specified destination.
*
* Return value: - Left new PositionVector with the next position - Right
* true: The destination has been reached false: Do nothing.
*
* @param comp
* @param destination
* @return Either the new position or Boolean (true) if no further position
* can be calculated
*/
public Either<PositionVector, Boolean> nextPosition(MovementSupported comp,
PositionVector destination);
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.api.topology.movement.local;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
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;
/**
* This interface provides method definitions for the implementation of a local
* movement strategy used by the abstract waypoint movement model.
*
* @author Fabio Zöllner
* @version 1.0, 09.04.2012
*/
public interface LocalMovementStrategy {
public double getMovementSpeed(SimLocationActuator ms);
public void setWaypointModel(WaypointModel model);
public void setObstacleModel(ObstacleModel model);
public void setScaleFactor(double scaleFactor);
/**
* This method is called by the abstract waypoint movement model to
* determine the next position on the way to the specified destination.
*
* Return value: - Left new PositionVector with the next position - Right
* true: The destination has been reached false: Do nothing.
*
* @param comp
* @param destination
* @return Either the new position or Boolean (true) if no further position
* can be calculated
*/
public Either<PositionVector, Boolean> nextPosition(SimLocationActuator comp,
PositionVector destination);
}
......@@ -31,6 +31,7 @@ import de.tud.kom.p2psim.api.topology.TopologyListener;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tudarmstadt.maki.simonstrator.api.component.GlobalComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
/**
* Each MAC has a view on the global topology of hosts (ie. the
......@@ -43,8 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* @author Bjoern Richerzhagen
* @version 1.0, 21.02.2012
*/
public interface TopologyView
extends TopologyListener, MovementListener, GlobalComponent {
public interface TopologyView extends TopologyListener, GlobalComponent, LocationListener {
/**
* The {@link PhyType} this View represents
......
......@@ -21,13 +21,11 @@
package de.tud.kom.p2psim.impl.topology;
import java.util.LinkedHashMap;
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 java.util.function.Consumer;
import de.tud.kom.p2psim.api.common.HostProperties;
import de.tud.kom.p2psim.api.common.SimHost;
......@@ -36,9 +34,6 @@ import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
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.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.PositionListener;
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;
......@@ -58,7 +53,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.N
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
......@@ -68,8 +62,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.sis.util.SiSTopologyProvider;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener;
import de.tudarmstadt.maki.simonstrator.api.operation.Operations;
import de.tudarmstadt.maki.simonstrator.api.operation.PeriodicOperation;
/**
* Default implementation of a {@link TopologyComponent}.
......@@ -87,11 +79,11 @@ public class DefaultTopologyComponent implements TopologyComponent {
private Topology topology;
private Set<PositionListener> positionListener = new LinkedHashSet<PositionListener>();
private Set<MovementListener> movementListeners = new LinkedHashSet<>();
private double currentMovementSpeed = -1;
private Map<LocationListener, LocationRequestImpl> openRequests = new LinkedHashMap<LocationListener, LocationRequestImpl>();
private List<LocationListener> listeners = new LinkedList<>();
/**
* This reference is nulled after placement, as the process is only done
......@@ -119,8 +111,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
sis.provide().nodeState(SiSTypes.PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID.getSingleIDSet(getHost()
.getId());
Set<INodeID> localID = INodeID
.getSingleIDSet(getHost().getId());
@Override
public Location getValue(INodeID nodeID,
......@@ -151,8 +143,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
public void eventOccurred(Object content, int type) {
if (getHost().getLinkLayer().hasPhy(PhyType.WIFI)) {
new SiSTopologyProvider(sis, SiSTypes.NEIGHBORS_WIFI,
DefaultTopologyComponent.this, getTopologyID(
NetInterfaceName.WIFI, true),
DefaultTopologyComponent.this,
getTopologyID(NetInterfaceName.WIFI, true),
DefaultTopologyComponent.class);
}
}
......@@ -166,8 +158,6 @@ public class DefaultTopologyComponent implements TopologyComponent {
@Override
public void shutdown() {
topology = null;
positionListener.clear();
movementListeners.clear();
host = null;
}
......@@ -176,31 +166,6 @@ public class DefaultTopologyComponent implements TopologyComponent {
return host;
}
@Override
public void positionChanged() {
for (PositionListener listener : positionListener) {
if (listener.getPosition().distanceTo(position) < listener
.getRadius()) {
listener.reachedPosition();
}
}
}
@Override
public void afterComponentMoved(MovementSupported comp) {
for (MovementListener moveListener : movementListeners) {
moveListener.afterComponentMoved(this);
}
}
@Override
public boolean movementActive() {
/*
* Needed? Maybe redesign the API
*/
return true;
}
@Override
public PositionVector getRealPosition() {
return position;
......@@ -211,26 +176,6 @@ public class DefaultTopologyComponent implements TopologyComponent {
return topology;
}
@Override
public void addPositionListener(PositionListener listener) {
positionListener.add(listener);
}
@Override
public void removePositionListener(PositionListener listener) {
positionListener.remove(listener);
}
@Override
public void addMovementListener(MovementListener listener) {
movementListeners.add(listener);
}
@Override
public void removeMovementListener(MovementListener listener) {
movementListeners.remove(listener);
}
@Override
public double getMinMovementSpeed() {
HostProperties properties = getHost().getProperties();
......@@ -243,13 +188,14 @@ public class DefaultTopologyComponent implements TopologyComponent {
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
}
private void calcRandomMovementSpeed() {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentMovementSpeed = (value * (max_speed - min_speed)) + min_speed;
this.currentMovementSpeed = (value * (max_speed - min_speed))
+ min_speed;
}
@Override
......@@ -259,7 +205,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
}
return this.currentMovementSpeed;
}
@Override
public void setMovementSpeed(double speed) {
this.currentMovementSpeed = speed;
......@@ -274,21 +220,47 @@ public class DefaultTopologyComponent implements TopologyComponent {
return position.clone();
}
@Override
public void updateCurrentLocation(double longitude, double latitude) {
position.setEntries(longitude, latitude);
// notify "non-request" listeners
for (LocationListener locationListener : listeners) {
locationListener.onLocationChanged(getHost(), getLastLocation());
}
}
@Override
public void requestLocationUpdates(LocationRequest request,
LocationListener listener) {
if (openRequests.containsKey(listener)) {
throw new AssertionError("This LocationListener is already in use.");
throw new AssertionError(
"This LocationListener is already in use.");
}
if (request == null) {
/*
* This listener wants to be triggered on EVERY position update, but
* it does not want to request position updates.
*/
if (!listeners.contains(listener)) {
listeners.add(listener);
}
} else {
/*
* Listener has its own request timing.
*/
LocationRequestImpl req = (LocationRequestImpl) request;
openRequests.put(listener, req);
req.immunizeAndStart(listener);
}
LocationRequestImpl req = (LocationRequestImpl) request;
openRequests.put(listener, req);
req.immunizeAndStart(listener);
}
@Override
public void removeLocationUpdates(LocationListener listener) {
listeners.remove(listener);
LocationRequestImpl impl = openRequests.remove(listener);
impl.cancel(listener);
if (impl != null) {
impl.cancel(listener);
}
}
@Override
......@@ -296,11 +268,10 @@ public class DefaultTopologyComponent implements TopologyComponent {
return new LocationRequestImpl();
}
private Map<LocationListener, LocationRequestImpl> openRequests = new LinkedHashMap<LocationListener, LocationRequestImpl>();
/**
* Update 15.03.16 added support for multiple listeners (however, frequency etc.
* is immune after the first request is registered.)
* Update 15.03.16 added support for multiple listeners (however, frequency
* etc. is immune after the first request is registered.)
*
* @author Bjoern Richerzhagen
* @version 1.0, Mar 15, 2016
......@@ -312,11 +283,11 @@ public class DefaultTopologyComponent implements TopologyComponent {
private long interval = 1 * Simulator.MINUTE_UNIT;
private int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
private Location lastLocation = null;
private List<LocationListener> listeners = new LinkedList<LocationListener>();
public LocationRequestImpl() {
// nothing to do
}
......@@ -335,7 +306,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
Event.scheduleImmediately(this, null, 0);
} else {
// Fire each new listener at least once
listener.onLocationChanged(getLastLocation());
listener.onLocationChanged(getHost(), getLastLocation());
}
listeners.add(listener);
}
......@@ -359,8 +330,10 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (!listeners.isEmpty()) {
// Only reschedule, if at least one listener is ... listening
Location newLoc = getLastLocation();
if (lastLocation == null || lastLocation.distanceTo(newLoc) > 0) {
listeners.forEach((LocationListener listener) -> listener.onLocationChanged(newLoc));
if (lastLocation == null
|| lastLocation.distanceTo(newLoc) > 0) {
listeners.forEach((LocationListener listener) -> listener
.onLocationChanged(getHost(), newLoc));
lastLocation = newLoc;
}
Event.scheduleWithDelay(interval, this, null, 0);
......@@ -380,9 +353,10 @@ public class DefaultTopologyComponent implements TopologyComponent {
private final static LinkedHashMap<TopologyID, LocalGraphView> graphViews = new LinkedHashMap<>();
@Override
public TopologyID getTopologyID(NetInterfaceName netName, boolean onlyOnline) {
TopologyID id = TopologyID.getIdentifier(netName.toString()
+ (onlyOnline ? "-online" : "-all"),
public TopologyID getTopologyID(NetInterfaceName netName,
boolean onlyOnline) {
TopologyID id = TopologyID.getIdentifier(
netName.toString() + (onlyOnline ? "-online" : "-all"),
DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id, new LocalGraphView(netName, onlyOnline));
......@@ -393,12 +367,13 @@ public class DefaultTopologyComponent implements TopologyComponent {
@Override
public TopologyID getTopologyID(NetInterfaceName netName,
boolean onlyOnline, double range) {
TopologyID id = TopologyID.getIdentifier(netName.toString()
+ (onlyOnline ? "-online" : "-all") + String.valueOf(range),
TopologyID id = TopologyID.getIdentifier(
netName.toString() + (onlyOnline ? "-online" : "-all")
+ String.valueOf(range),
DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id, new LocalGraphView(netName, onlyOnline,
range));
this.graphViews.put(id,
new LocalGraphView(netName, onlyOnline, range));
}
return id;
}
......@@ -433,8 +408,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
* @author Bjoern Richerzhagen
* @version 1.0, May 13, 2015
*/
private class LocalGraphView implements MovementListener,
ConnectivityListener {
private class LocalGraphView
implements LocationListener, ConnectivityListener {
/**
* Marker: has there been any movement since the graph view was last
......@@ -481,7 +456,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
assert !isDistanceBased || phy.isBroadcastMedium();
if (phy.isBroadcastMedium()) {
// register as listener for movement
addMovementListener(LocalGraphView.this);
DefaultTopologyComponent.this.requestLocationUpdates(null,
LocalGraphView.this);
}
// register as listener for online/offline events
if (onlyOnline) {
......@@ -522,17 +498,17 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Consider all nodes as potential neighbors
for (MacLayer neighborMac : topoView.getAllMacs()) {
// create, but do NOT add the node object
INode neighbor = currentView.createNode(neighborMac
.getHost().getId());
INode neighbor = currentView
.createNode(neighborMac.getHost().getId());
// only online nodes (already in graph)
if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
// Distance?
if (topoView.getDistance(mac.getMacAddress(),
neighborMac.getMacAddress()) <= distance) {
IEdge edge = currentView.createEdge(mac
.getHost().getId(), neighborMac
.getHost().getId());
IEdge edge = currentView.createEdge(
mac.getHost().getId(),
neighborMac.getHost().getId());
currentView.addElement(edge);
}
}
......@@ -542,21 +518,22 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Build neighborhoods based on underlay neighbors (1-hop)
for (MacLayer mac : topoView.getAllMacs()) {
// Rely on underlay for neighbors
List<MacAddress> neighbors = topoView.getNeighbors(mac
.getMacAddress());
List<MacAddress> neighbors = topoView
.getNeighbors(mac.getMacAddress());
for (MacAddress neighborMac : neighbors) {
// create, but do NOT add the node object
INode neighbor = currentView.createNode(topoView
.getMac(neighborMac).getHost().getId());
INode neighbor = currentView.createNode(
topoView.getMac(neighborMac).getHost().getId());
// only online nodes (already in graph)
if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
IEdge edge = currentView.createEdge(mac.getHost()
.getId(), topoView.getMac(neighborMac)
.getHost().getId());
IEdge edge = currentView.createEdge(
mac.getHost().getId(),
topoView.getMac(neighborMac).getHost()
.getId());
currentView.addElement(edge);
edge.setProperty(SiSTypes.PHY_DISTANCE, topoView
.getDistance(mac.getMacAddress(),
edge.setProperty(SiSTypes.PHY_DISTANCE,
topoView.getDistance(mac.getMacAddress(),
neighborMac));
}
}
......@@ -592,7 +569,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
}
@Override
public void afterComponentMoved(MovementSupported comp) {
public void onLocationChanged(Host host, Location location) {
this.isInvalid = true;
}
......
......@@ -44,6 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -78,7 +79,7 @@ public class TopologyFactory implements HostComponentFactory {
private static DBHostListManager dbHostList = null;
private static boolean useRegionGroups = false;
private boolean alreadyCreatedInstances = false;
private boolean alreadyAddedMovement = false;
......@@ -118,14 +119,28 @@ public class TopologyFactory implements HostComponentFactory {
}
measurementDBHosts.put(host, hostMeta);
}
TopologyComponent toCo = new DefaultTopologyComponent(host, topo, placement);
TopologyComponent toCo = new DefaultTopologyComponent(host, topo,
placement);
if (movement != null) {
/*
* Movement models influence a node's current position via the
* SimLocationActuator-Interface.
*/
movement.addComponent(toCo);
movement.addMovementListener(toCo);
/*
* Need to register TopoViews as movement listeners, as they might
* need to update topologies after each movement.
*/
for (PhyType phy : PhyType.values()) {
TopologyView view = topo.getTopologyView(phy);
if (view != null) {
toCo.requestLocationUpdates(null, view);
}
}
}
Monitor.log(TopologyFactory.class, Level.INFO,
"Topology Component for Host %s created. Placement: %s, Movement: %s",
Monitor.log(TopologyFactory.class, Level.INFO,
"Topology Component for Host %s created. Placement: %s, Movement: %s",
host.getHostId(), placement, movement);
return toCo;
}
......@@ -191,13 +206,6 @@ public class TopologyFactory implements HostComponentFactory {
((AbstractWaypointMovementModel) movement)
.setWaypointModel(waypointModel);
}
// add all views to the movement listener
for (PhyType phy : PhyType.values()) {
TopologyView view = topo.getTopologyView(phy);
if (view != null) {
movement.addMovementListener(view);
}
}
this.movement = movement;
}
......@@ -248,7 +256,7 @@ public class TopologyFactory implements HostComponentFactory {
return measurementDB;
}
public ObstacleModel getObstacleModel() {
return obstacleModel;
}
public ObstacleModel getObstacleModel() {
return obstacleModel;
}
}
......@@ -30,6 +30,7 @@ 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.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event;
......@@ -48,21 +49,14 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public abstract class AbstractMovementModel implements MovementModel {
private Set<MovementSupported> components = new LinkedHashSet<MovementSupported>();
private Set<SimLocationActuator> components = new LinkedHashSet<SimLocationActuator>();
protected PositionVector worldDimensions;
private List<MovementListener> listeners;
private long timeBetweenMoveOperations = -1;
private Random random = Randoms.getRandom(AbstractMovementModel.class);
public AbstractMovementModel() {
listeners = new LinkedList<MovementListener>();
// Simulator.registerAtEventBus(this);
}
/**
* Gets called periodically (after timeBetweenMoveOperations) or by an
* application and should be used to recalculate positions
......@@ -74,7 +68,7 @@ public abstract class AbstractMovementModel implements MovementModel {
*
* @return
*/
protected Set<MovementSupported> getComponents() {
protected Set<SimLocationActuator> getComponents() {
return components;
}
......@@ -86,7 +80,7 @@ public abstract class AbstractMovementModel implements MovementModel {
* @param component
*/
@Override
public void addComponent(MovementSupported component) {
public void addComponent(SimLocationActuator component) {
if (worldDimensions == null) {
worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
......@@ -94,25 +88,6 @@ public abstract class AbstractMovementModel implements MovementModel {
components.add(component);
}
@Override
public void addMovementListener(MovementListener listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
@Override
public void removeMovementListener(MovementListener listener) {
listeners.remove(listener);
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : listeners) {
listener.afterComponentMoved(comp);
}
comp.positionChanged();
}
/**
* Get a valid delta-Vector (does not cross world-boundaries and does not
* exceed moveSpeedLimit)
......@@ -124,9 +99,9 @@ public abstract class AbstractMovementModel implements MovementModel {
*/
protected PositionVector getRandomDeltaWithinSpeed(
PositionVector oldPosition, double minSpeed, double maxSpeed) {
return getRandomDelta(oldPosition, minSpeed
* getTimeBetweenMoveOperations() / Time.SECOND, maxSpeed
* getTimeBetweenMoveOperations() / Time.SECOND);
return getRandomDelta(oldPosition,
minSpeed * getTimeBetweenMoveOperations() / Time.SECOND,
maxSpeed * getTimeBetweenMoveOperations() / Time.SECOND);
}
/**
......@@ -175,6 +150,28 @@ public abstract class AbstractMovementModel implements MovementModel {
return true;
}
/**
* Call this method to finally update the location of the given component.
*
* @param actuator
* @param newPosition
*/
protected void updatePosition(SimLocationActuator actuator,
PositionVector newPosition) {
this.updatePosition(actuator, newPosition.getLongitude(), newPosition.getLatitude());
}
/**
* Call this method to finally update the location of the given component.
*
* @param actuator
* @param newPosition
*/
protected void updatePosition(SimLocationActuator actuator,
double longitude, double latitude) {
actuator.updateCurrentLocation(longitude, latitude);
}
/**
* Returns a random int between from and to, including both interval ends!
*
......
......@@ -21,15 +21,12 @@
package de.tud.kom.p2psim.impl.topology.movement;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.WeakHashMap;
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.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After;
......@@ -54,17 +51,15 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public abstract class AbstractWaypointMovementModel implements MovementModel {
private Set<MovementSupported> components = new LinkedHashSet<MovementSupported>();
private Set<SimLocationActuator> components = new LinkedHashSet<SimLocationActuator>();
protected PositionVector worldDimensions;
protected WeakHashMap<MovementSupported, PositionVector> destinations;
protected WeakHashMap<SimLocationActuator, PositionVector> destinations;
protected WeakHashMap<MovementSupported, Long> pauseTimes;
protected WeakHashMap<SimLocationActuator, Long> pauseTimes;
protected WeakHashMap<MovementSupported, Long> pauseInProgressTimes;
private List<MovementListener> listeners;
protected WeakHashMap<SimLocationActuator, Long> pauseInProgressTimes;
protected WaypointModel waypointModel;
......@@ -82,10 +77,9 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
public AbstractWaypointMovementModel(double worldX, double worldY) {
worldDimensions = new PositionVector(worldX, worldY);
listeners = new LinkedList<MovementListener>();
destinations = new WeakHashMap<MovementSupported, PositionVector>();
pauseTimes = new WeakHashMap<MovementSupported, Long>();
pauseInProgressTimes = new WeakHashMap<MovementSupported, Long>();
destinations = new WeakHashMap<SimLocationActuator, PositionVector>();
pauseTimes = new WeakHashMap<SimLocationActuator, Long>();
pauseInProgressTimes = new WeakHashMap<SimLocationActuator, Long>();
// Simulator.registerAtEventBus(this);
}
......@@ -126,11 +120,8 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
}
private void step() {
Set<MovementSupported> comps = getComponents();
for (MovementSupported mcomp : comps) {
if (!mcomp.movementActive()) {
continue;
}
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator mcomp : comps) {
Long currentPause = pauseInProgressTimes.get(mcomp);
if (currentPause != null) {
......@@ -168,8 +159,7 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
.nextPosition(mcomp, dst);
if (either.hasLeft()) {
mcomp.getRealPosition().replace(either.getLeft());
notifyPositionChange(mcomp);
updatePosition(mcomp, either.getLeft());
} else {
if (either.getRight().booleanValue()) {
pauseAndGetNextPosition(mcomp);
......@@ -181,13 +171,35 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
}
}
}
/**
* Call this method to finally update the location of the given component.
*
* @param actuator
* @param newPosition
*/
protected void updatePosition(SimLocationActuator actuator,
PositionVector newPosition) {
this.updatePosition(actuator, newPosition.getLongitude(), newPosition.getLatitude());
}
/**
* Call this method to finally update the location of the given component.
*
* @param actuator
* @param newPosition
*/
protected void updatePosition(SimLocationActuator actuator,
double longitude, double latitude) {
actuator.updateCurrentLocation(longitude, latitude);
}
/**
* Sets the pause time for the given component and calls nextPosition on it.
*
* @param comp
*/
private void pauseAndGetNextPosition(MovementSupported comp) {
private void pauseAndGetNextPosition(SimLocationActuator comp) {
Long pt = pauseTimes.get(comp) * Time.SECOND;
Monitor.log(AbstractWaypointMovementModel.class, Level.DEBUG,
"Position reached... pause time is " + pt);
......@@ -211,7 +223,7 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
* @param dst
* @return Returns true if the destination was reached
*/
private boolean reachedPosition(MovementSupported comp, PositionVector dst) {
private boolean reachedPosition(SimLocationActuator comp, PositionVector dst) {
PositionVector pos = comp.getRealPosition();
double distance = pos.distanceTo(dst);
......@@ -228,7 +240,7 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
* @param comp
* @return
*/
private PositionVector getDestination(MovementSupported comp) {
private PositionVector getDestination(SimLocationActuator comp) {
PositionVector dst = destinations.get(comp);
Monitor.log(AbstractWaypointMovementModel.class, Level.DEBUG, "Pos: "
......@@ -256,7 +268,7 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
* @param destination
* @param pauseTime
*/
protected void nextDestination(MovementSupported comp,
protected void nextDestination(SimLocationActuator comp,
PositionVector destination, long pauseTime) {
destinations.put(comp, destination);
pauseTimes.put(comp, pauseTime);
......@@ -269,14 +281,14 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
*
* @param component
*/
public abstract void nextPosition(MovementSupported component);
public abstract void nextPosition(SimLocationActuator component);
/**
* Get all participating Components
*
* @return
*/
protected Set<MovementSupported> getComponents() {
protected Set<SimLocationActuator> getComponents() {
return components;
}
......@@ -288,31 +300,12 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
* @param component
*/
@Override
public void addComponent(MovementSupported component) {
public void addComponent(SimLocationActuator component) {
Monitor.log(AbstractWaypointMovementModel.class, Level.DEBUG,
"AbstractMovementModel: Adding component to the movement model");
components.add(component);
}
@Override
public void addMovementListener(MovementListener listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
@Override
public void removeMovementListener(MovementListener listener) {
listeners.remove(listener);
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : listeners) {
listener.afterComponentMoved(comp);
}
comp.positionChanged();
}
/**
* Get a valid delta-Vector (does not cross world-boundaries and does not
* exceed moveSpeedLimit)
......
......@@ -33,6 +33,7 @@ import java.util.Vector;
import java.util.zip.GZIPInputStream;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.DefaultTopologyComponent;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -284,15 +285,12 @@ public class BonnMotionMovementModel extends AbstractMovementModel implements
public void eventOccurred(Object content, int type) {
if (type == EVENT_ID) {
BonnMotionEvent bme = (BonnMotionEvent) content;
Set<MovementSupported> components = getComponents();
for (MovementSupported comp : components) {
Set<SimLocationActuator> components = getComponents();
for (SimLocationActuator comp : components) {
if (((DefaultTopologyComponent) comp).getHost().getHostId() == bme
.getHostID()) {
PositionVector newPos = bme.getNextPosition();
PositionVector pos = comp.getRealPosition();
pos.setEntry(0, newPos.getX());
pos.setEntry(1, newPos.getY());
comp.positionChanged();
updatePosition(comp, newPos);
// FIXME Delete!! Only test-logger!
// log.warn(Simulator.getFormattedTime(Simulator.getCurrentTime())+" ID = " + bme.getHostID() +" pos = " + pos);
......
......@@ -34,6 +34,7 @@ import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modular.ModularMovementModel;
......@@ -64,9 +65,9 @@ public class CsvMovement extends AbstractMovementModel {
private LinkedList<LinkedList<CsvPathInfo>> readPathInfos;
private Map<MovementSupported, LinkedList<CsvPathInfo>> componentsPathsInfos;
private Map<SimLocationActuator, LinkedList<CsvPathInfo>> componentsPathsInfos;
private Map<MovementSupported, CsvMovementInfo> stateInfo;
private Map<SimLocationActuator, CsvMovementInfo> stateInfo;
/**
*
......@@ -79,14 +80,14 @@ public class CsvMovement extends AbstractMovementModel {
.getWorldDimensions();
this.file = movementPointsFile;
this.readPathInfos = new LinkedList<LinkedList<CsvPathInfo>>();
this.stateInfo = new LinkedHashMap<MovementSupported, CsvMovementInfo>();
this.componentsPathsInfos = new LinkedHashMap<MovementSupported, LinkedList<CsvPathInfo>>();
this.stateInfo = new LinkedHashMap<SimLocationActuator, CsvMovementInfo>();
this.componentsPathsInfos = new LinkedHashMap<SimLocationActuator, LinkedList<CsvPathInfo>>();
readData(minMovementSpeed, maxMovementSpeed);
}
@Override
public void addComponent(MovementSupported component) {
public void addComponent(SimLocationActuator component) {
super.addComponent(component);
LinkedList<CsvPathInfo> first = readPathInfos.removeFirst();
componentsPathsInfos.put(component, first);
......@@ -95,10 +96,8 @@ public class CsvMovement extends AbstractMovementModel {
@Override
public void move() {
Set<MovementSupported> comps = getComponents();
for (MovementSupported comp : comps) {
if (!comp.movementActive())
continue;
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition();
CsvMovementInfo info = stateInfo.get(comp);
......@@ -109,13 +108,12 @@ public class CsvMovement extends AbstractMovementModel {
return;
}
}
pos.add(info.getDelta());
updatePosition(comp, pos.plus(info.getDelta()));
info.setRemainingSteps(info.getRemainingSteps() - 1);
comp.positionChanged();
}
}
protected boolean assignNextMovementInfo(MovementSupported comp) {
protected boolean assignNextMovementInfo(SimLocationActuator comp) {
CsvMovementInfo info = stateInfo.get(comp);
PositionVector actPos = comp.getRealPosition();
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement;
import java.util.Map;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class DebugMovementModel extends AbstractWaypointMovementModel {
private Map<MovementSupported, PositionVector> lastDestinations = Maps.newHashMap();
private MovementSupported monitoredComp = null;
private long lastMonitoredPositionRequest = -1;
@XMLConfigurableConstructor({"worldX", "worldY"})
public DebugMovementModel(double worldX, double worldY) {
super(worldX, worldY);
}
@Override
public void nextPosition(MovementSupported component) {
PositionVector destination;
long pauseTime = 0;
long monitoredTime = 0;
PositionVector metricDimensions = waypointModel.getMetricDimensions();
PositionVector mapPixelRatio = metricDimensions.clone();
mapPixelRatio.divide(this.worldDimensions);
PositionVector speed = new PositionVector(getSpeedLimit(), getSpeedLimit());
speed.divide(mapPixelRatio);
double width = getWorldDimension(0);
double height = getWorldDimension(1);
if (monitoredComp == null) {
monitoredComp = component;
}
if (component == monitoredComp) {
if (lastMonitoredPositionRequest != -1) {
monitoredTime = Time.getCurrentTime() - lastMonitoredPositionRequest;
monitoredTime = monitoredTime / Time.SECOND;
}
lastMonitoredPositionRequest = Time.getCurrentTime();
}
PositionVector lastDestination = lastDestinations.get(component);
if (lastDestination != null) {
double lastX = lastDestination.getX();
double lastY = lastDestination.getY();
if (lastX == 0 && lastY == 0) {
if (component == monitoredComp) {
System.err.println("Vertical time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: North/West");
destination = new PositionVector(width, 0);
} else if (lastX != 0 && lastY != 0) {
if (component == monitoredComp) {
System.err.println("Vertical time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: North/East");
destination = new PositionVector(0, height); // * VisualizationInjector.getVisualScaleFactor()
} else if (lastX != 0 && lastY == 0) {
if (component == monitoredComp) {
System.err.println("Horizontal time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: South/East");
destination = new PositionVector(width, height);
} else { //if (lastX == 0 && lastY != 0) {
if (component == monitoredComp) {
System.err.println("Horizontal time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: South/West");
destination = new PositionVector(0, 0);
}
} else {
//System.err.println("Destination: North/West");
destination = new PositionVector(0, 0);
}
lastDestinations.put(component, destination);
nextDestination(component, destination, pauseTime);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement;
import java.util.Map;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class DebugMovementModel extends AbstractWaypointMovementModel {
private Map<SimLocationActuator, PositionVector> lastDestinations = Maps.newHashMap();
private SimLocationActuator monitoredComp = null;
private long lastMonitoredPositionRequest = -1;
@XMLConfigurableConstructor({"worldX", "worldY"})
public DebugMovementModel(double worldX, double worldY) {
super(worldX, worldY);
}
@Override
public void nextPosition(SimLocationActuator component) {
PositionVector destination;
long pauseTime = 0;
long monitoredTime = 0;
PositionVector metricDimensions = waypointModel.getMetricDimensions();
PositionVector mapPixelRatio = metricDimensions.clone();
mapPixelRatio.divide(this.worldDimensions);
PositionVector speed = new PositionVector(getSpeedLimit(), getSpeedLimit());
speed.divide(mapPixelRatio);
double width = getWorldDimension(0);
double height = getWorldDimension(1);
if (monitoredComp == null) {
monitoredComp = component;
}
if (component == monitoredComp) {
if (lastMonitoredPositionRequest != -1) {
monitoredTime = Time.getCurrentTime() - lastMonitoredPositionRequest;
monitoredTime = monitoredTime / Time.SECOND;
}
lastMonitoredPositionRequest = Time.getCurrentTime();
}
PositionVector lastDestination = lastDestinations.get(component);
if (lastDestination != null) {
double lastX = lastDestination.getX();
double lastY = lastDestination.getY();
if (lastX == 0 && lastY == 0) {
if (component == monitoredComp) {
System.err.println("Vertical time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: North/West");
destination = new PositionVector(width, 0);
} else if (lastX != 0 && lastY != 0) {
if (component == monitoredComp) {
System.err.println("Vertical time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: North/East");
destination = new PositionVector(0, height); // * VisualizationInjector.getVisualScaleFactor()
} else if (lastX != 0 && lastY == 0) {
if (component == monitoredComp) {
System.err.println("Horizontal time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: South/East");
destination = new PositionVector(width, height);
} else { //if (lastX == 0 && lastY != 0) {
if (component == monitoredComp) {
System.err.println("Horizontal time is " + monitoredTime + " with a speed of " + speed);
}
//System.err.println("Destination: South/West");
destination = new PositionVector(0, 0);
}
} else {
//System.err.println("Destination: North/West");
destination = new PositionVector(0, 0);
}
lastDestinations.put(component, destination);
nextDestination(component, destination, pauseTime);
}
}
......@@ -26,6 +26,7 @@ import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.stat.distributions.NormalDistribution;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
......@@ -53,7 +54,7 @@ public class GaussMarkovMovement extends AbstractMovementModel {
private Distribution distribution_d = null;
private Map<MovementSupported, GaussMarkovMovementInfo> stateInfos;
private Map<SimLocationActuator, GaussMarkovMovementInfo> stateInfos;
/**
*
......@@ -67,7 +68,7 @@ public class GaussMarkovMovement extends AbstractMovementModel {
"For GaussMarkovMovement alpha has to be set between zero and one.");
}
this.edgeThreshold = edgeThreshold;
this.stateInfos = new HashMap<MovementSupported, GaussMarkovMovement.GaussMarkovMovementInfo>();
this.stateInfos = new HashMap<SimLocationActuator, GaussMarkovMovement.GaussMarkovMovementInfo>();
}
@Override
......@@ -78,10 +79,9 @@ public class GaussMarkovMovement extends AbstractMovementModel {
if (distribution_d == null) {
distribution_d = new NormalDistribution(0, 1);
}
Set<MovementSupported> comps = getComponents();
for (MovementSupported comp : comps) {
if (!comp.movementActive())
continue;
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
// get old x and y
PositionVector pos = comp.getRealPosition();
GaussMarkovMovementInfo inf = stateInfos.get(comp);
......@@ -161,15 +161,13 @@ public class GaussMarkovMovement extends AbstractMovementModel {
inf.s_old = s_n;
PositionVector newPos = new PositionVector(x_n, y_n);
if (isValidPosition(newPos)) {
pos.setEntry(0, x_n);
pos.setEntry(1, y_n);
notifyPositionChange(comp);
updatePosition(comp, newPos);
}
}
}
@Override
public void addComponent(MovementSupported component) {
public void addComponent(SimLocationActuator component) {
super.addComponent(component);
GaussMarkovMovementInfo info = new GaussMarkovMovementInfo();
double rand = Randoms.getRandom(GaussMarkovMovement.class).nextDouble();
......
......@@ -22,7 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
/**
......@@ -39,14 +39,11 @@ public class RandomMovement extends AbstractMovementModel {
@Override
public void move() {
Set<MovementSupported> comps = getComponents();
for (MovementSupported comp : comps) {
if (!comp.movementActive())
continue;
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition();
pos.add(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed()));
notifyPositionChange(comp);
updatePosition(comp, pos.plus(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed())));
}
}
......
......@@ -26,6 +26,7 @@ import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time;
......@@ -37,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public class RandomPathMovement extends AbstractMovementModel {
private Map<MovementSupported, RandomPathMovementInfo> stateInfo;
private Map<SimLocationActuator, RandomPathMovementInfo> stateInfo;
/**
* Maximal time a component walks into one direction
......@@ -46,11 +47,11 @@ public class RandomPathMovement extends AbstractMovementModel {
public RandomPathMovement() {
super();
stateInfo = new LinkedHashMap<MovementSupported, RandomPathMovement.RandomPathMovementInfo>();
stateInfo = new LinkedHashMap<SimLocationActuator, RandomPathMovement.RandomPathMovementInfo>();
}
@Override
public void addComponent(MovementSupported component) {
public void addComponent(SimLocationActuator component) {
super.addComponent(component);
stateInfo.put(component, new RandomPathMovementInfo());
}
......@@ -61,23 +62,20 @@ public class RandomPathMovement extends AbstractMovementModel {
@Override
public void move() {
Set<MovementSupported> comps = getComponents();
for (MovementSupported comp : comps) {
if (!comp.movementActive())
continue;
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition();
RandomPathMovementInfo info = stateInfo.get(comp);
if (info.getRemainingSteps() == 0 || info.getDelta() == null) {
// assign new delta and new steps!
assignNewMovementInfo(comp);
}
pos.add(info.getDelta());
updatePosition(comp, pos.plus(info.getDelta()));
info.setRemainingSteps(info.getRemainingSteps() - 1);
notifyPositionChange(comp);
}
}
protected void assignNewMovementInfo(MovementSupported comp) {
protected void assignNewMovementInfo(SimLocationActuator comp) {
RandomPathMovementInfo info = stateInfo.get(comp);
PositionVector actPos = comp.getRealPosition();
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RandomWaypointMovement extends AbstractWaypointMovementModel {
private Random random = Randoms
.getRandom(RandomWaypointMovement.class);
@XMLConfigurableConstructor({"worldX", "worldY"})
public RandomWaypointMovement(double worldX, double worldY) {
super(worldX, worldY);
}
@Override
public void nextPosition(MovementSupported component) {
if (waypointModel == null) {
throw new ConfigurationException("SLAWMovementModel requires a valid waypoint model which hasn't been provided, cannot execute");
}
List<Waypoint> waypoints = Lists.newArrayList(waypointModel.getWaypoints(WeakWaypoint.class));
nextDestination(component, waypoints.get(random.nextInt(waypoints.size())).getPosition(), 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 <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RandomWaypointMovement extends AbstractWaypointMovementModel {
private Random random = Randoms
.getRandom(RandomWaypointMovement.class);
@XMLConfigurableConstructor({"worldX", "worldY"})
public RandomWaypointMovement(double worldX, double worldY) {
super(worldX, worldY);
}
@Override
public void nextPosition(SimLocationActuator component) {
if (waypointModel == null) {
throw new ConfigurationException("SLAWMovementModel requires a valid waypoint model which hasn't been provided, cannot execute");
}
List<Waypoint> waypoints = Lists.newArrayList(waypointModel.getWaypoints(WeakWaypoint.class));
nextDestination(component, waypoints.get(random.nextInt(waypoints.size())).getPosition(), 0);
}
}
......@@ -36,7 +36,7 @@ import javax.swing.JComponent;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure;
......@@ -76,7 +76,7 @@ public class SLAWMovementModel extends AbstractWaypointMovementModel {
protected int waypoint_ratio = 3;
protected Cluster[] clusters;
protected WeakHashMap<MovementSupported, SLAWMovementInformation> movementInformation;
protected WeakHashMap<SimLocationActuator, SLAWMovementInformation> movementInformation;
// TODO: minpause and maxpause are currently in microseconds... should be
// changed to minutes
......@@ -91,11 +91,11 @@ public class SLAWMovementModel extends AbstractWaypointMovementModel {
this.cluster_ratio = clusterRatio;
this.waypoint_ratio = waypointRatio;
movementInformation = new WeakHashMap<MovementSupported, SLAWMovementModel.SLAWMovementInformation>();
movementInformation = new WeakHashMap<SimLocationActuator, SLAWMovementModel.SLAWMovementInformation>();
}
@Override
public void nextPosition(MovementSupported node) {
public void nextPosition(SimLocationActuator node) {
// These variables have values same as in the matlab implementation of
// SLAW model by Seongik Hong, NCSU, US (3/10/2009)
......
......@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
/**
......@@ -47,10 +48,8 @@ public class TargetMovement extends AbstractMovementModel {
@Override
public void move() {
Set<MovementSupported> comps = getComponents();
for (MovementSupported comp : comps) {
if (!comp.movementActive())
continue;
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition();
if (Math.round(pos.getX()) == x && Math.round(pos.getY()) == y) {
continue;
......@@ -68,9 +67,8 @@ public class TargetMovement extends AbstractMovementModel {
} else {
vec = rVec;
}
pos.add(vec);
notifyPositionChange(comp);
updatePosition(comp, pos.plus(vec));
}
}
......
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