Search in sources :

Example 6 with Branch

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

Example 7 with Branch

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

Example 8 with Branch

use of org.iobserve.analysis.behavior.karlsruhe.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.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)

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