1 | package de.uka.ipd.sdq.simucomframework.variables.stoexvisitor; |
2 | |
3 | import java.util.Iterator; |
4 | |
5 | import org.apache.log4j.Logger; |
6 | import org.eclipse.emf.ecore.EObject; |
7 | |
8 | import de.uka.ipd.sdq.probfunction.ProbabilityDensityFunction; |
9 | import de.uka.ipd.sdq.probfunction.ProbabilityMassFunction; |
10 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
11 | import de.uka.ipd.sdq.probfunction.math.IProbabilityFunction; |
12 | import de.uka.ipd.sdq.probfunction.math.IProbabilityMassFunction; |
13 | import de.uka.ipd.sdq.probfunction.util.ProbfunctionSwitch; |
14 | import de.uka.ipd.sdq.simucomframework.variables.cache.StoExCache; |
15 | import de.uka.ipd.sdq.simucomframework.variables.cache.StoExCacheEntry; |
16 | |
17 | /** |
18 | * Visitor to visit probfunctions and evaluate them to return a sample |
19 | * @author Steffen Becker |
20 | * |
21 | */ |
22 | public class PCMProbfunctionEvaluationVisitor extends ProbfunctionSwitch<Object> { |
23 | private static Logger logger = |
24 | Logger.getLogger(PCMProbfunctionEvaluationVisitor.class.getName()); |
25 | |
26 | private StoExCacheEntry stoexCacheEntry; |
27 | |
28 | public PCMProbfunctionEvaluationVisitor(StoExCacheEntry stoexCacheEntry) { |
29 | this.stoexCacheEntry = stoexCacheEntry; |
30 | } |
31 | |
32 | @Override |
33 | public Object caseProbabilityDensityFunction(ProbabilityDensityFunction object) { |
34 | IProbabilityFunction pdf = stoexCacheEntry.getProbFunction(object); |
35 | Object result = drawSample(pdf); |
36 | logger.debug("Draw Sample returned "+result); |
37 | return result; |
38 | } |
39 | |
40 | @Override |
41 | public Object caseProbabilityMassFunction(ProbabilityMassFunction object) { |
42 | IProbabilityFunction pdf = stoexCacheEntry.getProbFunction(object); |
43 | Object result = drawSample(pdf); |
44 | logger.debug("Draw Sample returned "+result); |
45 | return result; |
46 | } |
47 | |
48 | private Object drawSample(IProbabilityFunction f) { |
49 | if (f == null) |
50 | throw new RuntimeException("Probability function in drawSample() must be != null"); |
51 | if (f instanceof IProbabilityMassFunction) |
52 | return ((IProbabilityMassFunction)f).drawSample(); |
53 | if (f instanceof IProbabilityDensityFunction) |
54 | return ((IProbabilityDensityFunction)f).drawSample(); |
55 | throw new RuntimeException("Should never be here. Unknown Probfunction found!"); |
56 | } |
57 | } |