Commit 7f1a395b authored by Nils Richerzhagen's avatar Nils Richerzhagen
Browse files

Merge branch 'master' into 'nr/monitoring-clemens'

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.

See merge request !34
parents a4f71157 354b5d84
......@@ -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
*
......
......@@ -254,6 +254,11 @@ public class DefaultTopologyComponent implements TopologyComponent {
}
}
@Override
public void setNewTargetLocation(double longitude, double latitude) {
movementModel.changeTargetLocation(this, longitude, latitude);
}
@Override
public void requestLocationUpdates(LocationRequest request,
LocationListener listener) {
......
......@@ -70,6 +70,13 @@ public abstract class AbstractMovementModel implements MovementModel {
// 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
* application and should be used to recalculate positions
......
......@@ -120,6 +120,13 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
// 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
* application and should be used to recalculate positions
......
......@@ -212,6 +212,12 @@ public class ModularMovementModel implements MovementModel, EventHandler {
// not supported
}
@Override
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public void addComponent(SimLocationActuator comp) {
moveableHosts.add(comp);
......
......@@ -127,6 +127,12 @@ 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.
......@@ -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);
}
......@@ -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;
}
......@@ -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());
}
}
......@@ -107,6 +107,12 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
// 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;
SimHost host = comp.getHost();
......
......@@ -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,8 +409,10 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
@Override
public void eventOccurred(Object se, int type) {
if (arrivedAtAttractionPoint.contains(se)) {
doTransition((SimLocationActuator) se);
}
}
public void setSocialFactor(double socialFactor) {
if (socialFactor < 0 || socialFactor > 1) {
......
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