Search in sources :

Example 1 with Branch

use of org.iobserve.analysis.userbehavior.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.userbehavior.data.Branch)

Example 2 with Branch

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

the class BranchModelCreator method mergeBranches.

/**
 * Merges branches.
 *
 * @param branch
 *            whose child branches are merged
 * @param doChildBranchesExist
 * @return
 */
private boolean mergeBranches(final Branch branch, final boolean doChildBranchesExist) {
    int indexOfEqualElements = 0;
    boolean isElementEqual = false;
    // their sequences
    for (int i = branch.getChildBranches().get(0).getBranchSequence().size() - 1; i >= 0; i--) {
        final ISequenceElement branchElement = branch.getChildBranches().get(0).getBranchSequence().get(i);
        isElementEqual = false;
        for (final Branch childBranch : branch.getChildBranches()) {
            if (childBranch.getBranchSequence().size() - 1 - indexOfEqualElements < 0) {
                isElementEqual = false;
                break;
            } else if (this.doBranchElementsMatch(branchElement, childBranch.getBranchSequence().get(childBranch.getBranchSequence().size() - 1 - indexOfEqualElements))) {
                isElementEqual = true;
            } else {
                isElementEqual = false;
                break;
            }
        }
        if (!isElementEqual) {
            break;
        }
        indexOfEqualElements++;
    }
    // Creates a new branch element that replaces the child branches that are merged
    final BranchElement branchElement = new BranchElement();
    final List<ISequenceElement> sequenceToAddToBranch = new ArrayList<>();
    for (int i = 0; i < indexOfEqualElements; i++) {
        sequenceToAddToBranch.add(0, branch.getChildBranches().get(0).getBranchSequence().get(branch.getChildBranches().get(0).getBranchSequence().size() - 1));
        for (final Branch childBranch : branch.getChildBranches()) {
            childBranch.getBranchSequence().remove(childBranch.getBranchSequence().size() - 1);
        }
    }
    for (final Branch childBranch : branch.getChildBranches()) {
        final BranchTransitionElement branchTransition = new BranchTransitionElement();
        branchTransition.setBranchSequence(childBranch.getBranchSequence());
        branchTransition.setTransitionLikelihood(childBranch.getBranchLikelihood());
        branchElement.addBranchTransition(branchTransition);
    }
    branch.getBranchSequence().add(branchElement);
    branch.getBranchSequence().addAll(sequenceToAddToBranch);
    // Removes the replaced child branches
    if (doChildBranchesExist) {
        final List<Branch> newChildBranches = branch.getChildBranches().get(0).getChildBranches();
        branch.getChildBranches().clear();
        branch.setChildBranches(newChildBranches);
    } else {
        branch.getChildBranches().clear();
    }
    if (doChildBranchesExist || indexOfEqualElements > 0) {
        this.fusionPerformed = true;
        return true;
    } else {
        return false;
    }
}
Also used : BranchTransitionElement(org.iobserve.analysis.userbehavior.data.BranchTransitionElement) Branch(org.iobserve.analysis.userbehavior.data.Branch) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement) ArrayList(java.util.ArrayList) BranchElement(org.iobserve.analysis.userbehavior.data.BranchElement)

Example 3 with Branch

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

Example 4 with Branch

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

the class BranchModelCreator method splitBranch.

/**
 * It splits the passed branch at the passed position of its branch sequence into two child
 * branches. The branch sequence of the passed branch is shorted to the position the split is
 * performed. The first child branch receives the remaining branch sequence, starting at the
 * position the split is performed. The second child branch´s sequence stays empty and is filled
 * later
 *
 * @param examinedBranch
 *            is split into two branches
 * @param positionInBranch
 *            is the position in the branch sequence where the split is performed
 * @param numberOfBranches
 *            is the current overall number of branches. Defines the new branch ids
 */
private void splitBranch(final Branch examinedBranch, final int positionInBranch, final int numberOfBranches) {
    final Branch childBranch1 = new Branch();
    final Branch childBranch2 = new Branch();
    final List<ISequenceElement> branchSequence = new ArrayList<>(examinedBranch.getBranchSequence().subList(0, positionInBranch));
    final List<ISequenceElement> branchSequence1 = new ArrayList<>(examinedBranch.getBranchSequence().subList(positionInBranch, examinedBranch.getBranchSequence().size()));
    final List<ISequenceElement> branchSequence2 = new ArrayList<>();
    examinedBranch.setBranchSequence(branchSequence);
    childBranch1.setBranchSequence(branchSequence1);
    childBranch2.setBranchSequence(branchSequence2);
    childBranch1.setBranchId(numberOfBranches + 1);
    childBranch2.setBranchId(numberOfBranches + 2);
    for (final Branch childBranch : examinedBranch.getChildBranches()) {
        childBranch1.addBranch(childBranch);
    }
    examinedBranch.getChildBranches().clear();
    examinedBranch.addBranch(childBranch1);
    examinedBranch.addBranch(childBranch2);
}
Also used : Branch(org.iobserve.analysis.userbehavior.data.Branch) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement) ArrayList(java.util.ArrayList)

Example 5 with Branch

use of org.iobserve.analysis.userbehavior.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 EntryCallSequenceModel 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.userbehavior.data.Branch) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList) BranchModel(org.iobserve.analysis.userbehavior.data.BranchModel)

Aggregations

Branch (org.iobserve.analysis.userbehavior.data.Branch)7 ArrayList (java.util.ArrayList)3 ISequenceElement (org.iobserve.analysis.userbehavior.data.ISequenceElement)3 BranchElement (org.iobserve.analysis.userbehavior.data.BranchElement)2 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)2 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)2 UserSession (org.iobserve.analysis.session.data.UserSession)1 BranchModel (org.iobserve.analysis.userbehavior.data.BranchModel)1 BranchTransitionElement (org.iobserve.analysis.userbehavior.data.BranchTransitionElement)1 LoopBranchElement (org.iobserve.analysis.userbehavior.data.LoopBranchElement)1 LoopElement (org.iobserve.analysis.userbehavior.data.LoopElement)1 Correspondent (org.iobserve.model.correspondence.Correspondent)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)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