Search in sources :

Example 6 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)

Example 7 with BranchTransition

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

the class TUsageModelToBehaviorModel 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
    final Map<EntryCallNode, Double> endNodes = 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);
    return endNodes;
}
Also used : SingleOrNoneCollector(org.iobserve.analysis.clustering.SingleOrNoneCollector) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) HashMap(java.util.HashMap) OutputPort(teetime.framework.OutputPort) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) List(java.util.List) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) Map(java.util.Map) BehaviorModel(org.iobserve.analysis.clustering.filter.models.BehaviorModel) EntryCallEdge(org.iobserve.analysis.clustering.filter.models.EntryCallEdge) Optional(java.util.Optional) EntryCallNode(org.iobserve.analysis.clustering.filter.models.EntryCallNode) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Branch(org.palladiosimulator.pcm.usagemodel.Branch) Start(org.palladiosimulator.pcm.usagemodel.Start) Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallNode(org.iobserve.analysis.clustering.filter.models.EntryCallNode) HashMap(java.util.HashMap) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with BranchTransition

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

the class BranchWithinBranchReference method createTheReferenceModel.

/**
 * Creates the reference model.
 *
 * @param usageModelBuilder
 * @param repositoryLookupModel
 * @param correspondenceModel
 * @param numberOfTransitionsOfExteriorBranch
 * @param numberOfTransitionsOfInteriorBranches
 * @param numberOfConcurrentUsers
 * @param branchTransitionCounter
 * @param listOfbranchTransitionCounterInterior
 * @return
 */
private static UsageModel createTheReferenceModel(final UsageModelFactory usageModelBuilder, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel, final int numberOfTransitionsOfExteriorBranch, final int numberOfTransitionsOfInteriorBranches, final int numberOfConcurrentUsers, final List<Integer> branchTransitionCounter, final List<List<Integer>> listOfbranchTransitionCounterInterior) {
    // In the following the reference usage model is created
    AbstractUserAction lastAction;
    Optional<Correspondent> optionCorrespondent;
    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);
    lastAction = start;
    // The exterior branch is created
    final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
    UsageModelFactory.connect(lastAction, branch);
    UsageModelFactory.connect(branch, stop);
    // Creates branch transitions according to the random countOfBranchTransitions
    for (int i = 0; i < numberOfTransitionsOfExteriorBranch; i++) {
        final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
        final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
        branchTransition.setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
        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) {
            optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (optionCorrespondent.isPresent()) {
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, optionCorrespondent.get());
            UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
        // The interior branch is created
        final org.palladiosimulator.pcm.usagemodel.Branch branchInterior = UsageModelFactory.createBranch("", branchTransitionBehaviour);
        UsageModelFactory.connect(lastAction, branchInterior);
        UsageModelFactory.connect(branchInterior, stopBranchTransition);
        for (int j = 0; j < numberOfTransitionsOfInteriorBranches; j++) {
            final BranchTransition branchTransitionInterior = UsageModelFactory.createBranchTransition(branchInterior);
            final ScenarioBehaviour branchTransitionBehaviourInterior = branchTransitionInterior.getBranchedBehaviour_BranchTransition();
            branchTransitionInterior.setBranchProbability((double) listOfbranchTransitionCounterInterior.get(i).get(j) / (double) branchTransitionCounter.get(i));
            final Start startBranchTransitionInterior = UsageModelFactory.createAddStartAction("", branchTransitionBehaviourInterior);
            final Stop stopBranchTransitionInterior = UsageModelFactory.createAddStopAction("", branchTransitionBehaviourInterior);
            lastAction = startBranchTransitionInterior;
            optionCorrespondent = BranchWithinBranchReference.getOptionCorrespondent(correspondenceModel, j);
            if (optionCorrespondent.isPresent()) {
                final Correspondent correspondent = optionCorrespondent.get();
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
                UsageModelFactory.addUserAction(branchTransitionBehaviourInterior, entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
            UsageModelFactory.connect(lastAction, stopBranchTransitionInterior);
        }
    }
    return usageModel;
}
Also used : EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent)

Example 9 with BranchTransition

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

the class BranchWithinLoopReference method getModel.

