Commit acff5b18 authored by Julian Zobel's avatar Julian Zobel
Browse files

Added implementation for Attraction Points to have specific pause time min and...

Added implementation for Attraction Points to have specific pause time min and max values. Adapted movement models to incorporate the alterrations
parent 3c3c3c92
......@@ -310,7 +310,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
.getComponentOrNull(Topology.class)
.getWorldDimensions().getY();
} else {
transition.reachedAttractionPoint(ms);
transition.reachedAttractionPoint(ms, ms.getCurrentTargetAttractionPoint());
}
}
......
......@@ -115,10 +115,10 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
.getWorldDimensions().getY();
} else {
if(transitions.containsKey(ms)) {
transitions.get(ms).reachedAttractionPoint(ms);
transitions.get(ms).reachedAttractionPoint(ms, ms.getCurrentTargetAttractionPoint());
}
else {
transition.reachedAttractionPoint(ms);
transition.reachedAttractionPoint(ms, ms.getCurrentTargetAttractionPoint());
}
movementListeners.forEach(l -> l.onTransition(ms));
}
......
......@@ -94,7 +94,7 @@ public abstract class AbstractAttractionBasedTransitionStrategy implements ITran
notifyListenersOfAssignmentUpdate(comp, attractionPoint);
}
protected long getRandomUniformDistributionPauseTime(AttractionPoint attractionPoint) {
private long getRandomUniformDistributionPauseTime(AttractionPoint attractionPoint) {
// if attraction point has own pause time use it, otherwise use default values
if(attractionPoint.hasPauseTime()) {
......@@ -105,7 +105,9 @@ public abstract class AbstractAttractionBasedTransitionStrategy implements ITran
}
}
protected long getPauseTime(AttractionPoint attractionPoint) {
return getRandomUniformDistributionPauseTime(attractionPoint);
}
public void setDefaultPauseTime(long defaultPauseTimeMin, long defaultPauseTimeMax) {
assert defaultPauseTimeMax >= 0 && defaultPauseTimeMin >= 0;
......
......@@ -88,7 +88,7 @@ public class FixedAssignmentStrategy extends AbstractAttractionBasedTransitionSt
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint) {
// don't care, as no further assignment takes place.
}
......
......@@ -20,9 +20,6 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
......@@ -31,6 +28,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
*
* @author Martin Hellwig
* @version 1.0, 03.07.2015
*
*
*
* @author Julian Zobel
* @version 1.1, 27.01.2020
*/
public interface ITransitionStrategy {
......@@ -59,7 +61,7 @@ public interface ITransitionStrategy {
*
* @param ms
*/
public void reachedAttractionPoint(SimLocationActuator ms);
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint);
/**
* Updates the target attraction point of a component
......
......@@ -61,7 +61,7 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
}
@Override
public void reachedAttractionPoint(SimLocationActuator comp) {
public void reachedAttractionPoint(SimLocationActuator comp, AttractionPoint attractionPoint) {
if(roamingStates.get(comp) == roamingTransitionState.PAUSE) {
return;
......@@ -70,7 +70,7 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
// start roaming if the AP was reached
if(roamingStates.get(comp) == roamingTransitionState.TRANSITION) {
// schedule the end of the roaming phase, which will make a new transition
Event.scheduleWithDelay(getRandomUniformDistributionPauseTime(), this, comp, EVENT_PAUSE_ENDED);
Event.scheduleWithDelay(getPauseTime(attractionPoint), this, comp, EVENT_PAUSE_ENDED);
}
this.roamingStates.put(comp, roamingTransitionState.PAUSE);
......@@ -78,18 +78,16 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
Event.scheduleWithDelay(gaussianDistributionPauseTime(Time.MINUTE, Time.MINUTE), this, comp, EVENT_ROAMING_PAUSE_ENDED);
}
@Override
protected long getRandomUniformDistributionPauseTime() {
protected long getPauseTime(AttractionPoint attractionPoint) {
if(useGaussianDistributedPauseTime) {
return gaussianDistributionPauseTime(pauseTimeMax-pauseTimeMin, 0.5*(pauseTimeMax-pauseTimeMin));
return gaussianDistributionPauseTime(defaultPauseTimeMax - defaultPauseTimeMin, 0.5*(defaultPauseTimeMax - defaultPauseTimeMin));
}
else {
return super.getRandomUniformDistributionPauseTime();
return getPauseTime(attractionPoint);
}
}
}
/**
* Use a gaussian distribution for the pause time interval generation, using a mean value and a standard deviation
......@@ -171,6 +169,8 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
AttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size()));
return assignment;
}
}
}
......@@ -59,7 +59,7 @@ public class ManualAssignmentStrategy implements ITransitionStrategy
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint) {
//Nothing to do.
}
......
......@@ -58,7 +58,7 @@ public class RandomInAreaTransitionStrategy extends AbstractAttractionBasedTrans
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint) {
currentTarget.put(ms, nextRandomPosition(assignments.get(ms), currentSearchRadius.get(ms)));
notifyListenersOfAssignmentUpdate(ms, currentTarget.get(ms));
}
......
......@@ -164,9 +164,9 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint) {
if (!arrivedAtAttractionPoint.contains(ms)) {
Event.scheduleWithDelay(getRandomUniformDistributionPauseTime(), this, ms, 0);
Event.scheduleWithDelay(getPauseTime(attractionPoint), this, ms, 0);
arrivedAtAttractionPoint.add(ms);
}
}
......
......@@ -75,14 +75,14 @@ public class WeightedTransitionStrategy extends AbstractAttractionBasedTransitio
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
public void reachedAttractionPoint(SimLocationActuator ms, AttractionPoint attractionPoint) {
// JZ: Added this to prevent multiple calls while pausing (otherwise most nodes will not wait more the minimum pause time)
if (!this.assignments.containsKey(ms)) {
return;
}
this.lastAssignments.put(ms, this.assignments.remove(ms));
Event.scheduleWithDelay(getRandomUniformDistributionPauseTime(), this, ms, EVENT_PAUSE_ENDED);
Event.scheduleWithDelay(getPauseTime(attractionPoint), this, ms, EVENT_PAUSE_ENDED);
}
}
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