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.resourceenvironment.ProcessingResourceSpecification; |
11 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
12 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentFactory; |
13 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
14 | |
15 | /** |
16 | * Alters all MTTF values of hardware resources in the model. |
17 | * |
18 | * @author brosch |
19 | * |
20 | */ |
21 | public class MTTFSensitivity extends MarkovSensitivity { |
22 | |
23 | /** |
24 | * The list of base values. |
25 | */ |
26 | List<Double> baseValues = null; |
27 | |
28 | /** |
29 | * The list of affected processing resource specifications. |
30 | */ |
31 | List<ProcessingResourceSpecification> specifications = null; |
32 | |
33 | /** |
34 | * The constructor. |
35 | * |
36 | * @param name |
37 | * the name of the sensitivity analysis |
38 | * @param variation |
39 | * the parameter variation |
40 | */ |
41 | public MTTFSensitivity(final String name, |
42 | final DoubleParameterVariation variation) { |
43 | |
44 | // Initialize basic variables: |
45 | super(name, variation); |
46 | } |
47 | |
48 | /** |
49 | * Alters the model according to the next sensitivity analysis step. |
50 | * |
51 | * @return indicates if the model could be successfully altered |
52 | */ |
53 | protected boolean alterModel() { |
54 | |
55 | // Iterate through all specifications: |
56 | for (int i = 0; i < specifications.size(); i++) { |
57 | // Set the failure probability: |
58 | specifications.get(i).setMTTF( |
59 | calculator.calculateCurrentDoubleValue( |
60 | getDoubleVariation(), getCurrentStepNumber(), |
61 | baseValues.get(i))); |
62 | } |
63 | |
64 | // Everything ok: |
65 | return true; |
66 | } |
67 | |
68 | /** |
69 | * Extracts the relevant sensitivity information from the given model. |
70 | */ |
71 | protected void extractSensitivityInformation() { |
72 | |
73 | // Declare result variables: |
74 | specifications = new BasicEList<ProcessingResourceSpecification>(); |
75 | baseValues = new ArrayList<Double>(); |
76 | |
77 | // Retrieve the PCM resource environment: |
78 | if (getModel().getResourceEnvironment() == null) { |
79 | // No resource environment found! |
80 | logger.error("No PCM ResourceEnvironment found."); |
81 | return; |
82 | } |
83 | |
84 | // Retrieve all resource specifications in all containers: |
85 | ResourceContainer resourceContainer = null; |
86 | EList<EObject> resourceContainers = helper.getElements(getModel() |
87 | .getResourceEnvironment(), ResourceenvironmentFactory.eINSTANCE |
88 | .createResourceContainer().eClass()); |
89 | for (EObject object : resourceContainers) { |
90 | resourceContainer = (ResourceContainer) object; |
91 | for (ProcessingResourceSpecification specification : resourceContainer |
92 | .getActiveResourceSpecifications_ResourceContainer()) { |
93 | specifications.add(specification); |
94 | baseValues.add(specification.getMTTF()); |
95 | } |
96 | } |
97 | if (specifications.size() == 0) { |
98 | logger.error("Did not find any ProcessingResourceSpecifications " |
99 | + "in the PCM ResourceEnvironment"); |
100 | } |
101 | } |
102 | |
103 | /** |
104 | * Builds the headings strings for logging. |
105 | * |
106 | * @return the log headings strings |
107 | */ |
108 | protected List<List<String>> getLogHeadingsMulti() { |
109 | |
110 | // Create a result list: |
111 | List<List<String>> resultList = new ArrayList<List<String>>(); |
112 | |
113 | // Create the headings: |
114 | ArrayList<String> headings = new ArrayList<String>(); |
115 | headings.add("Mean Time To Failure"); |
116 | resultList.add(headings); |
117 | |
118 | // Return the result: |
119 | return resultList; |
120 | } |
121 | |
122 | /** |
123 | * Builds the results strings for sensitivity logging. |
124 | * |
125 | * @return the results strings |
126 | */ |
127 | protected List<String> getLogSingleResultsMulti() { |
128 | |
129 | // Create a result list: |
130 | List<String> resultList = new ArrayList<String>(); |
131 | |
132 | // Create the result strings: |
133 | resultList.add(calculator.getCurrentLogEntry(getDoubleVariation(), |
134 | getCurrentStepNumber())); |
135 | |
136 | // Return the result: |
137 | return resultList; |
138 | } |
139 | } |