Search in sources :

Example 1 with BranchTransitionElement

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

the class PcmUsageModelBuilder method createBranch.

/**
 * Creates for a branch a corresponding PCM branch including a corresponding usage scenario.
 *
 * @param scenarioBehaviour
 *            to that the PCM branch is added
 * @param branchElement
 *            that is transformed to a PCM branch element
 * @return a PCM branch element
 */
private org.palladiosimulator.pcm.usagemodel.Branch createBranch(final ScenarioBehaviour scenarioBehaviour, final BranchElement branchElement) {
    final org.palladiosimulator.pcm.usagemodel.Branch branchUM = UsageModelFactory.createBranch("", scenarioBehaviour);
    for (final BranchTransitionElement transition : branchElement.getBranchTransitions()) {
        final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branchUM);
        final ScenarioBehaviour branchScenarioBehaviour = this.transformSequenceToScenarioBehavior(0, transition.getBranchSequence(), null);
        branchTransition.setBranchedBehaviour_BranchTransition(branchScenarioBehaviour);
        branchTransition.setBranch_BranchTransition(branchUM);
        branchTransition.setBranchProbability(transition.getTransitionLikelihood());
    }
    return branchUM;
}
Also used : BranchTransitionElement(org.iobserve.analysis.behavior.karlsruhe.data.BranchTransitionElement) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Example 2 with BranchTransitionElement

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

the class LoopBranchModelCreator method doBranchElementsMatch.

/**
 * Checks whether two branch elements are equal.
 *
 * @param branchElement1
 *            is matched against element 2
 * @param branchElement2
 *            is matched against element 1
 * @return whether the two passed branch elements are equal
 */
private boolean doBranchElementsMatch(final BranchElement branchElement1, final BranchElement branchElement2) {
    if (branchElement1.getBranchTransitions().size() == branchElement2.getBranchTransitions().size()) {
        for (int i = 0; i < branchElement1.getBranchTransitions().size(); i++) {
            boolean matchFound = false;
            final BranchTransitionElement transition1 = branchElement1.getBranchTransitions().get(i);
            for (int j = 0; j < branchElement2.getBranchTransitions().size(); j++) {
                final BranchTransitionElement transition2 = branchElement2.getBranchTransitions().get(j);
                if (transition1.getTransitionLikelihood() != transition2.getTransitionLikelihood()) {
                    continue;
                } else if (!this.doSequencesMatch(transition1.getBranchSequence(), transition2.getBranchSequence())) {
                    continue;
                } else {
                    matchFound = true;
                    break;
                }
            }
            if (!matchFound) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : BranchTransitionElement(org.iobserve.analysis.behavior.karlsruhe.data.BranchTransitionElement)

Example 3 with BranchTransitionElement

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

BranchTransitionElement (org.iobserve.analysis.behavior.karlsruhe.data.BranchTransitionElement)3 ArrayList (java.util.ArrayList)1 Branch (org.iobserve.analysis.behavior.karlsruhe.data.Branch)1 BranchElement (org.iobserve.analysis.behavior.karlsruhe.data.BranchElement)1 ISequenceElement (org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement)1 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)1 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)1