Search in sources :

Example 1 with UniformDistribution

use of de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution in project scylla by bptlab.

the class SimulationUtils method getDistribution.

public static NumericalDist<?> getDistribution(Distribution dist, SimulationModel model, String name, Integer nodeId, boolean showInReport, boolean showInTrace) throws InstantiationException {
    if (dist instanceof BinomialDistribution) {
        BinomialDistribution binDist = (BinomialDistribution) dist;
        double probability = binDist.getProbability();
        int amount = binDist.getAmount();
        return new DiscreteDistBinomial(model, name, probability, amount, showInReport, showInTrace);
    } else if (dist instanceof ConstantDistribution) {
        ConstantDistribution conDist = (ConstantDistribution) dist;
        double constantValue = conDist.getConstantValue();
        return new DiscreteDistConstant<Number>(model, name, constantValue, showInReport, showInTrace);
    } else if (dist instanceof EmpiricalDistribution) {
        EmpiricalDistribution empDist = (EmpiricalDistribution) dist;
        Map<Double, Double> entries = empDist.getEntries();
        DiscreteDistEmpirical<Double> cde = new DiscreteDistEmpirical<Double>(model, name, showInReport, showInTrace);
        for (Double value : entries.keySet()) {
            Double frequency = entries.get(value);
            cde.addEntry(value, frequency);
        }
        return cde;
    } else if (dist instanceof EmpiricalStringDistribution) {
        EmpiricalStringDistribution empDist = (EmpiricalStringDistribution) dist;
        Map<Double, Double> entries = empDist.getEntries();
        DiscreteDistEmpirical<Double> cde = new DiscreteDistEmpirical<Double>(model, name, showInReport, showInTrace);
        for (Double value : entries.keySet()) {
            Double frequency = entries.get(value);
            cde.addEntry(value, frequency);
        }
        return cde;
    } else if (dist instanceof ErlangDistribution) {
        ErlangDistribution erlDist = (ErlangDistribution) dist;
        double mean = erlDist.getMean();
        long order = erlDist.getOrder();
        return new ContDistErlang(model, name, order, mean, showInReport, showInTrace);
    } else if (dist instanceof ExponentialDistribution) {
        ExponentialDistribution expDist = (ExponentialDistribution) dist;
        double mean = expDist.getMean();
        return new ContDistExponential(model, name, mean, showInReport, showInTrace);
    } else if (dist instanceof TriangularDistribution) {
        TriangularDistribution triDist = (TriangularDistribution) dist;
        double lower = triDist.getLower();
        double upper = triDist.getUpper();
        double peak = triDist.getPeak();
        return new ContDistTriangular(model, name, lower, upper, peak, showInReport, showInTrace);
    } else if (dist instanceof NormalDistribution) {
        NormalDistribution norDist = (NormalDistribution) dist;
        double mean = norDist.getMean();
        double standardDeviation = norDist.getStandardDeviation();
        return new ContDistNormal(model, name, mean, standardDeviation, showInReport, showInTrace);
    } else if (dist instanceof PoissonDistribution) {
        PoissonDistribution poiDist = (PoissonDistribution) dist;
        double mean = poiDist.getMean();
        return new DiscreteDistPoisson(model, name, mean, showInReport, showInTrace);
    } else if (dist instanceof UniformDistribution) {
        UniformDistribution uniDist = (UniformDistribution) dist;
        double lower = uniDist.getLower();
        double upper = uniDist.getUpper();
        return new ContDistUniform(model, name, lower, upper, showInReport, showInTrace);
    } else {
        throw new InstantiationException("Distribution of node " + nodeId + " not supported.");
    }
}
Also used : PoissonDistribution(de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution) DiscreteDistBinomial(desmoj.core.dist.DiscreteDistBinomial) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) ContDistErlang(desmoj.core.dist.ContDistErlang) ContDistTriangular(desmoj.core.dist.ContDistTriangular) DiscreteDistPoisson(desmoj.core.dist.DiscreteDistPoisson) ContDistNormal(desmoj.core.dist.ContDistNormal) ContDistUniform(desmoj.core.dist.ContDistUniform) ConstantDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) ErlangDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution) ExponentialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution) UniformDistribution(de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution) ContDistExponential(desmoj.core.dist.ContDistExponential) NormalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution) BinomialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution) TriangularDistribution(de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution) Map(java.util.Map)

Example 2 with UniformDistribution

use of de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution in project scylla by bptlab.

the class SimulationConfigurationParser method getDistribution.

