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