Skip to content
Snippets Groups Projects
Commit 3305a732 authored by Nils Weidmann's avatar Nils Weidmann
Browse files

Manually insert new methods to solve the rest of the merge conflict

parent e5315a9b
No related branches found
No related tags found
1 merge request!75Bug #253 mobility hosts hover to origin after arriving at an event
Pipeline #
package movement; package movement;
import core.SimScenario;
import core.VhmListener; import core.VhmListener;
import core.Settings; import core.Settings;
import core.Coord; import core.Coord;
...@@ -8,6 +9,7 @@ import core.SimClock; ...@@ -8,6 +9,7 @@ import core.SimClock;
import input.VhmEvent; import input.VhmEvent;
import input.VhmEventNotifier; import input.VhmEventNotifier;
import movement.map.SimMap; import movement.map.SimMap;
import routing.util.EnergyModel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -61,6 +63,11 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh ...@@ -61,6 +63,11 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh
PANIC_MODE PANIC_MODE
} }
/**
* Update listener responsible for initiating host recharging.
*/
private static VhmRechargeInitiator rechargeInitiator = new VhmRechargeInitiator();
/** /**
* the current movement mode of the node * the current movement mode of the node
*/ */
...@@ -123,6 +130,11 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh ...@@ -123,6 +130,11 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh
*/ */
private double startTime; private double startTime;
/**
* Time at which the host's energy should be recharged next.
*/
private double nextScheduledRecharge = Double.POSITIVE_INFINITY;
/** /**
* Creates a new VoluntaryHelperMovement. * Creates a new VoluntaryHelperMovement.
* Only called once per nodegroup to create a prototype. * Only called once per nodegroup to create a prototype.
...@@ -167,6 +179,16 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh ...@@ -167,6 +179,16 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh
justChanged = false; justChanged = false;
} }
/**
* Set up method called once per group when initializing hosts.
*/
public static void setUp(SimScenario simScenario) {
// Make sure recharging is checked at every update time.
if (!simScenario.getUpdateListeners().contains(rechargeInitiator)) {
simScenario.addUpdateListener(rechargeInitiator);
}
}
/** /**
* Returns a new initial placement for a node * Returns a new initial placement for a node
* *
...@@ -532,6 +554,36 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh ...@@ -532,6 +554,36 @@ public class VoluntaryHelperMovement extends ExtendedMovementModel implements Vh
} }
} }
/**
* Checks whether the {@link DTNHost} directed by this movement model instance should be recharged and executes or
* schedules that recharge as needed.
*/
void possiblyRecharge() {
boolean batteryIsEmpty = this.comBus.getDouble(EnergyModel.ENERGY_VALUE_ID, 1) <= 0;
if (!batteryIsEmpty) {
// Do nothing if host still has battery.
return;
}
// If no recharge time is set yet, set a new one.
if (Double.isInfinite(this.nextScheduledRecharge)) {
double[] interval = this.properties.getTimeBeforeRecharge();
double diffToCurrentTime = interval[0] + rng.nextDouble() * (interval[1] - interval[0]);
this.nextScheduledRecharge = SimClock.getTime() + diffToCurrentTime;
}
// Check if we should recharge at current time. Then:
if (SimClock.getTime() >= this.nextScheduledRecharge) {
// Recharge battery.
this.comBus.updateProperty(
EnergyModel.ENERGY_VALUE_ID,
EnergyModel.chooseRandomEnergyLevel(this.properties.getInitEnergy(), rng));
// And reset next scheduled recharge.
this.nextScheduledRecharge = Double.POSITIVE_INFINITY;
}
}
/** /**
* Return the properties object of the movement model * Return the properties object of the movement model
* @return the properties object * @return the properties object
......
  • Contributor

    SonarQube analysis reported 2 issues

    • 🔽 2 minor
    1. 🔽 Make this line start at column 9. 📘
    2. 🔽 Make this line start at column 13. 📘
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment