Commit 38fab197 authored by Julian Zobel's avatar Julian Zobel
Browse files

Nodes are placed on random positions on the connection lines between...

Nodes are placed on random positions on the connection lines between Attraction points instead of a complete random position.
parent 4b963d5b
......@@ -148,15 +148,8 @@ public class StreetMovement implements MovementModel, EventHandler {
setTimeBetweenMoveOperations(timeBetweenMoveOperation);
for (SimLocationActuator ms : moveableHosts) {
AttractionPoint a = attractionPoints.get(rand.nextInt(attractionPoints.size()));
attractionOfClients.put(ms, a);
ms.updateCurrentLocation(a.getRealPosition().getLongitude(), a.getRealPosition().getLatitude());
positions.put(ms, ms.getRealPosition());
for (SimLocationActuator ms : moveableHosts) {
initializeStartingPosition(ms);
}
// initial move
......@@ -166,13 +159,76 @@ public class StreetMovement implements MovementModel, EventHandler {
}
}
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());
positions.put(ms, ms.getRealPosition());
}
private PositionVector returnRandomPositionBetweenPoints(AttractionPoint a,
AttractionPoint b) {
double longMin, longMax, latMin, latMax, longNew, latNew;
if(a.getRealPosition().getLongitude() != b.getRealPosition().getLongitude()) {
if(a.getRealPosition().getLongitude() < b.getRealPosition().getLongitude()) {
longMin = a.getRealPosition().getLongitude();
longMax = b.getRealPosition().getLongitude();
}
else {
longMin = b.getRealPosition().getLongitude();
longMax = a.getRealPosition().getLongitude();
}
do {
longNew = rand.nextDouble()*longMax;
} while(longNew < longMin);
assert longNew > longMin && longNew <= longMax;
return new PositionVector(longNew, a.getRealPosition().getLatitude());
}
if(a.getRealPosition().getLatitude() != b.getRealPosition().getLatitude()) {
if(a.getRealPosition().getLatitude() < b.getRealPosition().getLatitude()) {
latMin = a.getRealPosition().getLatitude();
latMax = b.getRealPosition().getLatitude();
}
else {
latMin = b.getRealPosition().getLatitude();
latMax = a.getRealPosition().getLatitude();
}
do{
latNew = rand.nextDouble()*latMax;
} while(latNew < latMin);
assert latNew > latMin && latNew <= latMax;
return new PositionVector(a.getRealPosition().getLongitude(), latNew);
}
return null;
}
/**
* This default implementation relies on {@link PlacementModel}s to be
* configured in the {@link TopologyFactory}
*/
@Override
public void placeComponent(SimLocationActuator actuator) {
// not used here i guess
}
@Override
......@@ -263,6 +319,18 @@ public class StreetMovement implements MovementModel, EventHandler {
attractionOfClients.put(ms, attractionPoints.get(rand.nextInt(attractionPoints.size())));
}
}
private AttractionPoint returnNextOrLastAttractionPoint(int index) {
boolean updownrand = rand.nextBoolean();
if(updownrand) {
index = ((index + 1) % attractionPoints.size());
} else {
index = ((index - 1 + attractionPoints.size()) % attractionPoints.size());
}
return attractionPoints.get(index);
}
@Override
public void eventOccurred(Object content, int type) {
......
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