Search in sources :

Example 1 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.data.Branch 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.behavior.karlsruhe.data.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Example 2 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.data.Branch in project iobserve-analysis by research-iobserve.

the class BranchModelCreator method createCallBranchModel.

/**
 * It creates a BranchModel from an EntryCallSequenceModel. At that the single sequences are
 * aggregated to a tree-like structure: Equal sequences are summarized to one sequence,
 * alternative sequences are represented via branches.
 *
 * @param entryCallSequenceModel
 *            whose call sequences are aggregated to a coherent CallBranchModel
 * @return a BranchModel corresponding to the passed EntryCallSequenceModel
 */
public BranchModel createCallBranchModel(final UserSessionCollectionModel entryCallSequenceModel) {
    // Sets the user group's specific workload intensity and likelihood
    final BranchModel branchModel = new BranchModel(entryCallSequenceModel.getWorkloadIntensity(), entryCallSequenceModel.getLikelihoodOfUserGroup());
    final List<UserSession> userSessions = entryCallSequenceModel.getUserSessions();
    // The initial branch that contains the root node
    // Every sequence passes this branch -> likelihood of reaching this branch is 1
    final Branch rootBranch = new Branch();
    rootBranch.setBranchLikelihood(1);
    rootBranch.setBranchId(1);
    rootBranch.setTreeLevel(0);
    // Descending sort by call sequence length
    Collections.sort(userSessions, BranchModelCreator.SORT_USER_SESSION_BY_CALL_SEQUENCE_SIZE);
    // Initializes the root sequence with the longest call sequence
    this.setBranchSequence(rootBranch, userSessions.get(0).getEvents(), 0);
    int numberOfBranches = 1;
    // loops over all userSession without the first user session that initialized the rootBranch
    for (int j = 1; j < userSessions.size(); j++) {
        final UserSession userSession = userSessions.get(j);
        // The branchGuide guides through the tree structure. It determines the recent regarded
        // branch
        final List<Integer> branchGuide = new ArrayList<>();
        // The position states the recent position within the branch sequence
        int positionInBranch = 0;
        for (int i = 0; i <= userSession.getEvents().size(); i++) {
            // Determines which branch is currently examined
            final Branch examinedBranch = this.getExaminedBranch(branchGuide, rootBranch);
            if (i < userSession.getEvents().size()) {
                final EntryCallEvent callEvent = userSession.getEvents().get(i);
                // currently examined branch
                if (this.checkPositionMatchInBranch(callEvent, examinedBranch, positionInBranch)) {
                    this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
                    positionInBranch++;
                    continue;
                }
                // a child branch
                if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
                    final int indexOfMatchingChildBranch = this.getIndexOfMatchingChildBranch(callEvent, examinedBranch);
                    if (indexOfMatchingChildBranch > -1) {
                        // Continue with the same call event but switching to the new branch
                        branchGuide.add(indexOfMatchingChildBranch);
                        // NOCS
                        i--;
                        positionInBranch = 0;
                        continue;
                    }
                }
                // No match could be found --> Split branch into child branches
                numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, false, userSession, i);
                break;
            } else {
                // End of sequence -> looking for an exit element
                if (this.checkIfBranchSequenceTerminates(examinedBranch, positionInBranch)) {
                    this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
                    break;
                }
                // Checks if there is an exit branch
                if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
                    final int indexOfMatchingChildBranch = this.getIndexOfMatchingExitBranch(examinedBranch);
                    if (indexOfMatchingChildBranch > -1) {
                        // Iterate the exit state adding but switching to the new branch
                        branchGuide.add(indexOfMatchingChildBranch);
                        // NOCS
                        i--;
                        positionInBranch = 0;
                        continue;
                    }
                }
                // No matching exit element found --> Split branch into child branches
                numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, true, null, 0);
                break;
            }
        }
    }
    branchModel.setRootBranch(rootBranch);
    branchModel.setNumberOfBranches(numberOfBranches);
    return branchModel;
}
Also used : Branch(org.iobserve.analysis.behavior.karlsruhe.data.Branch) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList) BranchModel(org.iobserve.analysis.behavior.karlsruhe.data.BranchModel)

Example 3 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.data.Branch in project iobserve-analysis by research-iobserve.

the class BranchModelCreator method addNewBranch.

/**
 * Adds a new child branch to the passed branch. The branch id of the new branch is the current
 * number of branches.
 *
 * @param examinedBranch
 *            receives a new child branch
 * @param numberOfBranches
 *            is the current overall number of branches. Defines the id of the new added branch
 */
private void addNewBranch(final Branch examinedBranch, final int numberOfBranches) {
    final Branch childBranch = new Branch();
    childBranch.setBranchId(numberOfBranches + 1);
    examinedBranch.addBranch(childBranch);
}
Also used : Branch(org.iobserve.analysis.behavior.karlsruhe.data.Branch)

Example 4 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.data.Branch in project iobserve-analysis by research-iobserve.

the class BranchModelCreator method splitBranch.

// TODO This function is largely broken as it modifies input parameter.
/**
 * It creates a new branch and adds it to the current examined branch as a new child branch.
 *
 * @param examinedBranch
 *            that is splitted
 * @param positionInBranch
 *            states the recent regarded position in branch sequence
 * @param numberOfBranches
 *            is the recent amount of branches
 * @param isExit
 *            states if it is the end of a sequence
 * @param userSession
 *            if it is not the end of the sequence, the user session holds the rest of sequence
 *            that will be added to the new branch
 * @param indexOfCallEvent
 *            if it is not the end of the sequence, it states at which position in the sequence
 *            it is added to the new branch
 */
private // NOCS
int splitBranch(// NOCS
final Branch examinedBranch, // NOCS
final int positionInBranch, // NOCS
int numberOfBranches, // NOCS
final boolean isExit, final UserSession userSession, final int indexOfCallEvent) {
    // If there is already a split at that position add a new branch
    if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
        this.addNewBranch(examinedBranch, numberOfBranches);
        // NOCS
        numberOfBranches++;
    } else {
        // Else split the branch into two branches
        this.splitBranch(examinedBranch, positionInBranch, numberOfBranches);
        // NOCS
        numberOfBranches = numberOfBranches + 2;
    }
    final int indexOfNewAddedBranch = examinedBranch.getChildBranches().size() - 1;
    // NOCS
    final Branch childBranch = examinedBranch.getChildBranches().get(indexOfNewAddedBranch);
    // Adds an exit element to the new exit branch
    if (isExit) {
        this.setExitElement(childBranch);
    // Adds the branch sequence to the new branch
    } else {
        this.setBranchSequence(childBranch, userSession.getEvents(), indexOfCallEvent);
    }
    return numberOfBranches;
}
Also used : Branch(org.iobserve.analysis.behavior.karlsruhe.data.Branch)

Example 5 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.data.Branch in project iobserve-analysis by research-iobserve.

the class PcmUsageModelBuilder method transformSequenceToScenarioBehavior.

/**
 * Creates a scenario behavior corresponding to the passed sequence. The sequence can be a
 * branch sequence or a loop sequence. It creates a sequence of entry level system calls
 * including loops within the sequence. It sets the successors and predecessors.
 *
 * @param indexOfScenario
 *            states the index of the created scenario within the usage scenario
 * @param sequence
 *            that is transformed to a scenario behavior
 * @param branch
 *            contains the child branches of the branch whose behavior is created
 * @return the created scenario behavior
 */