public static Distribution getDistribution(Element element, Namespace simNamespace, String fieldType) throws ScyllaValidationException {
    Distribution distribution;
    if (element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace) != null && fieldType.equals("string")) {
        Element el = element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace);
        // changed name here but now in the whole project
        EmpiricalStringDistribution dist = new EmpiricalStringDistribution();
        List<Element> entries = el.getChildren("entry", simNamespace);
        if (entries.isEmpty()) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        double sum = 0;
        try {
            for (Element entry : entries) {
                // normalize frequency to 1.0
                sum += Double.valueOf(entry.getAttributeValue("frequency"));
            }
            for (Element entry : entries) {
                dist.addEntry(entry.getAttributeValue("value"), Double.valueOf(entry.getAttributeValue("frequency")) / sum);
            }
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        distribution = dist;
    } else if (element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace) != null) {
        Element el = element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace);
        // changed name here but now in the whole project
        EmpiricalDistribution dist = new EmpiricalDistribution();
        List<Element> entries = el.getChildren("entry", simNamespace);
        if (entries.isEmpty()) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        double sum = 0;
        try {
            for (Element entry : entries) {
                // normalize frequency to 1.0
                sum += Double.valueOf(entry.getAttributeValue("frequency"));
            }
            for (Element entry : entries) {
                dist.addEntry(Double.valueOf(entry.getAttributeValue("value")), Double.valueOf(entry.getAttributeValue("frequency")) / sum);
            }
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        distribution = dist;
    } else if (element.getChild("binomialDistribution", simNamespace) != null) {
        Element el = element.getChild("binomialDistribution", simNamespace);
        try {
            double probability = Double.valueOf(el.getChildText("probability", simNamespace));
            int amount = Integer.valueOf(el.getChildText("amount", simNamespace));
            distribution = new BinomialDistribution(probability, amount);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a probability and an amount for binomialDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("constantDistribution", simNamespace) != null) {
        Element el = element.getChild("constantDistribution", simNamespace);
        try {
            double constantValue = Double.valueOf(el.getChildText("constantValue", simNamespace));
            distribution = new ConstantDistribution(constantValue);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a constantValue for constantDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("erlangDistribution", simNamespace) != null) {
        Element el = element.getChild("erlangDistribution", simNamespace);
        try {
            long order = Long.valueOf(el.getChildText("order", simNamespace));
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new ErlangDistribution(order, mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a order and a mean for erlangDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("exponentialDistribution", simNamespace) != null) {
        Element el = element.getChild("exponentialDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new ExponentialDistribution(mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean for exponentialDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("triangularDistribution", simNamespace) != null) {
        Element el = element.getChild("triangularDistribution", simNamespace);
        try {
            double lower = Double.valueOf(el.getChildText("lower", simNamespace));
            double upper = Double.valueOf(el.getChildText("upper", simNamespace));
            double peak = Double.valueOf(el.getChildText("peak", simNamespace));
            distribution = new TriangularDistribution(lower, upper, peak);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a lower, a upper and a peak for triangularDistribution at" + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("normalDistribution", simNamespace) != null) {
        Element el = element.getChild("normalDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            double standardDeviation = Double.valueOf(el.getChildText("standardDeviation", simNamespace));
            distribution = new NormalDistribution(mean, standardDeviation);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean and a standardDeviation for normalDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("poissonDistribution", simNamespace) != null) {
        Element el = element.getChild("poissonDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new PoissonDistribution(mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean for poissonDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("uniformDistribution", simNamespace) != null) {
        Element el = element.getChild("uniformDistribution", simNamespace);
        try {
            double lower = Double.valueOf(el.getChildText("lower", simNamespace));
            double upper = Double.valueOf(el.getChildText("upper", simNamespace));
            distribution = new UniformDistribution(lower, upper);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a lower and an upper for uniformDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else {
        throw new ScyllaValidationException("Distribution definition at " + getTaskOfDistribution(element) + " not found or not supported. Check spelling!");
    }
    return distribution;
}
Also used : PoissonDistribution(de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) ErlangDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution) Element(org.jdom2.Element) ExponentialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution) UniformDistribution(de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NormalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) NormalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution) ExponentialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution) TriangularDistribution(de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution) UniformDistribution(de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution) ErlangDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution) ConstantDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution) Distribution(de.hpi.bpt.scylla.model.configuration.distribution.Distribution) BinomialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution) PoissonDistribution(de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution) List(java.util.List) BinomialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution) ConstantDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution) TriangularDistribution(de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution)

Aggregations

BinomialDistribution (de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution)2 ConstantDistribution (de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution)2 EmpiricalDistribution (de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution)2 EmpiricalStringDistribution (de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution)2 ErlangDistribution (de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution)2 ExponentialDistribution (de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution)2 NormalDistribution (de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution)2 PoissonDistribution (de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution)2 TriangularDistribution (de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution)2 UniformDistribution (de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution)2 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)1 ContDistErlang (desmoj.core.dist.ContDistErlang)1 ContDistExponential (desmoj.core.dist.ContDistExponential)1 ContDistNormal (desmoj.core.dist.ContDistNormal)1 ContDistTriangular (desmoj.core.dist.ContDistTriangular)1 ContDistUniform (desmoj.core.dist.ContDistUniform)1 DiscreteDistBinomial (desmoj.core.dist.DiscreteDistBinomial)1 DiscreteDistEmpirical (desmoj.core.dist.DiscreteDistEmpirical)1 DiscreteDistPoisson (desmoj.core.dist.DiscreteDistPoisson)1