Commit 354b5d84 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Updates due to MovementActuator API change

- set target for movement currently only supported in the modularosm
model, feel free to extend other models by overwriting the default
implementation and create the corresponding merge requests.
parent 40749b3c
......@@ -46,6 +46,21 @@ public interface MovementModel {
*/
public void placeComponent(SimLocationActuator actuator);
/**
* OPTIONAL: tell the movement model to alter the current actuator's target
* location. If supported, the actuator will stop moving towards its old
* destination and start approaching the new destination instead.
*
* OBVIOUSLY, this is not supported by all models (from a semantic point of
* view)
*
* @param actuator
* @param longitude
* @param latitude
*/
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude);
/**
* If you want to trigger the movement periodically, set this to a time
*
......
......@@ -253,6 +253,11 @@ public class DefaultTopologyComponent implements TopologyComponent {
locationListener.onLocationChanged(getHost(), getLastLocation());
}
}
@Override
public void setNewTargetLocation(double longitude, double latitude) {
movementModel.changeTargetLocation(this, longitude, latitude);
}
@Override
public void requestLocationUpdates(LocationRequest request,
......
......@@ -69,6 +69,13 @@ public abstract class AbstractMovementModel implements MovementModel {
public void placeComponent(SimLocationActuator actuator) {
// not supported
}
@Override
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) throws UnsupportedOperationException {
// not supported by default. Extend this method, if needed.
throw new UnsupportedOperationException();
}
/**
* Gets called periodically (after timeBetweenMoveOperations) or by an
......
......@@ -119,6 +119,13 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
public void placeComponent(SimLocationActuator actuator) {
// not supported
}
@Override
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) throws UnsupportedOperationException {
// not supported by default. Extend this method, if needed.
throw new UnsupportedOperationException();
}
/**
* Gets called periodically (after timeBetweenMoveOperations) or by an
......
......@@ -211,6 +211,12 @@ public class ModularMovementModel implements MovementModel, EventHandler {
public void placeComponent(SimLocationActuator actuator) {
// not supported
}
@Override
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public void addComponent(SimLocationActuator comp) {
......
......@@ -127,9 +127,15 @@ public class AttractionPoint implements SimLocationActuator {
posVec.setEntries(longitude, latitude);
}
@Override
public void setNewTargetLocation(double longitude, double latitude)
throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public PositionVector getRealPosition() {
return posVec;
}
}
......@@ -59,10 +59,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* model. In this implementation, it has 3 different models/strategies.
* <p>
* M0: AttractionGenerator -> Generates the {@link AttractionPoint}s and place
* them on the map. The {@link AttractionPoint}s can't be moved, because they are
* static POIs from real-world data!
* them on the map. The {@link AttractionPoint}s can't be moved, because they
* are static POIs from real-world data!
* <p>
* M1: A general {@link MovementModel} is not used, because we use static attraction points.
* M1: A general {@link MovementModel} is not used, because we use static
* attraction points.
* <p>
* M2: The {@link TransitionStrategy}! It takes the Hosts, which should be moved
* around, but calculates only the assignment to the {@link AttractionPoint}s.
......@@ -94,7 +95,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
private final int EVENT_MOVE = 1;
private final int EVENT_INIT = 2;
protected PositionVector worldDimensions;
protected ITransitionStrategy transition;
......@@ -102,7 +103,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
protected IAttractionGenerator attractionGenerator;
protected LocalMovementStrategy localMovementStrategy;
protected IMapVisualization mapVisualization;
private Set<SimLocationActuator> moveableHosts = new LinkedHashSet<SimLocationActuator>();
......@@ -129,11 +130,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
* manually!
*/
public void initialize() {
if (!initialized) {
VisualizationInjector.injectComponent("AttractionPoints", -1,
new ModularMovementModelViz(this), true, false);
VisualizationInjector.injectComponent("Real Map", -2,
(JComponent) mapVisualization, true, false);
......@@ -145,10 +146,12 @@ public class ModularMovementModel implements MovementModel, EventHandler {
localMovementStrategy.setWaypointModel(Binder
.getComponentOrNull(Topology.class).getWaypointModel());
List<AttractionPoint> attractionPoints = attractionGenerator.getAttractionPoints();
List<AttractionPoint> attractionPoints = attractionGenerator
.getAttractionPoints();
transition.setAttractionPoints(attractionPoints);
//This adds the mobile hosts (smartphones/users) to the transition strategy
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
for (SimLocationActuator ms : moveableHosts) {
transition.addComponent(ms);
}
......@@ -161,7 +164,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
initialized = true;
}
}
/**
* This default implementation relies on {@link PlacementModel}s to be
* configured in the {@link TopologyFactory}
......@@ -171,6 +174,15 @@ public class ModularMovementModel implements MovementModel, EventHandler {
// not supported
}
@Override
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) {
/*
* Set a new target AP for the current actuator
*/
transition.updateTargetAttractionPoint(actuator, new AttractionPoint((int) longitude, (int) latitude, ""));
}
private void checkConfiguration() {
if (localMovementStrategy == null) {
throw new ConfigurationException(
......@@ -243,18 +255,26 @@ public class ModularMovementModel implements MovementModel, EventHandler {
Either<PositionVector, Boolean> either = localMovementStrategy
.nextPosition(ms, destination);
if (either.hasLeft()) {
ms.updateCurrentLocation(either.getLeft().getLongitude(), either.getLeft().getLatitude());
ms.updateCurrentLocation(either.getLeft().getLongitude(),
either.getLeft().getLatitude());
/*
* Check for negative or out of bound coordinates!
*/
assert ms.getRealPosition().getX() >= 0.0 && ms.getRealPosition().getX() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX();
assert ms.getRealPosition().getY() >= 0.0 && ms.getRealPosition().getY() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY();
assert ms.getRealPosition().getX() >= 0.0
&& ms.getRealPosition().getX() <= Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getX();
assert ms.getRealPosition().getY() >= 0.0
&& ms.getRealPosition().getY() <= Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getY();
} else {
transition.reachedAttractionPoint(ms);
}
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
public void setIAttractionGenerator(
IAttractionGenerator attractionGenerator) {
this.attractionGenerator = attractionGenerator;
}
......@@ -266,7 +286,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
public void setITransitionStrategy(ITransitionStrategy transition) {
this.transition = transition;
}
public void setIMapVisualization(IMapVisualization mapVisualization) {
this.mapVisualization = mapVisualization;
}
......@@ -286,6 +306,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
* @return
*/
protected List<AttractionPoint> getAttractionPoints() {
return new Vector<AttractionPoint>(attractionGenerator.getAttractionPoints());
return new Vector<AttractionPoint>(
attractionGenerator.getAttractionPoints());
}
}
......@@ -106,6 +106,12 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
public void reachedAttractionPoint(SimLocationActuator ms) {
// don't care, as no further assignment takes place.
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) {
assignments.put(comp, attractionPoint);
}
private void mappingHost(SimLocationActuator ms) {
SimHostComponent comp = (SimHostComponent) ms;
......
......@@ -49,17 +49,26 @@ public interface ITransitionStrategy {
public void setAttractionPoints(List<AttractionPoint> attractionPoints);
/**
* Add the object and assign the MS to an
* {@link AttractionPoint}.
* Add the object and assign the MS to an {@link AttractionPoint}.
*
* @param ms
*/
public void addComponent(SimLocationActuator ms);
/**
* Notify the TransitionStrategy, that the component has reached an attraction point.
* Notify the TransitionStrategy, that the component has reached an
* attraction point.
*
* @param ms
*/
public void reachedAttractionPoint(SimLocationActuator ms);
/**
* Updates the target attraction point of a component
*
* @param attractionPoint
*/
public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint);
}
......@@ -185,6 +185,13 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
doTransition(ms);
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) {
arrivedAtAttractionPoint.remove(comp);
assignments.put(comp, attractionPoint);
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
if (!arrivedAtAttractionPoint.contains(ms)) {
......@@ -402,7 +409,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
@Override
public void eventOccurred(Object se, int type) {
doTransition((SimLocationActuator) se);
if (arrivedAtAttractionPoint.contains(se)) {
doTransition((SimLocationActuator) se);
}
}
public void setSocialFactor(double socialFactor) {
......
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