private // NOCS
ScenarioBehaviour transformSequenceToScenarioBehavior(// NOCS
final int indexOfScenario, final List<ISequenceElement> sequence, final Branch branch) {
    final ScenarioBehaviour scenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    EntryLevelSystemCall lastESysCall = UsageModelFactory.createEmptyEntryLevelSystemCall();
    boolean isLastElementACall = false;
    Loop lastLoop = UsageModelFactory.createEmptyLoop();
    boolean isLastElementALoop = false;
    org.palladiosimulator.pcm.usagemodel.Branch lastLoopBranch = UsagemodelFactory.eINSTANCE.createBranch();
    boolean isLastElementALoopBranch = false;
    org.palladiosimulator.pcm.usagemodel.Branch lastBranch = UsagemodelFactory.eINSTANCE.createBranch();
    boolean isLastElementABranch = false;
    /**
     * Loops over all elements of the sequence and creates a corresponding scenario behavior by
     * connecting the elements via successor and predecessor connections.
     */
    for (final ISequenceElement branchElement : sequence) {
        // Element is a entryLevelSystemCall
        if (branchElement.getClass().equals(CallElement.class)) {
            EntryLevelSystemCall eSysCall = null;
            // Workaround TODO
            final String operationSignature = branchElement.getOperationSignature().replaceAll("\\(.*\\)", "()");
            final String[] operationSplit = operationSignature.split(" ");
            final OperationSignature modelOperationSignature = CorrespondenceUtility.findModelElementForOperation(this.correspondenceModel, Repository.class, branchElement.getClassSignature(), operationSplit[operationSplit.length - 1]);
            if (modelOperationSignature != null) {
                PcmUsageModelBuilder.LOGGER.debug("Usage: Found Correspondent: {}", modelOperationSignature.getEntityName());
                eSysCall = UsageModelFactory.createEntryLevelSystemCall(this.repositoryLookupModel, modelOperationSignature);
            }
            if (eSysCall != null) {
                if (isLastElementACall) {
                    UsageModelFactory.connect(lastESysCall, eSysCall);
                } else if (isLastElementALoop) {
                    UsageModelFactory.connect(lastLoop, eSysCall);
                } else if (isLastElementALoopBranch) {
                    UsageModelFactory.connect(lastLoopBranch, eSysCall);
                } else if (isLastElementABranch) {
                    UsageModelFactory.connect(lastBranch, eSysCall);
                } else {
                    UsageModelFactory.connect(start, eSysCall);
                }
                UsageModelFactory.addUserAction(scenarioBehaviour, eSysCall);
                lastESysCall = eSysCall;
                isLastElementACall = true;
                isLastElementALoop = false;
                isLastElementALoopBranch = false;
                isLastElementABranch = false;
            }
        } else if (branchElement.getClass().equals(LoopElement.class)) {
            // Element is a loop
            final Loop loop = this.createLoop(scenarioBehaviour, (LoopElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, loop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, loop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, loop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, loop);
            } else {
                UsageModelFactory.connect(start, loop);
            }
            lastLoop = loop;
            isLastElementALoop = true;
            isLastElementACall = false;
            isLastElementALoopBranch = false;
            isLastElementABranch = false;
        } else if (branchElement.getClass().equals(LoopBranchElement.class)) {
            // Element is a
            // looped Branch
            final org.palladiosimulator.pcm.usagemodel.Branch loopBranch = this.createLoopBranch(scenarioBehaviour, (LoopBranchElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, loopBranch);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, loopBranch);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, loopBranch);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, loopBranch);
            } else {
                UsageModelFactory.connect(start, loopBranch);
            }
            lastLoopBranch = loopBranch;
            isLastElementALoopBranch = true;
            isLastElementACall = false;
            isLastElementALoop = false;
            isLastElementABranch = false;
        } else if (branchElement.getClass().equals(BranchElement.class)) {
            // Element is a
            // Branch
            final org.palladiosimulator.pcm.usagemodel.Branch branchInter = this.createBranch(scenarioBehaviour, (BranchElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, branchInter);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, branchInter);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, branchInter);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, branchInter);
            } else {
                UsageModelFactory.connect(start, branchInter);
            }
            lastBranch = branchInter;
            isLastElementABranch = true;
            isLastElementALoopBranch = false;
            isLastElementACall = false;
            isLastElementALoop = false;
        } else {
            break;
        }
    }
    // checks if the branch got child branches
    if (branch == null) {
        if (isLastElementACall) {
            UsageModelFactory.connect(lastESysCall, stop);
        } else if (isLastElementALoop) {
            UsageModelFactory.connect(lastLoop, stop);
        } else if (isLastElementALoopBranch) {
            UsageModelFactory.connect(lastLoopBranch, stop);
        } else if (isLastElementABranch) {
            UsageModelFactory.connect(lastBranch, stop);
        } else {
            UsageModelFactory.connect(start, stop);
        }
    } else {
        final org.palladiosimulator.pcm.usagemodel.Branch branchUM = this.createChildBranch(scenarioBehaviour, indexOfScenario, branch);
        if (branchUM != null) {
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else {
                UsageModelFactory.connect(start, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            }
        } else {
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, stop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, stop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, stop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, stop);
            } else {
                UsageModelFactory.connect(start, stop);
            }
        }
    }
    return scenarioBehaviour;
}
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) ISequenceElement(org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement) LoopElement(org.iobserve.analysis.behavior.karlsruhe.data.LoopElement) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) Branch(org.iobserve.analysis.behavior.karlsruhe.data.Branch) LoopBranchElement(org.iobserve.analysis.behavior.karlsruhe.data.LoopBranchElement) BranchElement(org.iobserve.analysis.behavior.karlsruhe.data.BranchElement)

Aggregations

Branch (org.iobserve.analysis.behavior.karlsruhe.data.Branch)8 ArrayList (java.util.ArrayList)3 ISequenceElement (org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement)3 BranchElement (org.iobserve.analysis.behavior.karlsruhe.data.BranchElement)2 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)2 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)2 BranchModel (org.iobserve.analysis.behavior.karlsruhe.data.BranchModel)1 BranchTransitionElement (org.iobserve.analysis.behavior.karlsruhe.data.BranchTransitionElement)1 LoopBranchElement (org.iobserve.analysis.behavior.karlsruhe.data.LoopBranchElement)1 LoopElement (org.iobserve.analysis.behavior.karlsruhe.data.LoopElement)1 UserSession (org.iobserve.analysis.session.data.UserSession)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)1 OperationSignature (org.palladiosimulator.pcm.repository.OperationSignature)1 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)1 Loop (org.palladiosimulator.pcm.usagemodel.Loop)1 Start (org.palladiosimulator.pcm.usagemodel.Start)1 Stop (org.palladiosimulator.pcm.usagemodel.Stop)1