init
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
public class DeterministicDistribution extends Distribution{
|
||||
|
||||
private double value;
|
||||
|
||||
public DeterministicDistribution(double value) {
|
||||
super();
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.DETERMINISTIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/org/fog/utils/distribution/Distribution.java
Normal file
24
src/org/fog/utils/distribution/Distribution.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Distribution {
|
||||
|
||||
public static int NORMAL = 1;
|
||||
public static int DETERMINISTIC = 2;
|
||||
public static int UNIFORM = 3;
|
||||
|
||||
protected Random random;
|
||||
public abstract double getNextValue();
|
||||
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public void setRandom(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public abstract int getDistributionType();
|
||||
public abstract double getMeanInterTransmitTime();
|
||||
}
|
||||
47
src/org/fog/utils/distribution/NormalDistribution.java
Normal file
47
src/org/fog/utils/distribution/NormalDistribution.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class NormalDistribution extends Distribution{
|
||||
|
||||
private double mean;
|
||||
private double stdDev;
|
||||
|
||||
public NormalDistribution(double mean, double stdDev) {
|
||||
setMean(mean);
|
||||
setStdDev(stdDev);
|
||||
setRandom(new Random());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return random.nextGaussian()*stdDev + mean;
|
||||
}
|
||||
|
||||
public double getMean() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
public void setMean(double mean) {
|
||||
this.mean = mean;
|
||||
}
|
||||
|
||||
public double getStdDev() {
|
||||
return stdDev;
|
||||
}
|
||||
|
||||
public void setStdDev(double stdDev) {
|
||||
this.stdDev = stdDev;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
}
|
||||
45
src/org/fog/utils/distribution/UniformDistribution.java
Normal file
45
src/org/fog/utils/distribution/UniformDistribution.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
public class UniformDistribution extends Distribution{
|
||||
|
||||
private double min;
|
||||
private double max;
|
||||
|
||||
public UniformDistribution(double min, double max){
|
||||
super();
|
||||
setMin(min);
|
||||
setMax(max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return getRandom().nextDouble()*(getMax()-getMin())+getMin();
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public void setMin(double min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public void setMax(double max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.UNIFORM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return (min+max)/2;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user