| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.reliability.solver.sensitivity; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.List; |
| 8 | |
| 9 | import org.eclipse.emf.common.util.EList; |
| 10 | import org.eclipse.emf.ecore.EObject; |
| 11 | |
| 12 | import de.uka.ipd.sdq.pcm.repository.Repository; |
| 13 | import de.uka.ipd.sdq.pcm.seff.ProbabilisticBranchTransition; |
| 14 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
| 15 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
| 16 | |
| 17 | /** |
| 18 | * Provides sensitivity support to alter the branch probability of a |
| 19 | * probabilistic branch transition. |
| 20 | * |
| 21 | * @author brosch |
| 22 | * |
| 23 | */ |
| 24 | public class ProbabilisticBranchSensitivity extends MarkovSensitivity { |
| 25 | |
| 26 | /** |
| 27 | * The base value. |
| 28 | */ |
| 29 | private double baseValue; |
| 30 | |
| 31 | /** |
| 32 | * The affected probabilistic branch transition; |
| 33 | */ |
| 34 | private ProbabilisticBranchTransition transition = null; |
| 35 | |
| 36 | /** |
| 37 | * The ID of the branch transition to alter. |
| 38 | */ |
| 39 | private String transitionId; |
| 40 | |
| 41 | /** |
| 42 | * The constructor. |
| 43 | * |
| 44 | * @param name |
| 45 | * the name of the sensitivity analysis |
| 46 | * @param branchTransitionId |
| 47 | * the id of the branch transition to alter |
| 48 | * @param variation |
| 49 | * the parameter variation |
| 50 | */ |
| 51 | public ProbabilisticBranchSensitivity(final String name, |
| 52 | final String branchTransitionId, |
| 53 | final DoubleParameterVariation variation) { |
| 54 | |
| 55 | // Initialize base variables: |
| 56 | super(name, variation); |
| 57 | |
| 58 | // Further initialization: |
| 59 | this.transitionId = branchTransitionId; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Alters the model according to the next sensitivity analysis step. |
| 64 | * |
| 65 | * @return indicates if the model could be successfully altered |
| 66 | */ |
| 67 | protected boolean alterModel() { |
| 68 | |
| 69 | // Check validity: |
| 70 | if (transition == null) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | // Set the branch probability: |
| 75 | transition.setBranchProbability(calculator.calculateCurrentDoubleValue( |
| 76 | getDoubleVariation(), getCurrentStepNumber(), baseValue)); |
| 77 | |
| 78 | // Everything ok: |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Extracts the relevant sensitivity information from the given model. |
| 84 | */ |
| 85 | protected void extractSensitivityInformation() { |
| 86 | |
| 87 | // Retrieve all BranchTransitions in the PCM Repository: |
| 88 | List<Repository> repositories = getModel().getRepositories(); |
| 89 | if (repositories.size() == 0) { |
| 90 | // No repository found! |
| 91 | logger.error("No PCM Repositories found."); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | // Search for the relevant branch transition: |
| 96 | for (Repository repository : repositories) { |
| 97 | EList<EObject> branchTransitions = helper.getElements(repository, |
| 98 | SeffFactory.eINSTANCE.createProbabilisticBranchTransition() |
| 99 | .eClass()); |
| 100 | for (EObject object : branchTransitions) { |
| 101 | if (((ProbabilisticBranchTransition) object).getId().equals( |
| 102 | transitionId)) { |
| 103 | transition = (ProbabilisticBranchTransition) object; |
| 104 | baseValue = ((ProbabilisticBranchTransition) object) |
| 105 | .getBranchProbability(); |
| 106 | return; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | if (transition == null) { |
| 111 | logger |
| 112 | .error("Did not find any ProbabilisticBranchTransition with ID \"" |
| 113 | + transitionId + "\""); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Builds the headings strings for logging. |
| 119 | * |
| 120 | * @return the log headings strings |
| 121 | */ |
| 122 | protected List<List<String>> getLogHeadingsMulti() { |
| 123 | |
| 124 | // Create a result list: |
| 125 | List<List<String>> resultList = new ArrayList<List<String>>(); |
| 126 | |
| 127 | // Create the headings: |
| 128 | ArrayList<String> headings = new ArrayList<String>(); |
| 129 | headings.add("Branch Transition Name"); |
| 130 | headings.add("Branch Transition ID"); |
| 131 | headings.add("Branch Probability"); |
| 132 | resultList.add(headings); |
| 133 | |
| 134 | // Return the result: |
| 135 | return resultList; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Builds the results strings for sensitivity logging. |
| 140 | * |
| 141 | * @return the results strings |
| 142 | */ |
| 143 | protected List<String> getLogSingleResultsMulti() { |
| 144 | |
| 145 | // Create a result list: |
| 146 | List<String> resultList = new ArrayList<String>(); |
| 147 | |
| 148 | // Create the result strings: |
| 149 | resultList.add(transition.getEntityName()); |
| 150 | resultList.add(transitionId); |
| 151 | resultList.add(calculator.getCurrentLogEntry(getDoubleVariation(), |
| 152 | getCurrentStepNumber())); |
| 153 | |
| 154 | // Return the result: |
| 155 | return resultList; |
| 156 | } |
| 157 | } |