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

Added a fixed 30 Seconds pause time between roaming states

parent cfa7aab1
......@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/**
......@@ -40,12 +41,15 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTransitionStrategy implements EventHandler {
public static enum roamingTransitionState {
PAUSE,
ROAMING,
TRANSITION
}
protected Map<SimLocationActuator, roamingTransitionState> roamingStates = new LinkedHashMap<>();
protected final static int EVENT_ROAMING_PAUSE_ENDED = 2;
@Override
public void addComponent(SimLocationActuator comp) {
this.roamingStates.put(comp, roamingTransitionState.TRANSITION);
......@@ -56,21 +60,24 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public void reachedAttractionPoint(SimLocationActuator comp) {
// start roaming
if(roamingStates.get(comp) == roamingTransitionState.PAUSE) {
return;
}
// 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(getPauseTime(), this, comp, EVENT_PAUSE_ENDED);
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
Event.scheduleWithDelay(getPauseTime(), this, comp, EVENT_PAUSE_ENDED);
}
// roam around the attraction point
roamAroundAttractionPoint(comp);
this.roamingStates.put(comp, roamingTransitionState.PAUSE);
// schedule roaming
Event.scheduleWithDelay(Time.SECOND * 30, this, comp, EVENT_ROAMING_PAUSE_ENDED);
}
private void roamAroundAttractionPoint(SimLocationActuator comp) {
if(roamingStates.get(comp) == roamingTransitionState.ROAMING) {
if(roamingStates.get(comp) != roamingTransitionState.TRANSITION) {
AttractionPoint currentAttractionPoint = this.assignments.get(comp);
if(currentAttractionPoint == null) {
......@@ -79,6 +86,7 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
if(currentAttractionPoint.getRadius() > 0)
{
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
......@@ -86,10 +94,14 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public void eventOccurred(Object content, int type) {
assert type == EVENT_PAUSE_ENDED;
SimLocationActuator comp = (SimLocationActuator) content;
this.addComponent(comp);
if(type == EVENT_PAUSE_ENDED) {
SimLocationActuator comp = (SimLocationActuator) content;
this.addComponent(comp);
}
else if(type == EVENT_ROAMING_PAUSE_ENDED) {
SimLocationActuator comp = (SimLocationActuator) content;
this.roamAroundAttractionPoint(comp);
}
}
......@@ -108,6 +120,6 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
}
AttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size()));
return assignment;
}
}
}
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