/**
 * It creates a reference usage model that contains branches within loops. Accordingly, user
 * sessions whose call sequences differ from each other are iterated in a row. Thereby, at each
 * iteration of a branched call sequences the probabilities have to be equal because otherwise
 * it would not be an iteration (RQ-1.8)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModel
 *            repository model builder
 * @param correspondenceModel
 *            correspondence model
 *
 * @return reference usage model and corresponding user sessions
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel) throws IOException {
    // The number of model element parameters are created randomly. The number of user sessions
    // must be created accordingly to the number of branch transitions, because it must be
    // ensured that at each iteration of an branch the branch transition probabilities are
    // equal. This can be achieved by the same number of user sessions representing the branch
    // transition at each iteration
    final int numberOfLoops = TestHelper.getRandomInteger(3, 3);
    final int numberOfConcurrentUsers = (int) Math.pow(2, numberOfLoops) * 5;
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements testElements = 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();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    final AbstractUserAction lastAction = start;
    // The loop element is created that contains the iterated branch
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    final ScenarioBehaviour loopScenarioBehaviour = loop.getBodyBehaviour_Loop();
    UsageModelFactory.connect(lastAction, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(numberOfLoops));
    // Set number of loops
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    final Start loopStart = UsageModelFactory.createAddStartAction("", loopScenarioBehaviour);
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loopScenarioBehaviour);
    // The branch that is contained within the loop element is created
    final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", loopScenarioBehaviour);
    UsageModelFactory.connect(loopStart, branch);
    // The branch transition 1 is created
    final BranchTransition branchTransition1 = BranchWithinLoopReference.createBranchTransition(2, repositoryLookupModel, branch, correspondenceModel);
    // The branch transition 2 is created
    final BranchTransition branchTransition2 = BranchWithinLoopReference.createBranchTransition(3, repositoryLookupModel, branch, correspondenceModel);
    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(loopScenarioBehaviour, entryLevelSystemCall);
        UsageModelFactory.connect(branch, entryLevelSystemCall);
        UsageModelFactory.connect(entryLevelSystemCall, loopStop);
    }
    // User sessions according to the reference usage model are created. Thereby, it must be
    // ensured that each iteration of the branch the branch probabilities stay the same because
    // the branch is iterated. This can be achieved by an equal number of user sessions for each
    // branch transition at each iteration of the branch
    int countOfCallEvent3 = 0;
    int countOfCallEvent4 = 0;
    int entryTime = 1;
    int exitTime = 2;
    boolean branchDecision = false;
    // At each iteration the user sessions are distributed equally between the branch
    // transitions to ensure that the probabilities of the branch transitions stay equally
    final Map<Integer, List<List<UserSession>>> userSessionGroups = new HashMap<>();
    final List<List<UserSession>> startList = new ArrayList<>();
    startList.add(entryCallSequenceModel.getUserSessions());
    userSessionGroups.put(0, startList);
    // The loop that contains the branch
    for (int j = 0; j < numberOfLoops; j++) {
        countOfCallEvent3 = 0;
        countOfCallEvent4 = 0;
        final List<List<UserSession>> newUserSessionGroups = new ArrayList<>();
        // Ensures that the user sessions distribution stays equally
        for (int k = 0; k < userSessionGroups.get(j).size(); k++) {
            for (int i = 0; i < 2; i++) {
                final List<UserSession> userSessions = new ArrayList<>();
                newUserSessionGroups.add(userSessions);
            }
            final int indexGroupCallEvent3 = newUserSessionGroups.size() - 2;
            final int indexGroupCallEvent4 = newUserSessionGroups.size() - 1;
            for (int i = 0; i < userSessionGroups.get(j).get(k).size(); i++) {
                if (newUserSessionGroups.get(indexGroupCallEvent3).size() > newUserSessionGroups.get(indexGroupCallEvent4).size()) {
                    branchDecision = false;
                } else {
                    branchDecision = true;
                }
                // The branch within the loop
                if (branchDecision) {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 2, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent3);
                    countOfCallEvent3++;
                    entryTime += 2;
                    exitTime += 2;
                } else {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 3, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent4);
                    countOfCallEvent4++;
                    entryTime += 2;
                    exitTime += 2;
                }
                final EntryCallEvent entryCallEvent5 = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4], ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], String.valueOf(i), "hostname");
                userSessionGroups.get(j).get(k).get(i).add(entryCallEvent5, true);
                entryTime -= 2;
                exitTime -= 2;
            }
        }
        userSessionGroups.put(j + 1, newUserSessionGroups);
        entryTime += 2;
        exitTime += 2;
    }
    // Sets the likelihoods of branch transitions
    final double likelihoodOfCallEvent3 = (double) countOfCallEvent3 / (double) numberOfConcurrentUsers;
    final double likelihoodOfCallEvent4 = (double) countOfCallEvent4 / (double) numberOfConcurrentUsers;
    branchTransition1.setBranchProbability(likelihoodOfCallEvent3);
    branchTransition2.setBranchProbability(likelihoodOfCallEvent4);
    // 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);
    testElements.setEntryCallSequenceModel(entryCallSequenceModel);
    testElements.setUsageModel(usageModel);
    return testElements;
}
Also used : Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UserSession(org.iobserve.analysis.session.data.UserSession) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements) ArrayList(java.util.ArrayList) List(java.util.List) Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent)

Example 10 with BranchTransition

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);
}
Also used : EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent) Branch(org.palladiosimulator.pcm.usagemodel.Branch)

Aggregations

BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)12 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)9 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)8 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)6 Start (org.palladiosimulator.pcm.usagemodel.Start)6 Stop (org.palladiosimulator.pcm.usagemodel.Stop)6 Correspondent (org.iobserve.model.correspondence.Correspondent)5 Branch (org.palladiosimulator.pcm.usagemodel.Branch)4 Loop (org.palladiosimulator.pcm.usagemodel.Loop)4 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)4 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)2 Branch (org.iobserve.analysis.userbehavior.data.Branch)2 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)2 Map (java.util.Map)1 Optional (java.util.Optional)1 SingleOrNoneCollector (org.iobserve.analysis.clustering.SingleOrNoneCollector)1