Commit 20020ed4 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Movement: movement speed remains constant at a random value between min

and max for one component. 
Models MAY set a new speed as they wish (api of MovementSupported
changed to allow this behavior). Can be used, e.g., to update speed once
a target waypoint has been reached.
parent ea52b3cf
......@@ -109,10 +109,18 @@ public interface MovementSupported {
public double getMaxMovementSpeed();
/**
* Gets a movement speed between min and max movement speed. This will be
* randomly calculated!
* Gets the currently set movement speed for that node. Initialized with a
* random value between min and max. Use setMovementSpeed() to lateron
* change the value.
*
* @return A random movement speed between min and max movement speed.
* @return
*/
public double getMovementSpeed();
/**
* Allows to set the movement speed in meter per second. Should be between
* min and max speed, but this is not enforced.
*/
public void setMovementSpeed(double speed);
}
......@@ -90,6 +90,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
private Set<PositionListener> positionListener = new LinkedHashSet<PositionListener>();
private Set<MovementListener> movementListeners = new LinkedHashSet<>();
private double currentMovementSpeed = -1;
/**
* This reference is nulled after placement, as the process is only done
......@@ -258,18 +260,26 @@ public class DefaultTopologyComponent implements TopologyComponent {
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
}
private void calcRandomMovementSpeed() {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentMovementSpeed = (value * (max_speed - min_speed)) + min_speed;
}
@Override
public double getMovementSpeed() {
double min_speed;
double max_speed;
min_speed = getMinMovementSpeed();
max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
double speed = (value * (max_speed - min_speed)) + min_speed;
return speed;
if (currentMovementSpeed == -1) {
calcRandomMovementSpeed();
}
return this.currentMovementSpeed;
}
@Override
public void setMovementSpeed(double speed) {
this.currentMovementSpeed = speed;
}
@Override
......
......@@ -40,7 +40,7 @@ public abstract class AbstractLocalMovementStrategy implements
/*
* FIXME BR: why exactly is only the maxSpeed considered here?
*/
return ms.getMaxMovementSpeed() * scaleFactor;
return ms.getMovementSpeed() * scaleFactor;
}
public void setScaleFactor(double scaleFactor) {
......
......@@ -46,6 +46,8 @@ public class AttractionPoint implements MovementSupported {
private double maxSpeed;
private double currentSpeed = -1;
public AttractionPoint(PositionVector posVec, double minSpeed,
double maxSpeed) {
this.posVec = posVec;
......@@ -100,16 +102,20 @@ public class AttractionPoint implements MovementSupported {
}
@Override
public double getMovementSpeed() {
double min_speed;
double max_speed;
min_speed = getMinMovementSpeed();
max_speed = getMaxMovementSpeed();
public void setMovementSpeed(double speed) {
this.currentSpeed = speed;
}
double value = rnd.nextDouble();
double speed = (value * (max_speed - min_speed)) + min_speed;
return speed;
@Override
public double getMovementSpeed() {
if (currentSpeed == -1) {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentSpeed = (value * (max_speed - min_speed)) + min_speed;
}
return currentSpeed;
}
}
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