Search in sources :

Example 1 with ISequenceElement

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

the class BranchModelCreator method setBranchSequence.

/**
 * Sets the passed events as branch sequence of the passed branch. The sequenceStartIndex
 * defines at which position of the passed events the branch sequence starts
 *
 * @param examinedBranch
 *            for that the branchSequence will be set
 * @param events
 *            represent the sequence to set
 * @param sequenceStartIndex
 *            states at which position of the passed events the branch sequence starts
 */
private void setBranchSequence(final Branch examinedBranch, final List<EntryCallEvent> events, final int sequenceStartIndex) {
    final List<ISequenceElement> branchSequence = new ArrayList<>();
    for (int j = sequenceStartIndex; j < events.size(); j++) {
        final EntryCallEvent callEvent = events.get(j);
        final CallElement callElement = new CallElement(callEvent.getClassSignature(), callEvent.getOperationSignature());
        callElement.setAbsoluteCount(1);
        branchSequence.add(callElement);
    }
    final ExitElement exitElement = new ExitElement();
    exitElement.setAbsoluteCount(1);
    branchSequence.add(exitElement);
    examinedBranch.setBranchSequence(branchSequence);
}
Also used : EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) CallElement(org.iobserve.analysis.userbehavior.data.CallElement) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement) ArrayList(java.util.ArrayList) ExitElement(org.iobserve.analysis.userbehavior.data.ExitElement)

Example 2 with ISequenceElement

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

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

the class LoopBranchModelCreator method determineLoopCount.

/**
 * Determines the loop count by checking how often the loop is iterated in a row.
 *
 * @param loopElement
 *            whose loopCount is determined
 * @param branchSequence
 *            within the loopCount is determined
 */
private void determineLoopCount(final LoopElement loopElement, final List<ISequenceElement> branchSequence) {
    int loopCount = 2;
    for (int i = loopElement.getEndIndexInBranchSequence(); i + loopElement.getLoopSequence().size() < branchSequence.size(); i = i + loopElement.getLoopSequence().size()) {
        boolean isAdditionalLoop = true;
        for (int j = 0; j < loopElement.getLoopSequence().size(); j++) {
            final ISequenceElement element1 = branchSequence.get(loopElement.getStartIndexInBranchSequence() + j);
            final ISequenceElement element2 = branchSequence.get(i + 1 + j);
            if (element1.getClass().equals(CallElement.class) && element2.getClass().equals(CallElement.class)) {
                if (!this.areSequenceElementsEqual(element1, element2)) {
                    isAdditionalLoop = false;
                    break;
                }
            } else if (element1.getClass().equals(BranchElement.class) && element2.getClass().equals(BranchElement.class)) {
                if (!this.areSequenceElementsEqual(element1, element2)) {
                    isAdditionalLoop = false;
                    break;
                }
            } else {
                isAdditionalLoop = false;
                break;
            }
        }
        if (isAdditionalLoop) {
            loopCount++;
        } else {
            break;
        }
    }
    loopElement.setLoopCount(loopCount);
    loopElement.setNumberOfReplacedElements(loopCount * loopElement.getLoopSequence().size());
    loopElement.setEndIndexInBranchSequence(loopElement.getStartIndexInBranchSequence() + loopElement.getNumberOfReplacedElements() - 1);
}
Also used : CallElement(org.iobserve.analysis.userbehavior.data.CallElement) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement)

Example 4 with ISequenceElement

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

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

the class LoopBranchModelCreator method doSequencesMatch.

/**
 * Checks whether two sequences are equal.
 *
 * @param sequence1
 *            is matched against sequence 2
 * @param sequence2
 *            is matched against sequence 1
 * @return whether the two passed sequences are equal
 */
private boolean doSequencesMatch(final List<ISequenceElement> sequence1, final List<ISequenceElement> sequence2) {
    if (sequence1.size() < sequence2.size()) {
        return false;
    }
    for (int i = 0; i < sequence2.size(); i++) {
        final ISequenceElement branchElementOfSequence1 = sequence1.get(i);
        final ISequenceElement branchElementOfSequence2 = sequence2.get(i);
        if (!branchElementOfSequence1.getClass().equals(branchElementOfSequence2.getClass())) {
            return false;
        }
        if (branchElementOfSequence1.getClass().equals(CallElement.class) && branchElementOfSequence2.getClass().equals(CallElement.class)) {
            if (!branchElementOfSequence1.getClassSignature().equals(branchElementOfSequence2.getClassSignature()) || !branchElementOfSequence1.getOperationSignature().equals(branchElementOfSequence2.getOperationSignature())) {
                return false;
            }
        } else if (branchElementOfSequence1.getClass().equals(LoopElement.class) && branchElementOfSequence2.getClass().equals(LoopElement.class)) {
            final LoopElement loopElement1 = (LoopElement) branchElementOfSequence1;
            final LoopElement loopElement2 = (LoopElement) branchElementOfSequence2;
            if (!this.doSequencesMatch(loopElement1.getLoopSequence(), loopElement2.getLoopSequence())) {
                return false;
            }
        }
    }
    return true;
}
Also used : LoopElement(org.iobserve.analysis.userbehavior.data.LoopElement) CallElement(org.iobserve.analysis.userbehavior.data.CallElement) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement)

Aggregations

ISequenceElement (org.iobserve.analysis.userbehavior.data.ISequenceElement)7 ArrayList (java.util.ArrayList)4 CallElement (org.iobserve.analysis.userbehavior.data.CallElement)4 Branch (org.iobserve.analysis.userbehavior.data.Branch)3 BranchElement (org.iobserve.analysis.userbehavior.data.BranchElement)3 LoopElement (org.iobserve.analysis.userbehavior.data.LoopElement)3 BranchTransitionElement (org.iobserve.analysis.userbehavior.data.BranchTransitionElement)1 ExitElement (org.iobserve.analysis.userbehavior.data.ExitElement)1 LoopBranchElement (org.iobserve.analysis.userbehavior.data.LoopBranchElement)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 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)1 Start (org.palladiosimulator.pcm.usagemodel.Start)1 Stop (org.palladiosimulator.pcm.usagemodel.Stop)1