Commit 84fec2db authored by Anton Beloglazov's avatar Anton Beloglazov

UtilizationModelStochastic has been updated to optionally set a random seed

parent 163c51e4
...@@ -456,7 +456,7 @@ public class Host { ...@@ -456,7 +456,7 @@ public class Host {
* *
* @return the VM scheduler * @return the VM scheduler
*/ */
protected VmScheduler getVmScheduler() { public VmScheduler getVmScheduler() {
return vmScheduler; return vmScheduler;
} }
......
...@@ -14,7 +14,9 @@ import java.io.ObjectInputStream; ...@@ -14,7 +14,9 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random;
// TODO: Auto-generated Javadoc
/** /**
* The UtilizationModelStochastic class implements a model, according to which * The UtilizationModelStochastic class implements a model, according to which
* a Cloudlet generates random CPU utilization every time frame. * a Cloudlet generates random CPU utilization every time frame.
...@@ -24,6 +26,9 @@ import java.util.Map; ...@@ -24,6 +26,9 @@ import java.util.Map;
*/ */
public class UtilizationModelStochastic implements UtilizationModel { public class UtilizationModelStochastic implements UtilizationModel {
/** The random generator. */
private Random randomGenerator;
/** The history. */ /** The history. */
private Map<Double, Double> history; private Map<Double, Double> history;
...@@ -32,6 +37,12 @@ public class UtilizationModelStochastic implements UtilizationModel { ...@@ -32,6 +37,12 @@ public class UtilizationModelStochastic implements UtilizationModel {
*/ */
public UtilizationModelStochastic() { public UtilizationModelStochastic() {
setHistory(new HashMap<Double, Double>()); setHistory(new HashMap<Double, Double>());
setRandomGenerator(new Random());
}
public UtilizationModelStochastic(long seed) {
setHistory(new HashMap<Double, Double>());
setRandomGenerator(new Random(seed));
} }
/* (non-Javadoc) /* (non-Javadoc)
...@@ -43,7 +54,7 @@ public class UtilizationModelStochastic implements UtilizationModel { ...@@ -43,7 +54,7 @@ public class UtilizationModelStochastic implements UtilizationModel {
return getHistory().get(time); return getHistory().get(time);
} }
double utilization = Math.random(); double utilization = getRandomGenerator().nextDouble();
getHistory().put(time, utilization); getHistory().put(time, utilization);
return utilization; return utilization;
} }
...@@ -95,4 +106,22 @@ public class UtilizationModelStochastic implements UtilizationModel { ...@@ -95,4 +106,22 @@ public class UtilizationModelStochastic implements UtilizationModel {
ois.close(); ois.close();
} }
/**
* Sets the random generator.
*
* @param randomGenerator the new random generator
*/
public void setRandomGenerator(Random randomGenerator) {
this.randomGenerator = randomGenerator;
}
/**
* Gets the random generator.
*
* @return the random generator
*/
public Random getRandomGenerator() {
return randomGenerator;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment