Search in sources :

Example 1 with Loop

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

the class UsageModelProviderTest method createThenUpdateThenReadUpdated.

@Override
@Test
public void createThenUpdateThenReadUpdated() {
    final ModelProvider<UsageModel> modelProvider = new ModelProvider<>(UsageModelProviderTest.graph);
    final TestModelBuilder testModelBuilder = new TestModelBuilder();
    final UsageModel writtenModel = testModelBuilder.getUsageModel();
    final UsageModel readModel;
    final UsageScenario writtenUsageScenarioGroup0 = testModelBuilder.getUsageScenarioGroup0();
    final ScenarioBehaviour writtenBuyBookScenarioBehaviour = testModelBuilder.getBuyBookScenarioBehaviour();
    final EntryLevelSystemCall writtenGetQueryCall = testModelBuilder.getGetQueryCall();
    final EntryLevelSystemCall writtenGetPriceCall = testModelBuilder.getGetPriceCall();
    modelProvider.createComponent(writtenModel);
    // Update the model by adding a loop for choosing several books
    final Loop shoppingLoop = UsagemodelFactory.eINSTANCE.createLoop();
    final PCMRandomVariable loopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    final ScenarioBehaviour chooseBookBehaviour = UsagemodelFactory.eINSTANCE.createScenarioBehaviour();
    chooseBookBehaviour.setEntityName("Choose a book");
    chooseBookBehaviour.getActions_ScenarioBehaviour().add(writtenGetQueryCall);
    chooseBookBehaviour.getActions_ScenarioBehaviour().add(writtenGetPriceCall);
    writtenUsageScenarioGroup0.setEntityName("Updated " + writtenUsageScenarioGroup0.getEntityName());
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().remove(writtenGetQueryCall);
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().remove(writtenGetPriceCall);
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().add(shoppingLoop);
    writtenGetQueryCall.setScenarioBehaviour_AbstractUserAction(chooseBookBehaviour);
    writtenGetPriceCall.setScenarioBehaviour_AbstractUserAction(chooseBookBehaviour);
    shoppingLoop.setEntityName("Shopping loop");
    shoppingLoop.setScenarioBehaviour_AbstractUserAction(writtenBuyBookScenarioBehaviour);
    shoppingLoop.setBodyBehaviour_Loop(chooseBookBehaviour);
    shoppingLoop.setLoopIteration_Loop(loopIteration);
    loopIteration.setLoop_LoopIteration(shoppingLoop);
    loopIteration.setSpecification("2");
    modelProvider.updateComponent(UsageModel.class, writtenModel);
    readModel = modelProvider.readOnlyRootComponent(UsageModel.class);
    Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) Test(org.junit.Test)

Example 2 with Loop

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

the class UsageModelFactory method createLoop.

/**
 * Create loop in given parent {@link ScenarioBehaviour}. A {@link ScenarioBehaviour} is added
 * to the body of the loop, in order to make it possible adding further model elements.
 *
 * @param name
 *            name of loop
 * @param parent
 *            parent
 * @return created loop
 */
public static Loop createLoop(final String name, final ScenarioBehaviour parent) {
    // create the loop
    final Loop loop = UsagemodelFactory.eINSTANCE.createLoop();
    loop.setEntityName(name);
    parent.getActions_ScenarioBehaviour().add(loop);
    // create the body scenario behavior
    final ScenarioBehaviour bodyScenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    loop.setBodyBehaviour_Loop(bodyScenarioBehaviour);
    return loop;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)

Example 3 with Loop

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

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

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

the class TUsageModelToBehaviorModel method findLoopStart.

/**
 * Find first {@link EntryLevelSystemCall} element of a {@link Loop} body.
 *
 * @param loop
 *            loop
 * @return first found {@link EntryLevelSystemCall}, if found
 */
private Optional<EntryCallNode> findLoopStart(final AbstractUserAction action) {
    if (action instanceof Stop) {
        // LoopStart not found
        return Optional.empty();
    } else if (action instanceof EntryLevelSystemCall) {
        // found loop start
        final EntryLevelSystemCall entryLevelSystemCall = (EntryLevelSystemCall) action;
        final EntryCallNode entryCallNode = this.createEntryCallNode(entryLevelSystemCall);
        return Optional.of(entryCallNode);
    } else if (action instanceof Loop) {
        // search nested scenario
        final Loop loop = (Loop) action;
        final List<AbstractUserAction> userActions = loop.getBodyBehaviour_Loop().getActions_ScenarioBehaviour();
        if (userActions.size() > 0) {
            return this.findLoopStart(userActions.get(0));
        } else {
            return Optional.empty();
        }
    } else if (action instanceof Branch) {
        // will always found before
        return Optional.empty();
    } else {
        // next action
        return this.findLoopStart(action.getSuccessor());
    }
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallNode(org.iobserve.analysis.clustering.filter.models.EntryCallNode) Stop(org.palladiosimulator.pcm.usagemodel.Stop) Branch(org.palladiosimulator.pcm.usagemodel.Branch)

Aggregations

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