Search in sources :

Example 6 with ISequenceElement

use of org.iobserve.analysis.behavior.karlsruhe.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.behavior.karlsruhe.data.BranchTransitionElement) Branch(org.iobserve.analysis.behavior.karlsruhe.data.Branch) ISequenceElement(org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement) ArrayList(java.util.ArrayList) BranchElement(org.iobserve.analysis.behavior.karlsruhe.data.BranchElement)

Example 7 with ISequenceElement

use of org.iobserve.analysis.behavior.karlsruhe.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.behavior.karlsruhe.data.CallElement) ISequenceElement(org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement) ArrayList(java.util.ArrayList) ExitElement(org.iobserve.analysis.behavior.karlsruhe.data.ExitElement)

Aggregations

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