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.CommunicationLinkResourceSpecification; |
11 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
12 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentFactory; |
13 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
14 | |
15 | /** |
16 | * Provides sensitivity support to alter the failure probabilities of all |
17 | * communication links within the whole PCM Resource Environment. |
18 | * |
19 | * @author brosch |
20 | * |
21 | */ |
22 | public class NetworkSensitivity extends MarkovSensitivity { |
23 | |
24 | /** |
25 | * The list of base values. |
26 | */ |
27 | private List<Double> baseValues = null; |
28 | |
29 | /** |
30 | * The list of affected communication link resource specifications. |
31 | */ |
32 | private List<CommunicationLinkResourceSpecification> resources = null; |
33 | |
34 | /** |
35 | * The constructor. |
36 | * |
37 | * @param name |
38 | * the name of the sensitivity analysis |
39 | * @param variation |
40 | * the parameter variation |
41 | */ |
42 | public NetworkSensitivity(final String name, |
43 | final DoubleParameterVariation variation) { |
44 | |
45 | // Initialize base variables: |
46 | super(name, variation); |
47 | } |
48 | |
49 | /** |
50 | * Alters the model according to the next sensitivity analysis step. |
51 | * |
52 | * @return indicates if the model could be successfully altered |
53 | */ |
54 | protected boolean alterModel() { |
55 | |
56 | // Set the failure probabilities: |
57 | for (int i = 0; i < resources.size(); i++) { |
58 | resources.get(i).setFailureProbability( |
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 lists: |
74 | resources = new BasicEList<CommunicationLinkResourceSpecification>(); |
75 | baseValues = new ArrayList<Double>(); |
76 | |
77 | // Retrieve the PCM Resource Environment: |
78 | ResourceEnvironment resourceEnvironment = getModel() |
79 | .getResourceEnvironment(); |
80 | if (resourceEnvironment == null) { |
81 | // No resource environment found! |
82 | logger.error("No PCM ResourceEnvironment found."); |
83 | return; |
84 | } |
85 | |
86 | // Search for the relevant BasicComponent: |
87 | EList<EObject> commResources = helper.getElements(resourceEnvironment, |
88 | ResourceenvironmentFactory.eINSTANCE |
89 | .createCommunicationLinkResourceSpecification() |
90 | .eClass()); |
91 | for (EObject object : commResources) { |
92 | resources.add((CommunicationLinkResourceSpecification) object); |
93 | baseValues.add(((CommunicationLinkResourceSpecification) object) |
94 | .getFailureProbability()); |
95 | } |
96 | if (resources.size() == 0) { |
97 | logger |
98 | .error("Did not find any CommunicationLinkResourceSpecifications " |
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("Network Failure Probabilities"); |
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 | } |