1 | package de.uka.ipd.sdq.reliability.solver.sensitivity; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import org.eclipse.emf.common.util.BasicEList; |
7 | import org.eclipse.emf.common.util.EList; |
8 | import org.eclipse.emf.ecore.EObject; |
9 | |
10 | import de.uka.ipd.sdq.pcm.reliability.InternalFailureOccurrenceDescription; |
11 | import de.uka.ipd.sdq.pcm.repository.Repository; |
12 | import de.uka.ipd.sdq.pcm.seff.InternalAction; |
13 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
14 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
15 | |
16 | /** |
17 | * Provides sensitivity support to alter the failure probabilities of all |
18 | * internal actions within the whole PCM Repository. |
19 | * |
20 | * @author brosch |
21 | * |
22 | */ |
23 | public class SoftwareSensitivity extends MarkovSensitivity { |
24 | |
25 | /** |
26 | * The list of base values of this sensitivity. |
27 | */ |
28 | private List<Double> baseValues = null; |
29 | |
30 | /** |
31 | * The list of affected internal failure occurrence descriptions. |
32 | */ |
33 | private List<InternalFailureOccurrenceDescription> descriptions = null; |
34 | |
35 | /** |
36 | * The constructor. |
37 | * |
38 | * @param name |
39 | * the name of the sensitivity analysis |
40 | * @param variation |
41 | * the parameter variation |
42 | */ |
43 | public SoftwareSensitivity(final String name, |
44 | final DoubleParameterVariation variation) { |
45 | |
46 | // Initialize base variables: |
47 | super(name, variation); |
48 | } |
49 | |
50 | /** |
51 | * Alters the model according to the next sensitivity analysis step. |
52 | * |
53 | * @return indicates if the model could be successfully altered |
54 | */ |
55 | protected boolean alterModel() { |
56 | |
57 | // Set the failure probability: |
58 | for (int i = 0; i < descriptions.size(); i++) { |
59 | descriptions.get(i).setFailureProbability( |
60 | calculator.calculateCurrentDoubleValue( |
61 | getDoubleVariation(), getCurrentStepNumber(), |
62 | baseValues.get(i))); |
63 | } |
64 | |
65 | // Everything ok: |
66 | return true; |
67 | } |
68 | |
69 | /** |
70 | * Extracts the relevant sensitivity information from the given model. |
71 | */ |
72 | protected void extractSensitivityInformation() { |
73 | |
74 | // Declare result lists: |
75 | descriptions = new BasicEList<InternalFailureOccurrenceDescription>(); |
76 | baseValues = new ArrayList<Double>(); |
77 | |
78 | // Retrieve all InternalActions in the PCM Repository: |
79 | List<Repository> repositories = getModel().getRepositories(); |
80 | if (repositories.size() == 0) { |
81 | // No repository found! |
82 | logger.error("No PCM Repositories found."); |
83 | return; |
84 | } |
85 | |
86 | // Search for the relevant BasicComponent: |
87 | for (Repository repository : repositories) { |
88 | EList<EObject> internalActions = helper.getElements(repository, |
89 | SeffFactory.eINSTANCE.createInternalAction().eClass()); |
90 | for (EObject object : internalActions) { |
91 | for (InternalFailureOccurrenceDescription description : ((InternalAction) object) |
92 | .getInternalFailureOccurrenceDescriptions__InternalAction()) { |
93 | descriptions.add(description); |
94 | baseValues.add(description.getFailureProbability()); |
95 | } |
96 | } |
97 | } |
98 | if (descriptions.size() == 0) { |
99 | logger.error("Did not find any FailureOccurrenceDescriptions " |
100 | + "in the PCM Repository."); |
101 | } |
102 | } |
103 | |
104 | /** |
105 | * Builds the headings strings for logging. |
106 | * |
107 | * @return the log headings strings |
108 | */ |
109 | protected List<List<String>> getLogHeadingsMulti() { |
110 | |
111 | // Create a result list: |
112 | List<List<String>> resultList = new ArrayList<List<String>>(); |
113 | |
114 | // Create the headings: |
115 | ArrayList<String> headings = new ArrayList<String>(); |
116 | headings.add("Software Failure Probabilities"); |
117 | resultList.add(headings); |
118 | |
119 | // Return the result: |
120 | return resultList; |
121 | } |
122 | |
123 | /** |
124 | * Builds the results strings for sensitivity logging. |
125 | * |
126 | * @return the results strings |
127 | */ |
128 | protected List<String> getLogSingleResultsMulti() { |
129 | |
130 | // Create a result list: |
131 | List<String> resultList = new ArrayList<String>(); |
132 | |
133 | // Create the result strings: |
134 | resultList.add(calculator.getCurrentLogEntry(getDoubleVariation(), |
135 | getCurrentStepNumber())); |
136 | |
137 | // Return the result: |
138 | return resultList; |
139 | } |
140 | } |