/** * Checks if at the current time, {@link #getK() K} events have happened, * considering the {@link #eventsArrivalProbability() probability of these K events} * to happen in a time interval. * * @return true if the K events have happened at current time, false otherwise */ public boolean eventsHappened(){ return rand.sample() <= eventsArrivalProbability(); }
/** * Creates a fault injection mechanism for the Hosts of a given {@link Datacenter}. * The Hosts failures are randomly injected according to a {@link UniformDistr} * pseudo random number generator, which indicates the mean of failures to be generated per <b>hour</b>, * (which is also called <b>event rate</b> or <b>rate parameter</b>). * * @param datacenter the Datacenter to which failures will be randomly injected for its Hosts * @see #HostFaultInjection(Datacenter, ContinuousDistribution) */ public HostFaultInjection(final Datacenter datacenter) { this(datacenter, new UniformDistr()); }
/** * Gets the time delay in seconds, from the current simulation time, * that the next failure will be injected. * Since the values returned by the {@link #faultArrivalHoursGenerator} * are considered to be in <b>hours</b>, such values are converted to seconds. * * @return the next failure injection delay in seconds */ private double getTimeDelayForNextFault() { return faultArrivalHoursGenerator.sample() * 3600; }
/** * Creates a new Poisson random number generator to check * the probability of 1 event ({@link #getK() k}) to happen at each time * interval. * * @param lambda the average number of events that happen at each 1 time unit. * If one considers the unit as minute, this value means the average number of arrivals * at each minute. * @param seed the seed to initialize the uniform random number generator * @see #setK(int) * @see #setLambda(double) */ public PoissonDistr(final double lambda, final long seed){ this.rand = new UniformDistr(seed); this.k = 1; this.setLambda(lambda); }
/** * Creates an array with the configuration of PEs for each Cloudlet to be * created in each experiment run. Every experiment will use the same * Cloudlets configurations. * * @return the created cloudlet PEs array */ private int[] createCloudletPesArray() { int[] pesArray = new int[CLOUDLETS_TO_CREATE]; int totalNumberOfPes = 0; final ContinuousDistribution random = new NormalDistr(getBaseSeed(), 2, 0.6); for (int i = 0; i < CLOUDLETS_TO_CREATE; i++) { pesArray[i] = (int) random.sample() + 1; totalNumberOfPes += pesArray[i]; } return pesArray; }
@Override public double sample() { return super.sample() - shift; }
@Override public long getSeed() { return rand.getSeed(); }
/** * Creates a new continuous random number generator. * * @param numGen the actual random number generator that will be the base * to generate random numbers following a continuous distribution. * @param seed the seed to initialize the random number generator. If * it is passed -1, the current time will be used */ protected ContinuousDistributionAbstract(RealDistribution numGen, long seed) { this.numGen = numGen; if(seed == -1) seed = System.currentTimeMillis(); setSeed(seed); }
CloudletSchedulerExperiment(int index, ExperimentRunner runner) { super(index, runner); this.cloudletPesPrng = new UniformDistr(0, 1); }
/** * Gets a Pseudo Random Number used to give a * recovery time (in seconds) for each VM that was failed. * @return */ public double getRandomRecoveryTimeForVmInSecs() { return random.sample()*MAX_VM_RECOVERY_TIME_SECS + 1; }
@Override public double sample() { return super.sample() - shift; }
@Override public double sample() { final double variate = super.sample(); double num = 1; double nextNum = 1 + 1 / Math.pow(2, shape); double j = 3; while (variate > nextNum / den) { num = nextNum; nextNum += 1 / Math.pow(j, shape); j++; } return num / den; }
public PowerVmSelectionPolicyRandomSelection(){ super(); rand = new UniformDistr(); }
/** * Get the seek time for a file with the defined size. Given a file size in MB, this method * returns a seek time for the file in seconds. * * @param fileSize the size of a file in MB * @return the seek time in seconds */ private double getSeekTime(int fileSize) { double result = 0; if (gen != null) { result += gen.sample(); } if (fileSize > 0 && capacity != 0) { result += (fileSize / capacity); } return result; }
/** * Instantiates the simulation experiment. * * @param index a number the identifies the current experiment being run * @param runner the runner that will be in charge to setup and run the * experiment */ DatacenterBrokerHeuristicExperiment(int index, DatacenterBrokerHeuristicRunner runner) { super(index, runner); this.randomGen = new UniformDistr(0, 1); createSimulatedAnnealingHeuristic(); }
@Override public int getRandomValue(final int maxValue){ final double uniform = getRandom().sample(); /*always get an index between [0 and size[, regardless if the random number generator returns values between [0 and 1[ or >= 1*/ return (int)(uniform >= 1 ? uniform % maxValue : uniform * maxValue); }
private void createSimulatedAnnealingHeuristic() { heuristic = new CloudletToVmMappingSimulatedAnnealing(SA_INITIAL_TEMPERATURE, new UniformDistr(0, 1)); heuristic.setColdTemperature(SA_COLD_TEMPERATURE); heuristic.setCoolingRate(SA_COOLING_RATE); heuristic.setNeighborhoodSearchesByIteration(SA_NUMBER_OF_NEIGHBORHOOD_SEARCHES); }
/** * Randomly generates a number of PEs which will fail for the datacenter. * The minimum number of PEs to fail is 1. * * @param host the Host to generate a number of PEs to fail * @return the generated number of failed PEs for the datacenter, * between [1 and Number of PEs]. */ private int randomNumberOfFailedPes(final Host host) { /*the random generator return values from [0 to 1] and multiplying by the number of PEs we get a number between 0 and number of PEs*/ return (int) (random.sample() * host.getNumberOfWorkingPes()) + 1; }