Commit 1ba71f80 authored by Julian Zobel's avatar Julian Zobel
Browse files

Street Movement Model

parent 38fab197
......@@ -67,26 +67,11 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/**
* Modular Movement Model uses different models/strategies to create a movement
* 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!
* <p>
* 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.
* It doesn't move the Hosts! It will be only assignment a new AttractionPoint!
*
* <p>
* M3: The {@link LocalMovementStrategy} is responsible for the movement of the
* Hosts. It moves the hosts to the assigned AttractionPoint, and if the
* AttractionPoint has moved, then will be followed. The
* {@link LocalMovementStrategy} will be called from the
* {@link ModularMovementModel} to do a Movement!
*
*
* @author Julian Zobel
*
*
*/
public class StreetMovement implements MovementModel, EventHandler {
......@@ -139,13 +124,7 @@ public class StreetMovement implements MovementModel, EventHandler {
*/
public void initialize() {
if (!initialized) {
//AttractionPoint p1 = new AttractionPoint((int)(worldDimensions.getX())/2,(int)(worldDimensions.getY()/2), "center");
//attractionPoints.add(p1);
//System.out.println("Initialized Attraction Points with length " + attractionPoints.size());
if (!initialized) {
setTimeBetweenMoveOperations(timeBetweenMoveOperation);
for (SimLocationActuator ms : moveableHosts) {
......@@ -158,18 +137,22 @@ public class StreetMovement implements MovementModel, EventHandler {
initialized = true;
}
}
private void initializeStartingPosition(SimLocationActuator ms) {
/**
* Assign the given node a random attraction point and place it
* on a randomly selected position on the line between
* the assigned attraction point and another adjacent attraction point.
*
* @param ms
*/
private void initializeStartingPosition(SimLocationActuator ms) {
// set an initial attraction point
int index = rand.nextInt(attractionPoints.size());
AttractionPoint a = attractionPoints.get(index);
attractionOfClients.put(ms, a);
AttractionPoint b = this.returnNextOrLastAttractionPoint(index);
System.out.println("Starting Postion berechnen");
PositionVector startingPosition = this.returnRandomPositionBetweenPoints(a,b);
ms.updateCurrentLocation(startingPosition.getLongitude(), startingPosition.getLatitude());
......@@ -177,17 +160,24 @@ public class StreetMovement implements MovementModel, EventHandler {
positions.put(ms, ms.getRealPosition());
}
/**
* Returns a randomly selected point on the line between the two given attraction points
*
* @param a Attraction Point A
* @param b Attraction Point B
* @return PositionVector of a randomly selected point on the connecting line of the attraction points
*/
private PositionVector returnRandomPositionBetweenPoints(AttractionPoint a,
AttractionPoint b) {
double longMin, longMax, latMin, latMax, longNew, latNew;
// Points have different longitude, so only search for random value for longitude
if(a.getRealPosition().getLongitude() != b.getRealPosition().getLongitude()) {
if(a.getRealPosition().getLongitude() < b.getRealPosition().getLongitude()) {
longMin = a.getRealPosition().getLongitude();
longMax = b.getRealPosition().getLongitude();
}
else {
} else {
longMin = b.getRealPosition().getLongitude();
longMax = a.getRealPosition().getLongitude();
}
......@@ -200,13 +190,12 @@ public class StreetMovement implements MovementModel, EventHandler {
return new PositionVector(longNew, a.getRealPosition().getLatitude());
}
if(a.getRealPosition().getLatitude() != b.getRealPosition().getLatitude()) {
// Points have different latitude, so only search for random value for latitude
if(a.getRealPosition().getLatitude() != b.getRealPosition().getLatitude()) {
if(a.getRealPosition().getLatitude() < b.getRealPosition().getLatitude()) {
latMin = a.getRealPosition().getLatitude();
latMax = b.getRealPosition().getLatitude();
}
else {
} else {
latMin = b.getRealPosition().getLatitude();
latMax = a.getRealPosition().getLatitude();
}
......@@ -257,15 +246,10 @@ public class StreetMovement implements MovementModel, EventHandler {
}
}
private PositionVector randomOffsetVector() {
double x = rand.nextGaussian() * 6;
double y = rand.nextGaussian() * 6;
return new PositionVector(x, y);
}
protected void move() {
/**
* Move all nodes towards their assigned attraction point
*/
protected void move() {
for (Entry<SimLocationActuator, AttractionPoint> entry : attractionOfClients.entrySet()) {
SimLocationActuator ms = entry.getKey();
......@@ -273,12 +257,10 @@ public class StreetMovement implements MovementModel, EventHandler {
.getRealPosition();
PositionVector destination = new PositionVector(attractionCenter);
if (destination.distanceTo(ms.getRealPosition()) > ms.getMovementSpeed()) {
if (destination.distanceTo(ms.getRealPosition()) > ms.getMovementSpeed()) {
PositionVector newPosition = ms.getRealPosition().moveStep(destination, ms.getMovementSpeed());
ms.updateCurrentLocation(newPosition.getLongitude(), newPosition.getLatitude());
positions.put(ms, newPosition);
positions.put(ms, newPosition);
} else {
assignNewAttractionPoint(ms);
}
......@@ -300,7 +282,11 @@ public class StreetMovement implements MovementModel, EventHandler {
EVENT_MOVE);
}
/**
* Assign the node a random attraction point, that is adjacent to the last one
*
* @param ms The given node
*/
private void assignNewAttractionPoint(SimLocationActuator ms) {
if(attractionOfClients.containsKey(ms)) {
......@@ -320,6 +306,12 @@ public class StreetMovement implements MovementModel, EventHandler {
}
}
/**
* Returns the next or last attraction point of the list to the given list index
*
* @param index Index of the attraction point, for which another attraction point should be returned
* @return Attraction Point
*/
private AttractionPoint returnNextOrLastAttractionPoint(int index) {
boolean updownrand = rand.nextBoolean();
......@@ -340,12 +332,7 @@ public class StreetMovement implements MovementModel, EventHandler {
move();
}
}
/**
* Only for visualization!
*
* @return
*/
protected List<AttractionPoint> getAttractionPoints() {
return attractionPoints;
}
......
......@@ -377,8 +377,7 @@ public class WifiTopologyView extends RangedTopologyView {
rxSensitivityDbm);
double satRange = interferenceHelper.calculateMaximalRadius(
maxTxPowerDbm, satDbm);
System.out.println("satRange: " + satRange + " csRange: " + csRange
+ " range: " + range);
//System.out.println("satRange: " + satRange + " csRange: " + csRange + " range: " + range);
Monitor.log(WifiTopologyView.class, Level.INFO,
"WiFi underlay ranges: satRange: " + satRange + " csRange: "
+ csRange + " range: " + range);
......
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