This commit is contained in:
2021-04-06 00:45:28 +02:00
commit 17fabc368e
836 changed files with 3042963 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
/**
* Interface to be implemented by a random number generator.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public interface ContinuousDistribution {
/**
* Sample the random number generator.
*
* @return The sample
*/
double sample();
}

View File

@@ -0,0 +1,64 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* An exponential number generator.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class ExponentialDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The mean. */
private final double mean;
/**
* Creates a new exponential number generator.
*
* @param seed the seed to be used.
* @param mean the mean for the distribution.
*/
public ExponentialDistr(long seed, double mean) {
if (mean <= 0.0) {
throw new IllegalArgumentException("Mean must be greater than 0.0");
}
numGen = new Random(seed);
this.mean = mean;
}
/**
* Creates a new exponential number generator.
*
* @param mean the mean for the distribution.
*/
public ExponentialDistr(double mean) {
if (mean <= 0.0) {
throw new IllegalArgumentException("Mean must be greated than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.mean = mean;
}
/**
* Generate a new random number.
*
* @return the next random number in the sequence
*/
@Override
public double sample() {
return -mean * Math.log(numGen.nextDouble());
}
}

View File

@@ -0,0 +1,78 @@
/*
* Title: CloudSim Toolkit
* Descripimport java.util.Random;
mulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class GammaDistr.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class GammaDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The alpha. */
private final int alpha;
/** The beta. */
private final double beta;
/**
* Instantiates a new gamma distr.
*
* @param seed the seed
* @param alpha the alpha
* @param beta the beta
*/
public GammaDistr(Random seed, int alpha, double beta) {
if (alpha <= 0 || beta <= 0.0) {
throw new IllegalArgumentException("Alpha and beta must be greater than 0.0");
}
numGen = seed;
this.alpha = alpha;
this.beta = beta;
}
/**
* Instantiates a new gamma distr.
*
* @param alpha the alpha
* @param beta the beta
*/
public GammaDistr(int alpha, double beta) {
if (alpha <= 0 || beta <= 0.0) {
throw new IllegalArgumentException("Alpha and beta must be greater than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.alpha = alpha;
this.beta = beta;
}
/*
* (non-Javadoc)
* @see cloudsim.distributions.ContinuousDistribution#sample()
*/
@Override
public double sample() {
double sum = 0.0;
for (int i = 0; i < alpha; i++) {
sum += Math.log(numGen.nextDouble());
}
return -beta * sum;
}
}

View File

@@ -0,0 +1,77 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class LognormalDistr.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class LognormalDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The mean. */
private final double mean;
/** The dev. */
private final double dev;
/**
* Instantiates a new lognormal distr.
*
* @param seed the seed
* @param mean the mean
* @param dev the dev
*/
public LognormalDistr(Random seed, double mean, double dev) {
if (mean <= 0.0 || dev <= 0.0) {
throw new IllegalArgumentException("Mean and deviation must be greater than 0.0");
}
numGen = seed;
this.mean = mean;
this.dev = dev;
}
/**
* Instantiates a new lognormal distr.
*
* @param mean the mean
* @param dev the dev
*/
public LognormalDistr(double mean, double dev) {
if (mean <= 0.0 || dev <= 0.0) {
throw new IllegalArgumentException("Mean and deviation must be greater than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.mean = mean;
this.dev = dev;
}
/*
* (non-Javadoc)
* @see cloudsim.distributions.ContinuousDistribution#sample()
*/
@Override
public double sample() {
// generate a normal variate from a uniform variate
double n = Math.sqrt(-2 * Math.log(numGen.nextDouble()))
* Math.sin(2 * Math.PI * numGen.nextDouble());
// use it to generate the lognormal variate
return Math.pow(Math.E, mean + dev * n);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class LomaxDistribution.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class LomaxDistribution extends ParetoDistr implements ContinuousDistribution {
/** The shift. */
private final double shift;
/**
* Instantiates a new lomax distribution.
*
* @param shape the shape
* @param location the location
* @param shift the shift
*/
public LomaxDistribution(double shape, double location, double shift) {
super(shape, location);
if (shift > location) {
throw new IllegalArgumentException("Shift must be smaller or equal than location");
}
this.shift = shift;
}
/**
* Instantiates a new lomax distribution.
*
* @param seed the seed
* @param shape the shape
* @param location the location
* @param shift the shift
*/
public LomaxDistribution(Random seed, double shape, double location, double shift) {
super(seed, shape, location);
if (shift > location) {
throw new IllegalArgumentException("Shift must be smaller or equal than location");
}
this.shift = shift;
}
/*
* (non-Javadoc)
* @see cloudsim.distributions.ParetoDistr#sample()
*/
@Override
public double sample() {
return super.sample() - shift;
}
}

View File

@@ -0,0 +1,73 @@
/*
* Title: CloudSim Toolkit
* Descripimport java.util.Random;
mulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class ParetoDistr.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class ParetoDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The shape. */
private final double shape;
/** The location. */
private final double location;
/**
* Instantiates a new pareto distr.
*
* @param seed the seed
* @param shape the shape
* @param location the location
*/
public ParetoDistr(Random seed, double shape, double location) {
if (shape <= 0.0 || location <= 0.0) {
throw new IllegalArgumentException("Mean and deviation must be greater than 0.0");
}
numGen = seed;
this.shape = shape;
this.location = location;
}
/**
* Instantiates a new pareto distr.
*
* @param shape the shape
* @param location the location
*/
public ParetoDistr(double shape, double location) {
if (shape <= 0.0 || location <= 0.0) {
throw new IllegalArgumentException("Mean and deviation must be greater than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.shape = shape;
this.location = location;
}
/*
* (non-Javadoc)
* @see cloudsim.distributions.ContinuousDistribution#sample()
*/
@Override
public double sample() {
return location / Math.pow(numGen.nextDouble(), 1 / shape);
}
}

View File

@@ -0,0 +1,95 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* A random number generator based on the Uniform distribution.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class UniformDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The min. */
private final double mag, min;
/**
* Creates new uniform distribution.
*
* @param min minimum value
* @param max maximum value
*/
public UniformDistr(double min, double max) {
if (min >= max) {
throw new IllegalArgumentException("Maximum must be greater than the minimum.");
}
numGen = new Random();
mag = max - min;
this.min = min;
}
/**
* Creates new uniform distribution.
*
* @param min minimum value
* @param max maximum value
* @param seed simulation seed to be used
*/
public UniformDistr(double min, double max, long seed) {
if (min >= max) {
throw new IllegalArgumentException("Maximum must be greater than the minimum.");
}
numGen = new Random(seed);
mag = max - min;
this.min = min;
}
/**
* Generate a new random number.
*
* @return the next random number in the sequence
*/
@Override
public double sample() {
return (numGen.nextDouble() * (mag)) + min;
}
/**
* Generates a new random number based on the number generator and values provided as
* parameters.
*
* @param rd the random number generator
* @param min the minimum value
* @param max the maximum value
* @return the next random number in the sequence
*/
public static double sample(Random rd, double min, double max) {
if (min >= max) {
throw new IllegalArgumentException("Maximum must be greater than the minimum.");
}
return (rd.nextDouble() * (max - min)) + min;
}
/**
* Set the random number generator's seed.
*
* @param seed the new seed for the generator
*/
public void setSeed(long seed) {
numGen.setSeed(seed);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Title: CloudSim Toolkit
* Descripimport java.util.Random;
mulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class WeibullDistr.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class WeibullDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The alpha. */
private final double alpha;
/** The beta. */
private final double beta;
/**
* Instantiates a new weibull distr.
*
* @param seed the seed
* @param alpha the alpha
* @param beta the beta
*/
public WeibullDistr(Random seed, double alpha, double beta) {
if (alpha <= 0.0 || beta <= 0.0) {
throw new IllegalArgumentException("Alpha and beta must be greater than 0.0");
}
numGen = seed;
this.alpha = alpha;
this.beta = beta;
}
/**
* Instantiates a new weibull distr.
*
* @param alpha the alpha
* @param beta the beta
*/
public WeibullDistr(double alpha, double beta) {
if (alpha <= 0.0 || beta <= 0.0) {
throw new IllegalArgumentException("Alpha and beta must be greater than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.alpha = alpha;
this.beta = beta;
}
/*
* (non-Javadoc)
* @see cloudsim.distributions.ContinuousDistribution#sample()
*/
@Override
public double sample() {
return beta * Math.pow(-Math.log(numGen.nextDouble()), 1 / alpha);
}
}

View File

@@ -0,0 +1,97 @@
/*
* Title: CloudSim Toolkit
* Descripimport java.util.Random;
mulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.distributions;
import java.util.Random;
/**
* The Class ZipfDistr.
*
* @author Marcos Dias de Assuncao
* @since CloudSim Toolkit 1.0
*/
public class ZipfDistr implements ContinuousDistribution {
/** The num gen. */
private final Random numGen;
/** The shape. */
private final double shape;
/** The den. */
private double den;
/**
* Instantiates a new zipf distr.
*
* @param seed the seed
* @param shape the shape
* @param population the population
*/
public ZipfDistr(long seed, double shape, int population) {
if (shape <= 0.0 || population < 1) {
throw new IllegalArgumentException("Mean must be greater than 0.0 and population greater than 0");
}
numGen = new Random(seed);
this.shape = shape;
computeDen(shape, population);
}
/**
* Instantiates a new zipf distr.
*
* @param shape the shape
* @param population the population
*/
public ZipfDistr(double shape, int population) {
if (shape <= 0.0) {
throw new IllegalArgumentException("Mean must be greated than 0.0 and population greater than 0");
}
numGen = new Random(System.currentTimeMillis());
this.shape = shape;
computeDen(shape, population);
}
/**
* Generate a new random number.
*
* @return the next random number in the sequence
*/
@Override
public double sample() {
double variate = numGen.nextDouble();
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;
}
/**
* Compute den.
*
* @param shape the shape
* @param population the population
*/
private void computeDen(double shape, int population) {
den = 0.0;
for (int j = 1; j <= population; j++) {
den += 1 / Math.pow(j, shape);
}
}
}