| 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.reliability.ReliabilityFactory; |
| 12 | import de.uka.ipd.sdq.pcm.reliability.SoftwareInducedFailureType; |
| 13 | import de.uka.ipd.sdq.pcm.repository.Repository; |
| 14 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
| 15 | |
| 16 | /** |
| 17 | * Provides sensitivity support to alter all software failure-on-demand |
| 18 | * probabilities of a given SoftwareInducedFailureType. |
| 19 | * |
| 20 | * @author brosch |
| 21 | * |
| 22 | */ |
| 23 | public class FailureTypeSensitivity 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 IDs of the affected software-induced failure type. |
| 37 | */ |
| 38 | private List<String> typeIds = null; |
| 39 | |
| 40 | /** |
| 41 | * The constructor. |
| 42 | * |
| 43 | * @param name |
| 44 | * the name of the sensitivity analysis |
| 45 | * @param typeIds |
| 46 | * the IDs of the software-induced failure type |
| 47 | * @param variation |
| 48 | * the parameter variation |
| 49 | */ |
| 50 | public FailureTypeSensitivity(final String name, |
| 51 | final List<String> typeIds, final DoubleParameterVariation variation) { |
| 52 | |
| 53 | // Initialize base variables: |
| 54 | super(name, variation); |
| 55 | |
| 56 | // Store further information: |
| 57 | this.typeIds = typeIds; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Alters the model according to the next sensitivity analysis step. |
| 62 | * |
| 63 | * @return indicates if the model could be successfully altered |
| 64 | */ |
| 65 | protected boolean alterModel() { |
| 66 | |
| 67 | // Set the failure probability: |
| 68 | for (int i = 0; i < descriptions.size(); i++) { |
| 69 | descriptions.get(i).setFailureProbability( |
| 70 | calculator.calculateCurrentDoubleValue( |
| 71 | getDoubleVariation(), getCurrentStepNumber(), |
| 72 | baseValues.get(i))); |
| 73 | } |
| 74 | |
| 75 | // Everything ok: |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Extracts the relevant sensitivity information from the given model. |
| 81 | */ |
| 82 | protected void extractSensitivityInformation() { |
| 83 | |
| 84 | // Declare result lists: |
| 85 | descriptions = new BasicEList<InternalFailureOccurrenceDescription>(); |
| 86 | baseValues = new ArrayList<Double>(); |
| 87 | |
| 88 | // Retrieve all InternalActions in the PCM Repository: |
| 89 | List<Repository> repositories = getModel().getRepositories(); |
| 90 | if (repositories.size() == 0) { |
| 91 | // No repository found! |
| 92 | logger.error("No PCM Repositories found."); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | // Search for the relevant failure type: |
| 97 | for (Repository repository : repositories) { |
| 98 | EList<EObject> failureTypes = helper.getElements(repository, |
| 99 | ReliabilityFactory.eINSTANCE |
| 100 | .createSoftwareInducedFailureType().eClass()); |
| 101 | for (EObject object : failureTypes) { |
| 102 | for (String typeId : typeIds) { |
| 103 | if (((SoftwareInducedFailureType) object).getId().equals( |
| 104 | typeId)) { |
| 105 | for (InternalFailureOccurrenceDescription occurrenceDescription : ((SoftwareInducedFailureType) object) |
| 106 | .getInternalFailureOccurrenceDescriptions__SoftwareInducedFailureType()) { |
| 107 | descriptions.add(occurrenceDescription); |
| 108 | baseValues.add(occurrenceDescription |
| 109 | .getFailureProbability()); |
| 110 | } |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | if (descriptions.size() == 0) { |
| 117 | logger.error("Did not find any FailureOccurrenceDescriptions for " |
| 118 | + "the specified SoftwareInducedFailureTypes"); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * (non-Javadoc) |
| 124 | * |
| 125 | * @seede.uka.ipd.sdq.reliability.solver.sensitivity.MarkovSensitivity# |
| 126 | * getLogHeadingsMulti() |
| 127 | */ |
| 128 | @Override |
| 129 | protected List<List<String>> getLogHeadingsMulti() { |
| 130 | |
| 131 | // Create a result list: |
| 132 | List<List<String>> resultList = new ArrayList<List<String>>(); |
| 133 | |
| 134 | // Create the headings: |
| 135 | ArrayList<String> headings = new ArrayList<String>(); |
| 136 | headings.add("Failure Probability"); |
| 137 | resultList.add(headings); |
| 138 | |
| 139 | // Return the result: |
| 140 | return resultList; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * (non-Javadoc) |
| 145 | * |
| 146 | * @seede.uka.ipd.sdq.reliability.solver.sensitivity.MarkovSensitivity# |
| 147 | * getLogSingleResultsMulti() |
| 148 | */ |
| 149 | @Override |
| 150 | protected List<String> getLogSingleResultsMulti() { |
| 151 | |
| 152 | // Create a result list: |
| 153 | List<String> resultList = new ArrayList<String>(); |
| 154 | |
| 155 | // Create the result strings: |
| 156 | resultList.add(calculator.getCurrentLogEntry(getDoubleVariation(), |
| 157 | getCurrentStepNumber())); |
| 158 | |
| 159 | // Return the result: |
| 160 | return resultList; |
| 161 | } |
| 162 | |
| 163 | } |