Commit 9301602b authored by Simon Eismann's avatar Simon Eismann

wrapped cern abstract distribution in custom abstract distribution class

parent 7e15cbd6
......@@ -52,7 +52,7 @@ package de.tud.cs.simqpn.kernel;
import java.util.LinkedList;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import cern.jet.random.Empirical;
import cern.jet.random.EmpiricalWalker;
import cern.jet.random.Exponential;
......
......@@ -69,8 +69,6 @@ import org.dom4j.Element;
import cern.colt.list.AbstractDoubleList;
import cern.colt.list.DoubleArrayList;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Exponential;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNConfiguration;
......@@ -81,6 +79,8 @@ import de.tud.cs.simqpn.kernel.entities.queue.QueueingDiscipline;
import de.tud.cs.simqpn.kernel.entities.stats.QPlaceQueueStats;
import de.tud.cs.simqpn.kernel.executor.Executor;
import de.tud.cs.simqpn.kernel.loading.XMLWelch;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistributionWrapper;
import de.tud.cs.simqpn.kernel.loading.distributions.Deterministic;
/**
......@@ -192,12 +192,12 @@ public class QPlace extends Place {
String lambdaString = distribution.toString().split("\\(")[1]
.split("\\)")[0];
double lambda = Double.parseDouble(lambdaString);
this.randServTimeGen[c] = new Exponential(lambda,
RandomNumberGenerator.nextRandNumGen());
this.randServTimeGen[c] = new AbstractDistributionWrapper(
new Exponential(lambda, RandomNumberGenerator.nextRandNumGen()));
} else if (((QPlace) original).randServTimeGen[c].getClass()
.equals(Deterministic.class)) {
double value = ((QPlace) original).randServTimeGen[c]
.nextDouble();
.nextDouble(-1);
this.randServTimeGen[c] = new Deterministic(value);
} else {
// TODO implement copy of other distributions
......@@ -495,7 +495,7 @@ public class QPlace extends Place {
private void calculateServiceTimeIfFutureListIsEmpty(int color) {
if (futureList.get(color).isEmpty()) {
int concurrency = queueTokenPop[color];
double serviceTime = randServTimeGen[color].nextDouble();
double serviceTime = randServTimeGen[color].nextDouble(concurrency);
if (serviceTime < 0) {
serviceTime = 0;
}
......
......@@ -89,7 +89,7 @@ public class PRIOQueue extends Queue {
int n = 0;
while (n < count && numBusyServers < numServers) {
// Schedule service completion event
double servTime = queueingPlace.randServTimeGen[color].nextDouble();
double servTime = queueingPlace.randServTimeGen[color].nextDouble(-1);
if (servTime < 0)
servTime = 0;
Token tk = (tokensToBeAdded != null) ? tokensToBeAdded[n]
......@@ -134,7 +134,7 @@ public class PRIOQueue extends Queue {
if (!priorityQueue.isEmpty()) {
Token tk = priorityQueue.remove();
QPlace qPl = (QPlace) tk.place;
double servTime = qPl.randServTimeGen[tk.color].nextDouble();
double servTime = qPl.randServTimeGen[tk.color].nextDouble(-1);
if (servTime < 0) {
servTime = 0;
executor.scheduleEvent(servTime, this, tk);
......
......@@ -43,7 +43,6 @@ package de.tud.cs.simqpn.kernel.entities.queue;
import org.apache.log4j.Logger;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Empirical;
import cern.jet.random.EmpiricalWalker;
import cern.jet.random.Exponential;
......@@ -55,6 +54,8 @@ import de.tud.cs.simqpn.kernel.entities.QPlace;
import de.tud.cs.simqpn.kernel.entities.Token;
import de.tud.cs.simqpn.kernel.executor.Executor;
import de.tud.cs.simqpn.kernel.executor.QueueEvent;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistributionWrapper;
/**
* This class implements the Processor Sharing(PS) scheduling strategy.
......@@ -203,9 +204,9 @@ public class PSQueue extends Queue {
// PS Queues
if (expPS) {
expRandServTimeGen = new Exponential[1];
expRandServTimeGen[0] = new Exponential(0,
RandomNumberGenerator.nextRandNumGen());
expRandServTimeGen = new AbstractDistribution[1];
expRandServTimeGen[0] = new AbstractDistributionWrapper(
new Exponential(0, RandomNumberGenerator.nextRandNumGen()));
double[] pdf = new double[totNumColors];
for (int c = 0; c < totNumColors; c++)
pdf[c] = 1;
......@@ -256,7 +257,7 @@ public class PSQueue extends Queue {
((Exponential) expRandServTimeGen[0]).setState(totServRate);
randColorGen.setState2(pdf);
double servTime = expRandServTimeGen[0].nextDouble();
double servTime = expRandServTimeGen[0].nextDouble(-1);
if (servTime < 0)
servTime = 0;
int color = randColorGen.nextInt();
......
......@@ -113,7 +113,7 @@ public class RANDOMQueue extends Queue {
int n = 0;
while (n < count && numBusyServers < numServers) {
// Schedule service completion event
double servTime = qPl.randServTimeGen[color].nextDouble();
double servTime = qPl.randServTimeGen[color].nextDouble(-1);
if (servTime < 0)
servTime = 0;
Token tk = (tokensToBeAdded != null) ? tokensToBeAdded[n]
......@@ -147,7 +147,7 @@ public class RANDOMQueue extends Queue {
int index = randomGenerator.nextInt(waitingLine.size());
Token tk = (Token) waitingLine.remove(index);
QPlace qPl = (QPlace) tk.place;
double servTime = qPl.randServTimeGen[tk.color].nextDouble();
double servTime = qPl.randServTimeGen[tk.color].nextDouble(-1);
if (servTime < 0)
servTime = 0;
executor.scheduleEvent(servTime, this, tk);
......
......@@ -192,7 +192,7 @@ public class ThreadSchedulingQueue extends Queue {
tokenData.alreadyScheduled = true;
tokenData.requiredProcessingTime = queingPlace.randServTimeGen[color]
.nextDouble();
.nextDouble(-1);
if (tokenData.requiredProcessingTime < 0) {
tokenData.requiredProcessingTime = 0;
}
......
package de.tud.cs.simqpn.kernel.loading.distributions;
public interface AbstractDistribution {
public double nextDouble(int concurrency);
}
package de.tud.cs.simqpn.kernel.loading.distributions;
public class AbstractDistributionWrapper implements AbstractDistribution {
private cern.jet.random.AbstractDistribution innerDistribution;
public AbstractDistributionWrapper(cern.jet.random.AbstractDistribution innerDistribution) {
this.innerDistribution = innerDistribution;
}
@Override
public double nextDouble(int concurrency) {
return innerDistribution.nextDouble();
}
}
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Beta;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -53,7 +52,7 @@ public class BetaCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution() throws SimQPNException {
return new Beta(alpha, beta, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Beta(alpha, beta, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.BreitWigner;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -62,7 +61,8 @@ public class BreitWignerCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new BreitWigner(mean, gamma, cut, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(
new BreitWigner(mean, gamma, cut, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.BreitWignerMeanSquare;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -62,7 +61,8 @@ public class BreitWignerMeanSquareCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new BreitWignerMeanSquare(mean, gamma, cut, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(
new BreitWignerMeanSquare(mean, gamma, cut, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.ChiSquare;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -58,7 +57,7 @@ public class ChiSquareCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new ChiSquare(freedom, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new ChiSquare(freedom, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -43,7 +43,6 @@ package de.tud.cs.simqpn.kernel.loading.distributions;
import java.util.InputMismatchException;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -67,7 +66,8 @@ public class ContinuousEmpiricalCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution() throws SimQPNException {
return new ContinuousEmpirical(values, pdf, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(
new ContinuousEmpirical(values, pdf, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -40,8 +40,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
/**
* A deterministic distribution that always returns the double passed to the
* constructor.
......@@ -51,7 +49,7 @@ import cern.jet.random.AbstractDistribution;
* @author Philipp Meier
*
*/
public class Deterministic extends AbstractDistribution {
public class Deterministic implements AbstractDistribution {
private double value;
......@@ -60,13 +58,8 @@ public class Deterministic extends AbstractDistribution {
this.value = value;
}
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public double nextDouble() {
public double nextDouble(int concurrency) {
return value;
}
......
......@@ -41,7 +41,7 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.SimQPNException;
public class DeterministicCreator extends DistributionCreator {
......
......@@ -43,7 +43,6 @@ package de.tud.cs.simqpn.kernel.loading.distributions;
import java.util.InputMismatchException;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Empirical;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -68,7 +67,8 @@ public class DiscreteEmpiricalCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution() throws SimQPNException {
return new DiscreteEmpirical(values, pdf, Empirical.NO_INTERPOLATION, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(
new DiscreteEmpirical(values, pdf, Empirical.NO_INTERPOLATION, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -51,7 +51,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.dom4j.Element;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.SimQPNException;
public abstract class DistributionCreator {
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
import de.tud.cs.simqpn.kernel.util.LogUtil;
......@@ -64,8 +63,8 @@ public class EmpiricalCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new ScaledEmpirical( offset, scale, pdf, cern.jet.random.Empirical.LINEAR_INTERPOLATION,
RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new ScaledEmpirical(offset, scale, pdf,
cern.jet.random.Empirical.LINEAR_INTERPOLATION, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Exponential;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -58,7 +57,7 @@ public class ExponentialCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Exponential(lambda, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Exponential(lambda, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.ExponentialPower;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -59,7 +58,7 @@ public class ExponentialPowerCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new ExponentialPower(tau, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new ExponentialPower(tau, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Gamma;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -60,7 +59,7 @@ public class GammaCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Gamma(alpha, lambda, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Gamma(alpha, lambda, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Hyperbolic;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -61,7 +60,7 @@ public class HyperbolicCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Hyperbolic(alpha, beta, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Hyperbolic(alpha, beta, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Logarithmic;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -63,7 +62,7 @@ public class LogarithmicCreator extends DistributionCreator {
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Logarithmic(p, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Logarithmic(p, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Normal;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -60,7 +59,7 @@ public class NormalCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Normal(mean, stdDev, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Normal(mean, stdDev, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,11 +41,7 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
public class Periodical extends AbstractDistribution {
private static final long serialVersionUID = -6171122408442436886L;
public class Periodical implements AbstractDistribution {
private final double[] data;
private int currentPos = 0;
......@@ -62,7 +58,7 @@ public class Periodical extends AbstractDistribution {
}
@Override
public double nextDouble() {
public double nextDouble(int concurrency) {
double result = data[currentPos];
currentPos = (currentPos + 1) % data.length;
return result;
......
......@@ -41,7 +41,7 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.SimQPNException;
import de.tud.cs.simqpn.kernel.util.LogUtil;
......
......@@ -40,12 +40,8 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
public class Replay implements AbstractDistribution {
public class Replay extends AbstractDistribution {
private static final long serialVersionUID = 1L;
private double[] replayValues;
private int nextValue;
private String colorRefId;
......@@ -57,7 +53,7 @@ public class Replay extends AbstractDistribution {
}
@Override
public double nextDouble() {
public double nextDouble(int concurrency) {
if (nextValue == replayValues.length)
throw new IllegalStateException("There are only " + replayValues.length
+ " values in the replayfile for the colorRef " + colorRefId
......
......@@ -41,7 +41,7 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution;
import de.tud.cs.simqpn.kernel.SimQPNException;
public class ReplayCreator extends DistributionCreator {
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.StudentT;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -59,7 +58,7 @@ public class StudentTCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new StudentT(freedom, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new StudentT(freedom, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.Uniform;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -65,7 +64,7 @@ public class UniformCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new Uniform(min, max, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new Uniform(min, max, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -41,7 +41,6 @@
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
import cern.jet.random.AbstractDistribution;
import cern.jet.random.VonMises;
import de.tud.cs.simqpn.kernel.RandomNumberGenerator;
import de.tud.cs.simqpn.kernel.SimQPNException;
......@@ -59,7 +58,7 @@ public class VonMisesCreator extends DistributionCreator {
@Override
public AbstractDistribution getDistribution()
throws SimQPNException {
return new VonMises(freedom, RandomNumberGenerator.nextRandNumGen());
return new AbstractDistributionWrapper(new VonMises(freedom, RandomNumberGenerator.nextRandNumGen()));
}
@Override
......
......@@ -40,6 +40,6 @@
*
*/
/**
* This package contains factory methods and extensions to cern.jet.random.AbstractDistribution.
* This package contains factory methods and extensions to de.tud.cs.simqpn.kernel.loading.distributions.AbstractDistribution.
*/
package de.tud.cs.simqpn.kernel.loading.distributions;
......@@ -53,7 +53,7 @@ import org.apache.log4j.Logger;
import org.dom4j.Element;
import org.dom4j.XPath;