Search in sources :

Example 6 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class BranchWithinLoopReference method createBranchTransition.

/**
 * Create a branch transition.
 *
 * @param callId
 *            id of the operation class and operation signature
 * @param repositoryLookupModel
 *            usage model builder
 * @param branch
 *            pcm branch element
 * @param correspondenceModel
 *            correspondence model data
 *
 * @return returns the created branch transition or null on error
 */
private static BranchTransition createBranchTransition(final int callId, final RepositoryLookupModelProvider repositoryLookupModel, final org.palladiosimulator.pcm.usagemodel.Branch branch, final ICorrespondence correspondenceModel) {
    final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
    final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
    final Start start = UsageModelFactory.createStart("");
    UsageModelFactory.addUserAction(branchTransitionBehaviour, start);
    final Stop stop = UsageModelFactory.createStop("");
    UsageModelFactory.addUserAction(branchTransitionBehaviour, stop);
    final Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[callId], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[callId]);
    if (optionCorrespondent.isPresent()) {
        final Correspondent correspondent = optionCorrespondent.get();
        final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
        UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
        UsageModelFactory.connect(start, entryLevelSystemCall);
        UsageModelFactory.connect(entryLevelSystemCall, stop);
        return branchTransition;
    } else {
        return null;
    }
}
Also used : EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent)

Example 7 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class LoopWithinBranchReference method getModel.

/**
 * It creates a reference usage model that contains loops within branches. Accordingly, user
 * sessions whose call sequences differ from each other at the positions of the branches and
 * that contain iterated call sequences are created.(RQ-1.6)
 *
 * @param referenceUsageModelFileName
 *            file name of the reference model to store its result
 * @param repositoryLookupModel
 *            repository lookup model
 * @param correspondenceModel
 *            correspondence model
 *
 * @return a reference model and corresponding user sessions
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, 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(3, 2);
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(30, 10 * numberOfBranchTransitions);
    final int lengthOfBranchSequence = TestHelper.getRandomInteger(2, 1);
    final int countOfLoop = TestHelper.getRandomInteger(3, 2);
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    // 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();
    // lastAction = start;
    final Branch branch = LoopWithinBranchReference.createBranch(repositoryLookupModel, scenarioBehaviour, correspondenceModel, numberOfBranchTransitions, lengthOfBranchSequence, countOfLoop);
    // According to the reference usage model user sessions are created that exactly represent
    // the user behavior of the reference usage model. The entry and exit times enable that the
    // calls within the user sessions are ordered according to the reference usage model. The
    // branch transition counter ensures that each branch transition is represnted within the
    // user sessions
    final List<Integer> branchTransitionCounter = new ArrayList<>();
    boolean areAllBranchesVisited = true;
    do {
        for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
            branchTransitionCounter.add(i, 0);
        }
        int entryTime = 1;
        for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
            entryTime = 1;
            // Each user session represents one of the branch transitions
            final int branchDecisioner = TestHelper.getRandomInteger(numberOfBranchTransitions - 1, 0);
            if (branchDecisioner == 0) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 0, 1, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            } else if (branchDecisioner == 1) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 1, 2, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            } else if (branchDecisioner == 2) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 2, 0, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            }
        }
        // It is checked whether all branch transitions are represented within the user sessions
        for (int i = 0; i < branchTransitionCounter.size(); i++) {
            if (branchTransitionCounter.get(i) == 0) {
                areAllBranchesVisited = false;
                break;
            }
        }
    } while (!areAllBranchesVisited);
    // Sets the likelihoods of the branch transitions according to the created user sessions
    for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
        branch.getBranchTransitions_Branch().get(i).setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
    }
    // Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
    // as the reference elements. Our approach is now executed with the EntryCallSequenceModel
    // and the resulting usage model can be matched against the reference usage model
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    return referenceElements;
}
Also used : UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Branch(org.palladiosimulator.pcm.usagemodel.Branch) ArrayList(java.util.ArrayList) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements)

Example 8 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour 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 ICorrespondence 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 Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
            if (optionCorrespondent.isPresent()) {
                final Correspondent correspondent = optionCorrespondent.get();
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
                UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (lengthOfBranchSequence == 2) {
            final Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
            if (optionCorrespondent.isPresent()) {
                final Correspondent correspondent = optionCorrespondent.get();
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
                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 Optional<Correspondent> optionCorrespondent;
        switch(i) {
            case 0:
                optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
                break;
            case 1:
                optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
                break;
            case 2:
                optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
                break;
            default:
                throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (optionCorrespondent.isPresent()) {
            final Correspondent correspondent = optionCorrespondent.get();
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
            UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
        UsageModelFactory.connect(lastAction, loopStop);
        UsageModelFactory.connect(loop, stopBranchTransition);
    }
    return branch;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Branch(org.palladiosimulator.pcm.usagemodel.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent)

Example 9 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class PcmUsageModelBuilder method modelBranchScenarioBehavior.

/**
 * Creates for the passed branch a scenario behavior.
 *
 * @param branch
 *            whose behavior is created
 * @param indexOfUserGroup
 *            states to which user group the passed branch belongs
 */
private void modelBranchScenarioBehavior(final Branch branch, final int indexOfUserGroup) {
    final ScenarioBehaviour scenarioBehaviour = this.transformSequenceToScenarioBehavior(indexOfUserGroup, branch.getBranchSequence(), branch);
    this.branchScenarioBehavioursOfUserGroups.get(indexOfUserGroup).put(branch.getBranchId(), scenarioBehaviour);
}
Also used : ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)

Example 10 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour 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;
}
Also used : ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Branch(org.iobserve.analysis.userbehavior.data.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Aggregations

ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)21 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)12 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)10 Start (org.palladiosimulator.pcm.usagemodel.Start)10 Stop (org.palladiosimulator.pcm.usagemodel.Stop)10 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)10 Correspondent (org.iobserve.model.correspondence.Correspondent)9 Loop (org.palladiosimulator.pcm.usagemodel.Loop)9 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)8 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)8 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)7 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)7 ReferenceElements (org.iobserve.analysis.userbehavior.ReferenceElements)6 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)4 ArrayList (java.util.ArrayList)3 Branch (org.palladiosimulator.pcm.usagemodel.Branch)3 HashMap (java.util.HashMap)2 Branch (org.iobserve.analysis.userbehavior.data.Branch)2 List (java.util.List)1 UserSession (org.iobserve.analysis.session.data.UserSession)1