PureEdgeSim -locationmanager package -MobilityModel file

MobilityModel

The main class of the mobility manager module, which generates mobility paths for different edge devices.

Current device location

 protected Location currentLocation;

Is the device moving?

 protected boolean isMobile = false;

Minimum pause duration

 protected double minPauseDuration;

Maximum pause duration

 protected double maxPauseDuration;

Maximum movement duration

 protected double maxMobilityDuration;

Minimum movement duration

 protected double minMobilityDuration;

speed

 protected double speed;

Simulation Manager

 protected SimulationManager simulationManager;

Nearest edge data center

 protected ComputingNode closestEdgeDataCenter = ComputingNode.NULL;

The position of each time interval

 Map<Integer, Location> path = new LinkedHashMap<>(
(int) (SimulationParameters.simulationDuration / SimulationParameters.updateInterval));

The nearest edge data center for each interval

 Map<Integer, ComputingNode> datacentersMap = new LinkedHashMap<>(
(int) (SimulationParameters.simulationDuration / SimulationParameters.updateInterval));

Initialize the null movement model to prevent null pointers

 /**
* An attribute that implements the Null Object Design Pattern to avoid
* NullPointerException when using the NULL object instead of attributing null
* to MobilityModel variables.
*/
public static final MobilityModel NULL = new MobilityModelNull();

initialize object

 protected MobilityModel(SimulationManager simulationManager, Location location) {<!-- -->
currentLocation = location;
setSimulationManager(simulationManager);
}
protected MobilityModel() {<!-- -->
}

Returns the XY position at the next moment

 protected abstract Location getNextLocation(Location location);

Update location

 public Location updateLocation(double time) {<!-- -->
if (time <= SimulationParameters.simulationDuration)
currentLocation = path.get((int) time * 1000);
return currentLocation;
}

get current location

 public Location getCurrentLocation() {<!-- -->
return currentLocation;
}

Get whether it is a mobile model

 public boolean isMobile() {<!-- -->
return isMobile;
}

Set whether it is a mobile model

 public MobilityModel setMobile(boolean mobile) {<!-- -->
isMobile = mobile;
return this;
}

Get the smallest consecutive pause period

 public double getMinPauseDuration() {<!-- -->
return minPauseDuration;
}

Set minimum continuous pause period

 public MobilityModel setMinPauseDuration(double minPauseDuration) {<!-- -->
this.minPauseDuration = minPauseDuration;
return this;
}

Get the maximum pause period

 public double getMaxPauseDuration() {<!-- -->
return maxPauseDuration;
}

Set maximum pause duration

 public MobilityModel setMaxPauseDuration(double maxPauseDuration) {<!-- -->
this.maxPauseDuration = maxPauseDuration;
return this;
}

Get the minimum movement duration

 public double getMinMobilityDuration() {<!-- -->
return minMobilityDuration;
}

Set minimum movement duration

 public MobilityModel setMinMobilityDuration(double minMobilityDuration) {<!-- -->
this.minMobilityDuration = minMobilityDuration;
return this;
}

Get maximum movement duration

 public double getMaxMobilityDuration() {<!-- -->
return maxMobilityDuration;
}

Set maximum movement duration

 public MobilityModel setMaxMobilityDuration(double maxMobilityDuration) {<!-- -->
this.maxMobilityDuration = maxMobilityDuration;
return this;
}

get speed

 public double getSpeed() {<!-- -->
return speed;
}

Set speed

 public MobilityModel setSpeed(double speed) {<!-- -->
this.speed = speed;
return this;
}

Calculate the distance between nodes

 public double distanceTo(ComputingNode device2) {<!-- -->
return Math.abs(Math.sqrt(Math
.pow((getCurrentLocation().getXPos() - device2.getMobilityModel().getCurrentLocation().getXPos()), 2)
+ Math.pow((getCurrentLocation().getYPos() - device2.getMobilityModel().getCurrentLocation().getYPos()),
\t\t\t\t\t\t2)));
}

get emulation manager

 public SimulationManager getSimulationManager() {<!-- -->
return simulationManager;
}

Set up the simulation manager

 public void setSimulationManager(SimulationManager simulationManager) {<!-- -->
this.simulationManager = simulationManager;
}

Generate path

 public void generatePath() {<!-- -->

        closestEdgeDataCenter = getDataCenter();

        if (!isMobile())
            return;
        Location newLocation = getCurrentLocation();//Get the current location

        // Working around the double imprecision
        int interval = (int) (SimulationParameters.updateInterval * 1000);//Calculate update interval
        int simulationTime = (int) (SimulationParameters.simulationDuration * 1000);//Calculate simulation time

        for (int i = 0; i <= simulationTime; i = i + interval) {<!-- -->
            path.put(i, newLocation);//Insert a new location on the path every interval
            newLocation = getNextLocation(newLocation);
            datacentersMap.put(i, getDataCenter());
        }
}

Get the closest computing node (internal function call)

 protected ComputingNode getDataCenter() {<!-- -->
        List<ComputingNode> list = getSimulationManager().getDataCentersManager().getComputingNodesGenerator()
                .getEdgeOnlyList();//Get the list of edge data centers

        double range = SimulationParameters.edgeDataCentersRange;//Edge data center connection range
        ComputingNode closestDC = ComputingNode.NULL;

        for (int i = 0; i < list.size(); i + + ) {<!-- -->
            if (list.get(i).isPeripheral() & amp; & amp; distanceTo(list.get(i)) <= range) {<!-- -->//Within the transmission range of the edge data center
                range = distanceTo(list.get(i));
                closestDC = list.get(i);
                //Loop to find the edge data center with the minimum distance
            }
        }
        return closestDC;
    }

Get the nearest computing node (call this yourself)

 public ComputingNode getClosestEdgeDataCenter() {<!-- -->
        return (isMobile //Whether it is a mobile device
                 & amp; & amp; getSimulationManager().getSimulation().clock() <= SimulationParameters.simulationDuration)//Whether it is within the simulation time
                ? datacentersMap.get((int) (getSimulationManager().getSimulation().clock() * 1000))//Get the nearest edge data center at the current location
                : closestEdgeDataCenter;//The location of the closest data center at the last time
    }