Search in sources :

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

Example 17 with BranchTransition

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

Example 18 with BranchTransition

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

Example 19 with BranchTransition

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);
}
Also used : BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel) 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) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) Map(java.util.Map) Optional(java.util.Optional) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) 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.behavior.models.extended.EntryCallNode) HashMap(java.util.HashMap) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 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.behavior.karlsruhe.data.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

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