use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class LoopWithinBranchReference method createBranch.
/**
* Creates a branch and branch transitions according to the random countOfBranchTransitions.
*
* @param scenarioBehaviour
* @param repositoryLookupModel
* @param correspondenceModel
* @param numberOfBranchTransitions
* @param lengthOfBranchSequence
* @param countOfLoop
* @return
*/
private static Branch createBranch(final RepositoryLookupModelProvider repositoryLookupModel, final ScenarioBehaviour scenarioBehaviour, final CorrespondenceModel correspondenceModel, final int numberOfBranchTransitions, final int lengthOfBranchSequence, final int countOfLoop) {
final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
final Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
UsageModelFactory.connect(start, branch);
UsageModelFactory.connect(branch, stop);
AbstractUserAction lastAction = start;
// For each branch transition its calls are added to the branch transition
for (int i = 0; i < numberOfBranchTransitions; i++) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
final Start startBranchTransition = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(branchTransitionBehaviour, startBranchTransition);
final Stop stopBranchTransition = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(branchTransitionBehaviour, stopBranchTransition);
lastAction = startBranchTransition;
if (i >= 0 && i < 3) {
final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (lengthOfBranchSequence == 2) {
final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
}
// Within the branch transition a loop element is created
final Loop loop = UsageModelFactory.createLoop("", branchTransitionBehaviour);
UsageModelFactory.connect(lastAction, loop);
final PCMRandomVariable pcmLoop2Iteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoop2Iteration.setSpecification(String.valueOf(countOfLoop));
loop.setLoopIteration_Loop(pcmLoop2Iteration);
final Start loopStart = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
final Stop loopStop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
lastAction = loopStart;
// The calls that are iterated are added to the loop
final OperationSignature operationSignature;
switch(i) {
case 0:
operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
break;
case 1:
operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
break;
case 2:
operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
break;
default:
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, loopStop);
UsageModelFactory.connect(loop, stopBranchTransition);
}
return branch;
}
use of org.palladiosimulator.pcm.usagemodel.BranchTransition in project iobserve-analysis by research-iobserve.
the class UserBehaviorEvaluation method sortBranchTransitions.
/**
* It sorts a list of branch transitions by their first EntryLevelSystemCall.
*
* @param branchTransitions
* that are sorted
* @return sorted list of branch transitions
*/
private static List<BranchTransition> sortBranchTransitions(final List<BranchTransition> branchTransitions) {
final List<String> entityNames = new ArrayList<>();
final List<BranchTransition> branchTransitionsSorted = new ArrayList<>();
for (final BranchTransition branchTransition : branchTransitions) {
final EntryLevelSystemCall call = (EntryLevelSystemCall) branchTransition.getBranchedBehaviour_BranchTransition().getActions_ScenarioBehaviour().get(0).getSuccessor();
entityNames.add(call.getEntityName());
}
java.util.Collections.sort(entityNames);
for (final String entityName : entityNames) {
for (final BranchTransition branchTransition : branchTransitions) {
final EntryLevelSystemCall call = (EntryLevelSystemCall) branchTransition.getBranchedBehaviour_BranchTransition().getActions_ScenarioBehaviour().get(0).getSuccessor();
if (call.getEntityName().equals(entityName)) {
branchTransitionsSorted.add(branchTransition);
}
}
}
return branchTransitionsSorted;
}
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 CorrespondenceModel 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 UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
// In the following the reference usage model is created
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 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) {
final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, operationSignature);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
final OperationSignature operationSignature;
if (i == 0) {
operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
} else {
operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
}
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, operationSignature);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stopBranchTransition);
}
final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
if (operationSignature != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, operationSignature);
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);
}
Aggregations