Search in sources :

Example 6 with ReferenceElements

use of org.iobserve.analysis.test.userbehavior.ReferenceElements 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 CorrespondenceModel 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 UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(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 : UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) 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) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements)

Example 7 with ReferenceElements

use of org.iobserve.analysis.test.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.

the class OverlappingIterationReference method getModel.

/**
 * Creates a reference model that contains a loop element. The user sessions contain iterated
 * call sequences that share overlapping calls. Thereby, one iterated sequence consists of more
 * calls than the other. Thus, it can be checked whether the approach transforms the iterated
 * call sequence that consists of more calls to a loop (RQ-1.4)
 *
 * @param referenceUsageModelFileName
 *            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 referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final CorrespondenceModel correspondenceModel) throws IOException {
    // Creates 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.
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
    // One of the iterated sequences is iterated twice and one is iterated three times. The
    // number of iterations is set randomly.
    final int loopCount1 = TestHelper.getRandomInteger(3, 2);
    final int lengthOfSequence1 = 2 * loopCount1;
    final int loopCount2;
    if (loopCount1 == 3) {
        loopCount2 = 2;
    } else {
        loopCount2 = 3;
    }
    final int lengthOfSequence2 = 2 * loopCount2;
    final ReferenceElements referenceElements = new ReferenceElements();
    final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    // In the following the reference usage model is created
    AbstractUserAction lastAction;
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
    final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
    final Start start = UsageModelFactory.createStart("");
    UsageModelFactory.addUserAction(scenarioBehaviour, start);
    final Stop stop = UsageModelFactory.createStop("");
    UsageModelFactory.addUserAction(scenarioBehaviour, stop);
    // According to the randomly set number of iterations the sequence that is iterated three
    // times is represented by a loop element. The other sequence is represented by a sequence
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    if (lengthOfSequence1 >= lengthOfSequence2) {
        UsageModelFactory.connect(start, loop);
        final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
        pcmLoopIteration.setSpecification(String.valueOf(loopCount1));
        // Set number of loops
        loop.setLoopIteration_Loop(pcmLoopIteration);
        final Start loopStart = UsageModelFactory.createStart("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
        final Stop loopStop = UsageModelFactory.createStop("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, loopStart, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
        UsageModelFactory.connect(lastAction, loopStop);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, loop, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
        UsageModelFactory.connect(lastAction, stop);
    } else {
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, start, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, lastAction, scenarioBehaviour);
        UsageModelFactory.connect(lastAction, loop);
        final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
        pcmLoopIteration.setSpecification(String.valueOf(loopCount2));
        // Set number of loops
        loop.setLoopIteration_Loop(pcmLoopIteration);
        final Start loopStart = UsageModelFactory.createStart("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
        final Stop loopStop = UsageModelFactory.createStop("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
        lastAction = loopStart;
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
        lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
        UsageModelFactory.connect(lastAction, loopStop);
        UsageModelFactory.connect(loop, stop);
    }
    OverlappingIterationReference.createMatchingEntryAndExitEvents(entryCallSequenceModel, lengthOfSequence1, lengthOfSequence2, loopCount1, loopCount2);
    // 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 : AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) Loop(org.palladiosimulator.pcm.usagemodel.Loop) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable)

Example 8 with ReferenceElements

use of org.iobserve.analysis.test.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.

the class SimpleLoopReferenceHelper method getModel.

/**
 * Creates a reference model that contains a loop element. Accordingly, user sessions whose call
 * sequences contain iterated calls are created.(RQ-1.3)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModelProvider
 *            repository model provider
 * @param correspondenceModel
 *            correspondence model
 *
 * @return the reference usage model and a corresponding EntryCallSequenceModel
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final CorrespondenceModel 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
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
    final int loopCount = TestHelper.getRandomInteger(5, 2);
    final int numberOfIteratedCalls = TestHelper.getRandomInteger(5, 1);
    final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    // In the following the reference usage model is created
    AbstractUserAction lastAction;
    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);
    // A loop is created and the loop count is set
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    UsageModelFactory.connect(start, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(loopCount));
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    // The EntryLevelSystemCalls that are iterated are added to the loop element
    final Start loopStart = UsageModelFactory.createAddStartAction("", loop.getBodyBehaviour_Loop());
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loop.getBodyBehaviour_Loop());
    lastAction = loopStart;
    // iterated calls to the loop
    for (int i = 0; i < numberOfIteratedCalls; i++) {
        if (i >= 0 && i < 5) {
            final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
            if (operationSignature != null) {
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, operationSignature);
                UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
    }
    UsageModelFactory.connect(lastAction, loopStop);
    // 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
    int entryTime = 1;
    int exitTime = 2;
    for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
        entryTime = 1;
        exitTime = 2;
        // number of iterated calls
        for (int k = 0; k < loopCount; k++) {
            for (int j = 0; j < numberOfIteratedCalls; j++) {
                EntryCallEvent entryCallEvent = null;
                if (j >= 0 && j < 5) {
                    entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[j], ReferenceUsageModelBuilder.CLASS_SIGNATURE[j], String.valueOf(i), "hostname");
                } else {
                    throw new IllegalArgumentException("Illegal value of model element parameter");
                }
                entryCallSequenceModel.getUserSessions().get(i).add(entryCallEvent, true);
                entryTime = entryTime + 2;
                exitTime = exitTime + 2;
            }
        }
    }
    // 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 : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements)

Example 9 with ReferenceElements

use of org.iobserve.analysis.test.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.

the class BranchWithinBranchReference method getModel.

/**
 * It creates a reference usage model that contains nested branches. Accordingly, user sessions
 * whose call sequences differ from each other at the positions of the branches are
 * created.(RQ-1.5)
 *
 * @param referenceUsageModelFileName
 *            file name of the reference model to store its result
 * @param usageModelBuilder
 *            usage model builder
 * @param repositoryLookupModel
 *            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 referenceUsageModelFileName, final UsageModelFactory usageModelBuilder, final RepositoryLookupModelProvider repositoryLookupModel, final CorrespondenceModel 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 numberOfTransitionsOfExteriorBranch = TestHelper.getRandomInteger(3, 2);
    final int numberOfTransitionsOfInteriorBranches = TestHelper.getRandomInteger(3, 2);
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 10 * numberOfTransitionsOfExteriorBranch);
    final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    final List<Integer> branchTransitionCounter = new ArrayList<>();
    final List<List<Integer>> listOfbranchTransitionCounterInterior = new ArrayList<>();
    BranchWithinBranchReference.createUserSessions(branchTransitionCounter, listOfbranchTransitionCounterInterior, numberOfTransitionsOfExteriorBranch, numberOfTransitionsOfInteriorBranches, entryCallSequenceModel);
    final UsageModel usageModel = BranchWithinBranchReference.createTheReferenceModel(usageModelBuilder, repositoryLookupModel, correspondenceModel, numberOfTransitionsOfExteriorBranch, numberOfTransitionsOfInteriorBranches, numberOfConcurrentUsers, branchTransitionCounter, listOfbranchTransitionCounterInterior);
    // 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 : UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) ArrayList(java.util.ArrayList) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ReferenceElements (org.iobserve.analysis.test.userbehavior.ReferenceElements)9 UserSessionCollectionModel (org.iobserve.analysis.data.UserSessionCollectionModel)8 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)7 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)6 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)6 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)5 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)5 Start (org.palladiosimulator.pcm.usagemodel.Start)5 Stop (org.palladiosimulator.pcm.usagemodel.Stop)5 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)4 OperationSignature (org.palladiosimulator.pcm.repository.OperationSignature)4 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)4 Loop (org.palladiosimulator.pcm.usagemodel.Loop)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 HashMap (java.util.HashMap)1 UserSession (org.iobserve.analysis.session.data.UserSession)1 Part (org.iobserve.model.correspondence.Part)1 Repository (org.palladiosimulator.pcm.repository.Repository)1 Branch (org.palladiosimulator.pcm.usagemodel.Branch)1