1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.spa.basicsolver.visitor.perfhandler; |
5 | |
6 | import java.util.Hashtable; |
7 | |
8 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
9 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException; |
10 | import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException; |
11 | import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException; |
12 | import de.uka.ipd.sdq.spa.basicsolver.visitor.AlternativeHandler; |
13 | import de.uka.ipd.sdq.spa.expression.Alternative; |
14 | import de.uka.ipd.sdq.spa.expression.Expression; |
15 | |
16 | /** |
17 | * @author Ihssane |
18 | * |
19 | */ |
20 | public class PerformanceAlternativeHandler implements AlternativeHandler { |
21 | |
22 | private Hashtable<Expression, IProbabilityDensityFunction> pdfTable; |
23 | |
24 | protected PerformanceAlternativeHandler( |
25 | Hashtable<Expression, IProbabilityDensityFunction> pdfTable) { |
26 | this.pdfTable = pdfTable; |
27 | } |
28 | |
29 | public void handle(Alternative alt) { |
30 | try { |
31 | IProbabilityDensityFunction leftDF = pdfTable.get(alt.getLeftOption() |
32 | .getRegexp()); |
33 | IProbabilityDensityFunction rightDF = pdfTable.get(alt.getRightOption() |
34 | .getRegexp()); |
35 | double rightProb = alt.getRightOption().getProbability(); |
36 | double leftProb = alt.getLeftOption().getProbability(); |
37 | |
38 | IProbabilityDensityFunction altPDF = leftDF.scale(leftProb).add( |
39 | rightDF.scale(rightProb)); |
40 | pdfTable.put(alt, altPDF); |
41 | } catch (FunctionsInDifferenDomainsException e) { |
42 | e.printStackTrace(); |
43 | System.exit(1); |
44 | } catch (UnknownPDFTypeException e) { |
45 | e.printStackTrace(); |
46 | System.exit(1); |
47 | } catch (IncompatibleUnitsException e) { |
48 | e.printStackTrace(); |
49 | System.exit(1); |
50 | } |
51 | } |
52 | |
53 | public Hashtable<Expression, IProbabilityDensityFunction> getPdfTable() { |
54 | return pdfTable; |
55 | } |
56 | |
57 | public void setPdfTable( |
58 | Hashtable<Expression, IProbabilityDensityFunction> pdfTable) { |
59 | this.pdfTable = pdfTable; |
60 | } |
61 | |
62 | public PerformanceAlternativeHandler() { |
63 | super(); |
64 | } |
65 | |
66 | } |