use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class SimpleBranchReference method getModel.
/**
* Creates a reference model that contains a branch element. Accordingly, user sessions whose
* call sequences differ from each other at the position of the branch are created.(RQ-1.2)
*
* @param referenceModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModelProvider
* repository model provider
* @param correspondenceModel
* correspondence model
*
* @return a reference usage model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final ICorrespondence correspondenceModel) throws IOException {
// Create a random number of user sessions and random model element parameters. The user
// sessions' behavior will be created according to the reference usage model and
// subsequently the user sessions are used to create a usage model. The created usage model
// is matched against the reference usage model. The minimum number of user sessions is set
// dependently from the random number of branch transitions, because it must be ensured that
// each branch transition is represented within the user sessions.
final int numberOfBranchTransitions = TestHelper.getRandomInteger(5, 2);
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 10 * numberOfBranchTransitions);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
// In the following the reference usage model is created
Optional<Correspondent> correspondent;
final UsageModel usageModel = UsageModelFactory.createUsageModel();
final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
AbstractUserAction lastAction = start;
// Creates the branch element and the branch transitions according to the random number of
// branch transitions
final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
UsageModelFactory.connect(start, branch);
// the alternative call sequences
for (int i = 0; i < numberOfBranchTransitions; i++) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
final Start startBranchTransition = UsageModelFactory.createAddStartAction("", branchTransitionBehaviour);
final Stop stopBranchTransition = UsageModelFactory.createAddStopAction("", branchTransitionBehaviour);
lastAction = startBranchTransition;
if (i >= 0 && i < 5) {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
if (i == 0) {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
} else {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
}
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stopBranchTransition);
}
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(scenarioBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(branch, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stop);
final List<Integer> branchTransitionCounter = SimpleBranchReference.computeBranchTransitions(entryCallSequenceModel, branch, numberOfBranchTransitions);
// the randomly created user sessions
for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
branch.getBranchTransitions_Branch().get(i).setBranchProbability((double) branchTransitionCounter.get(i) / numberOfConcurrentUsers);
}
return SimpleBranchReference.saveReferenceElements(usageModel, referenceModelFileName, entryCallSequenceModel);
}
use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class PcmUsageModelBuilder method createBranch.
/**
* Creates for a branch a corresponding PCM branch including a corresponding usage scenario.
*
* @param scenarioBehaviour
* to that the PCM branch is added
* @param branchElement
* that is transformed to a PCM branch element
* @return a PCM branch element
*/
private org.palladiosimulator.pcm.usagemodel.Branch createBranch(final ScenarioBehaviour scenarioBehaviour, final BranchElement branchElement) {
final org.palladiosimulator.pcm.usagemodel.Branch branchUM = UsageModelFactory.createBranch("", scenarioBehaviour);
for (final BranchTransitionElement transition : branchElement.getBranchTransitions()) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branchUM);
final ScenarioBehaviour branchScenarioBehaviour = this.transformSequenceToScenarioBehavior(0, transition.getBranchSequence(), null);
branchTransition.setBranchedBehaviour_BranchTransition(branchScenarioBehaviour);
branchTransition.setBranch_BranchTransition(branchUM);
branchTransition.setBranchProbability(transition.getTransitionLikelihood());
}
return branchUM;
}
use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class PcmUsageModelBuilder method createChildBranch.
/**
* Creates a PCM branch corresponding to the child branches of the passed branch.
*
* @param scenarioBehaviour
* to that the PCM branch is added
* @param indexOfScenario
* states the index of the scenario within the usage scenario
* @param branch
* whose child branches are transformed to a PCM branch
* @return a PCM branch
*/
private org.palladiosimulator.pcm.usagemodel.Branch createChildBranch(final ScenarioBehaviour scenarioBehaviour, final int indexOfScenario, final Branch branch) {
if (branch.getChildBranches().size() > 0) {
final org.palladiosimulator.pcm.usagemodel.Branch branchUM = UsageModelFactory.createBranch("", scenarioBehaviour);
for (final Branch childBranch : branch.getChildBranches()) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branchUM);
branchTransition.setBranchedBehaviour_BranchTransition(this.branchScenarioBehavioursOfUserGroups.get(indexOfScenario).get(childBranch.getBranchId()));
branchTransition.setBranch_BranchTransition(branchUM);
branchTransition.setBranchProbability(childBranch.getBranchLikelihood());
}
return branchUM;
}
return null;
}
use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class UsageModelToBehaviorModelStage method traverseBranch.
private Map<EntryCallNode, Double> traverseBranch(final BehaviorModel behaviorModel, final Optional<Map<EntryCallNode, Double>> optPreviousNodes, final Branch branch) {
// assign new probabilities to the nodes
final Map<BranchTransition, Map<EntryCallNode, Double>> transitionMap = new HashMap<>();
for (final BranchTransition transition : branch.getBranchTransitions_Branch()) {
final Map<EntryCallNode, Double> branchMap = new HashMap<>();
optPreviousNodes.ifPresent(previousNodes -> previousNodes.keySet().stream().forEach(node -> branchMap.put(node, transition.getBranchProbability())));
transitionMap.put(transition, branchMap);
}
// traverse all branches and collect the end nodes
return branch.getBranchTransitions_Branch().stream().map(transition -> this.traverseScenarioBehavior(transition.getBranchedBehaviour_BranchTransition(), behaviorModel, // all
Optional.of(transitionMap.get(transition)))).collect(HashMap::new, Map::putAll, // collect endNodes
Map::putAll);
}
use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class PcmUsageModelBuilder method createLoopBranch.
/**
* Creates a PCM branch for a LoopBranchElement.
*
* @param scenarioBehaviour
* to that the PCM branch is added
* @param loopBranch
* that is transformed to a PCM branch
* @return a PCM branch
*/
private org.palladiosimulator.pcm.usagemodel.Branch createLoopBranch(final ScenarioBehaviour scenarioBehaviour, final LoopBranchElement loopBranch) {
final org.palladiosimulator.pcm.usagemodel.Branch branchUM = UsageModelFactory.createBranch("", scenarioBehaviour);
for (final Branch branch : loopBranch.getLoopBranches()) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branchUM);
final ScenarioBehaviour branchScenarioBehaviour = this.transformSequenceToScenarioBehavior(0, branch.getBranchSequence(), null);
branchTransition.setBranchedBehaviour_BranchTransition(branchScenarioBehaviour);
branchTransition.setBranch_BranchTransition(branchUM);
branchTransition.setBranchProbability(branch.getBranchLikelihood());
}
return branchUM;
}
Aggregations