EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.stoex.analyser.probfunction]

COVERAGE SUMMARY FOR SOURCE FILE [ProbfunctionHelper.java]

nameclass, %method, %block, %line, %
ProbfunctionHelper.java0%   (0/1)0%   (0/7)0%   (0/299)0%   (0/71)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProbfunctionHelper0%   (0/1)0%   (0/7)0%   (0/299)0%   (0/71)
<static initializer> 0%   (0/1)0%   (0/11)0%   (0/6)
ProbfunctionHelper (): void 0%   (0/1)0%   (0/3)0%   (0/1)
createFunction (List, String, ProbfunctionFactory): ContinuousPDF 0%   (0/1)0%   (0/191)0%   (0/41)
getDoubleValue (Unary): double 0%   (0/1)0%   (0/40)0%   (0/7)
isFunctionID (String): boolean 0%   (0/1)0%   (0/10)0%   (0/4)
isFunctionWithOneParameterID (String): boolean 0%   (0/1)0%   (0/20)0%   (0/6)
isFunctionWithTwoParameterID (String): boolean 0%   (0/1)0%   (0/24)0%   (0/7)

1package de.uka.ipd.sdq.stoex.analyser.probfunction;
2 
3import java.util.List;
4 
5 
6import de.uka.ipd.sdq.probfunction.ContinuousPDF;
7import de.uka.ipd.sdq.probfunction.ExponentialDistribution;
8import de.uka.ipd.sdq.probfunction.GammaDistribution;
9import de.uka.ipd.sdq.probfunction.LognormalDistribution;
10import de.uka.ipd.sdq.probfunction.NormalDistribution;
11import de.uka.ipd.sdq.probfunction.ProbfunctionFactory;
12import de.uka.ipd.sdq.probfunction.math.IGammaDistribution;
13import de.uka.ipd.sdq.probfunction.math.ILognormalDistribution;
14 
15import de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionFactoryImpl;
16import de.uka.ipd.sdq.stoex.DoubleLiteral;
17import de.uka.ipd.sdq.stoex.Expression;
18import de.uka.ipd.sdq.stoex.IntLiteral;
19import de.uka.ipd.sdq.stoex.NegativeExpression;
20import de.uka.ipd.sdq.stoex.NumericLiteral;
21import de.uka.ipd.sdq.stoex.Unary;
22 
23public class ProbfunctionHelper {
24        
25        public static final String LOGNORM = "Lognorm";
26        public static final String LOGNORM2 = "LognormMoments";
27        public static final String GAMMA = "Gamma";
28        public static final String GAMMA2 = "GammaMoments";
29        public static final String NORM = "Norm";
30        
31        public static final Object EXP = "Exp";
32        public static final Object POIS = "Pois";
33        public static final Object UNIINT = "UniInt";
34        public static final Object UNIDOUBLE = "UniDouble";
35        public static final Object BINOM = "Binom";
36 
37        public static ContinuousPDF createFunction(List<Expression> parameters, String type, ProbfunctionFactory probFuncFactory) {
38                
39                try {
40                
41                        if (type.equals(LOGNORM)){
42                                LognormalDistribution lognorm = probFuncFactory.createLognormalDistribution();
43                                lognorm.setMu(getDoubleValue((Unary)parameters.get(0)));
44                                lognorm.setSigma(getDoubleValue((NumericLiteral)parameters.get(1)));
45                                return lognorm;
46                        } else if (type.equals(LOGNORM2)){
47                                LognormalDistribution lognorm = probFuncFactory.createLognormalDistribution();
48                                double mean = getDoubleValue((NumericLiteral)parameters.get(0));
49                                double stdev = getDoubleValue((NumericLiteral)parameters.get(1));
50                                double variance = stdev * stdev ;
51                                ILognormalDistribution dist = ProbabilityFunctionFactoryImpl.getInstance().getPDFFactory().createLognormalDistributionFromMoments(mean, variance);
52                                lognorm.setMu(dist.getMu());
53                                lognorm.setSigma(dist.getSigma());
54                                return lognorm;
55                        } else if (type.equals(GAMMA)){
56                                GammaDistribution gamma = probFuncFactory.createGammaDistribution();
57                                gamma.setAlpha(getDoubleValue((NumericLiteral)parameters.get(0)));
58                                gamma.setTheta(getDoubleValue((NumericLiteral)parameters.get(1)));
59                                return gamma;
60                        } else if (type.equals(GAMMA2)){
61                                GammaDistribution gamma = probFuncFactory.createGammaDistribution();
62                                double mean = getDoubleValue((NumericLiteral)parameters.get(0));
63                                double coeffVar = getDoubleValue((NumericLiteral)parameters.get(1));
64                                IGammaDistribution dist = ProbabilityFunctionFactoryImpl.getInstance().getPDFFactory().createGammaDistributionFromMoments(mean, coeffVar);
65                                gamma.setAlpha(dist.getAlpha());
66                                gamma.setTheta(dist.getTheta());
67                                return gamma;
68                        } else if (type.equals(NORM)){
69                                NormalDistribution expo = probFuncFactory.createNormalDistribution();
70                                double mean = getDoubleValue((NumericLiteral)parameters.get(0));
71                                double sigma = getDoubleValue((NumericLiteral)parameters.get(1));
72                                expo.setMu(mean);
73                                expo.setSigma(sigma);
74                                return expo;
75                        } else if (type.equals(EXP)){
76                                ExponentialDistribution exp = probFuncFactory.createExponentialDistribution();
77                                exp.setRate(getDoubleValue((NumericLiteral)parameters.get(0)));
78                                return exp;
79                        } else throw new UnsupportedOperationException("Function "+type+" not supported!");
80                } catch (IndexOutOfBoundsException e){
81                        throw new UnsupportedOperationException("Function "+type+" needs more parameters. See help and stacktrace.", e);
82                }
83        } 
84        
85        private static double getDoubleValue(Unary unary) {
86                if (unary instanceof DoubleLiteral){
87                        return ((DoubleLiteral)unary).getValue();
88                } else if (unary instanceof IntLiteral){
89                        return ((IntLiteral)unary).getValue();
90                } else if (unary instanceof NegativeExpression){
91                        return (-1.0) * getDoubleValue(((NegativeExpression)unary).getInner());
92                } else {
93                        throw new RuntimeException("Unknown numeric literal "+unary.getClass().getName()+" encountered. Cannot handle it, aborting. Please contact developers.");
94                }
95        }
96 
97        public static boolean isFunctionWithTwoParameterID(String id){
98                if (id.equals(LOGNORM) 
99                                || id.equals(LOGNORM2)
100                                || id.equals(NORM)
101                                || id.equals(GAMMA)
102                                || id.equals(GAMMA2))
103                        return true;
104                return false;
105        }
106        
107        public static boolean isFunctionWithOneParameterID(String id){
108                if (id.equals(EXP) 
109                                || id.equals(BINOM)
110                                || id.equals(POIS)
111                                || id.equals(UNIINT))
112                        return true;
113                return false;
114        }
115        
116        public static boolean isFunctionID(String id){
117                if (isFunctionWithOneParameterID(id)
118                                || isFunctionWithTwoParameterID(id))
119                        return true;
120                return false;
121        }
122 
123        
124}

[all classes][de.uka.ipd.sdq.stoex.analyser.probfunction]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov