edgecloudsim/src/edu/boun/edgecloudsim/task_generator/IdleActiveLoadGenerator.java

105 lines
4.1 KiB
Java
Raw Normal View History

/*
* Title: EdgeCloudSim - Idle/Active Load Generator implementation
*
* Description:
* IdleActiveLoadGenerator implements basic load generator model where the
* mobile devices generate task in active period and waits in idle period.
* Task interarrival time (load generation period), Idle and active periods
* are defined in the configuration file.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.task_generator;
import java.util.ArrayList;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.utils.TaskProperty;
import edu.boun.edgecloudsim.utils.SimLogger;
import edu.boun.edgecloudsim.utils.SimUtils;
public class IdleActiveLoadGenerator extends LoadGeneratorModel{
int taskTypeOfDevices[];
public IdleActiveLoadGenerator(int _numberOfMobileDevices, double _simulationTime, String _simScenario) {
super(_numberOfMobileDevices, _simulationTime, _simScenario);
}
@Override
public void initializeModel() {
taskList = new ArrayList<TaskProperty>();
//exponential number generator for file input size, file output size and task length
ExponentialDistribution[][] expRngList = new ExponentialDistribution[SimSettings.getInstance().getTaskLookUpTable().length][3];
//create random number generator for each place
for(int i=0; i<SimSettings.getInstance().getTaskLookUpTable().length; i++) {
if(SimSettings.getInstance().getTaskLookUpTable()[i][0] ==0)
continue;
expRngList[i][0] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][5]);
expRngList[i][1] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][6]);
expRngList[i][2] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][7]);
}
//Each mobile device utilizes an app type (task type)
taskTypeOfDevices = new int[numberOfMobileDevices];
for(int i=0; i<numberOfMobileDevices; i++) {
int randomTaskType = -1;
double taskTypeSelector = SimUtils.getRandomDoubleNumber(0,100);
double taskTypePercentage = 0;
for (int j=0; j<SimSettings.getInstance().getTaskLookUpTable().length; j++) {
taskTypePercentage += SimSettings.getInstance().getTaskLookUpTable()[j][0];
if(taskTypeSelector <= taskTypePercentage){
randomTaskType = j;
break;
}
}
if(randomTaskType == -1){
some minor backward compatible, major backward incompatible changes and code formatting (beautification) Minor Modifications: * Indentation issues are fixed * Typo errors in source code and comments are fixed * Misspelled parameters in plotTaskFailureReason.m are corrected * sim_results folder is added to .gitignore file Backward compatible changes * The exit code of the application when there is an error is changed from 0 to 1 * Default constructors are added for Location.java, LoadGeneratorModel.java, MobilityModel.java, EdgeOrchestrator.java (this change request coming from a developer) * public TaskProperty(int mobileDeviceId, double startTime, ExponentialDistribution[] expRngList) is added to TaskProperty.java (this change request coming from a developer to create a task without task type) * double getCreationTime() function is added to Task.java * void reconfigureMips(double mips) function is added to EdgeVM (for future usage) * gsm_propagation_delay variable is added to config file. SimSettings class is also modified accordingly. You can use it if you have cellular network access in your scenario. * wlan_range, northern_bound, southern_bound, eastern_bound, western_bound variables are added to config file; and relevant functions are added to SimSettings class. (this change request coming from a developer) Backward incompatible changes! * location_check_interval variable name is changed to location_check_interval in config.properties file. Please update your config files accordingly (remove 'vm_' part) * Major modifications are applied in SimLogger class to decrease time complexity. Now the basic results are kept in the memory and saved to the files at the end of the simulation. As a result of this change, the signature of the SimLogger.addLog () function had to be changed. You must add the mobile device id as the first argument. Please update your MobileDeviceManager class accordingly (add task.getCloudletId () as the first argument).
2020-10-30 09:06:09 +01:00
SimLogger.printLine("Impossible is occurred! no random task type!");
continue;
}
taskTypeOfDevices[i] = randomTaskType;
double poissonMean = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][2];
double activePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][3];
double idlePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][4];
double activePeriodStartTime = SimUtils.getRandomDoubleNumber(
SimSettings.CLIENT_ACTIVITY_START_TIME,
SimSettings.CLIENT_ACTIVITY_START_TIME + activePeriod); //active period starts shortly after the simulation started (e.g. 10 seconds)
double virtualTime = activePeriodStartTime;
ExponentialDistribution rng = new ExponentialDistribution(poissonMean);
while(virtualTime < simulationTime) {
double interval = rng.sample();
if(interval <= 0){
SimLogger.printLine("Impossible is occurred! interval is " + interval + " for device " + i + " time " + virtualTime);
continue;
}
//SimLogger.printLine(virtualTime + " -> " + interval + " for device " + i + " time ");
virtualTime += interval;
if(virtualTime > activePeriodStartTime + activePeriod){
activePeriodStartTime = activePeriodStartTime + activePeriod + idlePeriod;
virtualTime = activePeriodStartTime;
continue;
}
taskList.add(new TaskProperty(i,randomTaskType, virtualTime, expRngList));
}
}
}
@Override
public int getTaskTypeOfDevice(int deviceId) {
// TODO Auto-generated method stub
return taskTypeOfDevices[deviceId];
}
}