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;
}
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);
}
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;
}
}
Aggregations