Search in sources :

Example 1 with BranchTransition

use of org.palladiosimulator.pcm.usagemodel.BranchTransition 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 2 with BranchTransition

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 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 3 with BranchTransition

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

Example 4 with BranchTransition

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;
}
Also used : EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) ArrayList(java.util.ArrayList) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Example 5 with BranchTransition

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

the class UserBehaviorEvaluation method getModelElements.

/**
 * Extracts for a scenario behavior the model elements.
 *
 * @param scenarioBehaviour
 *            whose model elements are extracted
 * @param modelElements
 *            the list to that the model elements are added
 */
private static void getModelElements(final ScenarioBehaviour scenarioBehaviour, final List<ModelElement> modelElements) {
    final List<AbstractUserAction> actionsOfScenarioBehaviour = scenarioBehaviour.getActions_ScenarioBehaviour();
    AbstractUserAction nextActionOfScenarioBehaviour = actionsOfScenarioBehaviour.get(0);
    // element
    while (nextActionOfScenarioBehaviour != null) {
        if (nextActionOfScenarioBehaviour.getClass().equals(StartImpl.class)) {
            final ModelElement modelElement = new ModelElement(true, false, false, false, false, "", "", 0);
            modelElements.add(modelElement);
        } else if (nextActionOfScenarioBehaviour.getClass().equals(StopImpl.class)) {
            final ModelElement modelElement = new ModelElement(false, true, false, false, false, "", "", 0);
            modelElements.add(modelElement);
        } else if (nextActionOfScenarioBehaviour.getClass().equals(EntryLevelSystemCallImpl.class)) {
            final EntryLevelSystemCall call = (EntryLevelSystemCall) nextActionOfScenarioBehaviour;
            final ModelElement modelElement = new ModelElement(false, false, true, false, false, call.getEntityName(), "", 0);
            modelElements.add(modelElement);
        } else if (nextActionOfScenarioBehaviour.getClass().equals(LoopImpl.class)) {
            final Loop loop = (Loop) nextActionOfScenarioBehaviour;
            final ModelElement modelElement = new ModelElement(false, false, false, false, true, "", loop.getLoopIteration_Loop().getSpecification(), 0);
            modelElements.add(modelElement);
            UserBehaviorEvaluation.getModelElements(loop.getBodyBehaviour_Loop(), modelElements);
        } else if (nextActionOfScenarioBehaviour.getClass().equals(BranchImpl.class)) {
            final Branch branch = (Branch) nextActionOfScenarioBehaviour;
            // Because the branch transitions of the usage models are not always in the same
            // order, we order the branch transitions by the entity name of their first
            // EntryLevelSystemCall. In doing so, the model elements of each usage model are
            // added in the same order independently of the ordering of the usage model. The
            // ordering of the branch transitions does not affect the accuracy of an usage model
            // and is created randomly within the usage model and can not be influenced.
            final List<BranchTransition> branchTransitionsSorted = UserBehaviorEvaluation.sortBranchTransitions(branch.getBranchTransitions_Branch());
            for (int i = 0; i < branchTransitionsSorted.size(); i++) {
                final ModelElement modelElement = new ModelElement(false, false, false, true, false, "", "", branchTransitionsSorted.get(i).getBranchProbability());
                modelElements.add(modelElement);
                UserBehaviorEvaluation.getModelElements(branchTransitionsSorted.get(i).getBranchedBehaviour_BranchTransition(), modelElements);
            }
        }
        // Gets the successor model element
        nextActionOfScenarioBehaviour = nextActionOfScenarioBehaviour.getSuccessor();
    }
}
Also used : AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) LoopImpl(org.palladiosimulator.pcm.usagemodel.impl.LoopImpl) Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Branch(org.palladiosimulator.pcm.usagemodel.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) StopImpl(org.palladiosimulator.pcm.usagemodel.impl.StopImpl)

Aggregations

BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)23 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)17 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)16 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)12 Start (org.palladiosimulator.pcm.usagemodel.Start)12 Stop (org.palladiosimulator.pcm.usagemodel.Stop)12 Branch (org.palladiosimulator.pcm.usagemodel.Branch)8 Loop (org.palladiosimulator.pcm.usagemodel.Loop)8 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)8 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)8 Correspondent (org.iobserve.model.correspondence.Correspondent)5 OperationSignature (org.palladiosimulator.pcm.repository.OperationSignature)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)4 Map (java.util.Map)2 Optional (java.util.Optional)2 Branch (org.iobserve.analysis.behavior.karlsruhe.data.Branch)2 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)2