Search in sources :

Example 1 with LoopElement

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

the class LoopBranchModelCreator method filterLoops.

/**
 * Checks if there are overlaps between the passed loops, i.e. if more than one loop uses the
 * same call element. If it detects an overlap it filters the loop out that replaces less call
 * elements
 *
 * @param loopElements
 */
private void filterLoops(final List<LoopElement> loopElements) {
    for (int i = 0; i < loopElements.size(); i++) {
        for (int j = i + 1; j < loopElements.size(); j++) {
            final LoopElement loopElement1 = loopElements.get(i);
            final LoopElement loopElement2 = loopElements.get(j);
            // Checks if there is an overlap between two loops
            if (loopElement1.getStartIndexInBranchSequence() >= loopElement2.getStartIndexInBranchSequence() && loopElement1.getStartIndexInBranchSequence() <= loopElement2.getEndIndexInBranchSequence() || loopElement1.getEndIndexInBranchSequence() >= loopElement2.getStartIndexInBranchSequence() && loopElement1.getEndIndexInBranchSequence() <= loopElement2.getEndIndexInBranchSequence() || loopElement2.getStartIndexInBranchSequence() >= loopElement1.getStartIndexInBranchSequence() && loopElement2.getStartIndexInBranchSequence() <= loopElement1.getEndIndexInBranchSequence() || loopElement2.getEndIndexInBranchSequence() >= loopElement1.getStartIndexInBranchSequence() && loopElement2.getEndIndexInBranchSequence() <= loopElement1.getEndIndexInBranchSequence()) {
                // Returns the removed loop
                final boolean loop1Weaker = this.removeTheWeakerLoop(loopElements, loopElement1, loopElement2, i, j);
                // Iterate loop considering the removing
                if (loop1Weaker) {
                    // NOCS
                    i--;
                    break;
                } else {
                    // NOCS
                    j--;
                }
            }
        }
    }
}
Also used : LoopElement(org.iobserve.analysis.userbehavior.data.LoopElement)

Example 2 with LoopElement

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

Example 3 with LoopElement

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

the class LoopBranchModelCreator method insertLoopsIntoBranch.

/**
 * Inserts the passed loops into the branch sequence and removes the call elements that are.
 * replaced by the loops
 *
 * @param loopElements
 *            are the loops that are inserted into the branch sequence
 * @param branch
 *            receives the loops within its branch sequence
 */
private void insertLoopsIntoBranch(final List<LoopElement> loopElements, final List<ISequenceElement> branchSequence) {
    Collections.sort(loopElements, new Comparator<LoopElement>() {

        @Override
        public int compare(final LoopElement e1, final LoopElement e2) {
            final int index1 = e1.getStartIndexInBranchSequence();
            final int index2 = e2.getStartIndexInBranchSequence();
            if (index1 > index2) {
                return 1;
            } else if (index1 < index2) {
                return -1;
            }
            return 0;
        }
    });
    for (int i = 0; i < loopElements.size(); i++) {
        final LoopElement loopElement = loopElements.get(i);
        loopElement.setStartIndexInBranchSequence(loopElement.getStartIndexInBranchSequence() + i);
        loopElement.setEndIndexInBranchSequence(loopElement.getStartIndexInBranchSequence() + 1);
        branchSequence.add(loopElement.getStartIndexInBranchSequence(), loopElement);
    }
    int countOfRemovedElementsFromLoopsBefore = 0;
    for (final LoopElement loopElement : loopElements) {
        for (int i = 0; i < loopElement.getNumberOfReplacedElements(); i++) {
            final int indexToRemove = loopElement.getStartIndexInBranchSequence() + 1 - countOfRemovedElementsFromLoopsBefore;
            branchSequence.remove(indexToRemove);
        }
        countOfRemovedElementsFromLoopsBefore += loopElement.getNumberOfReplacedElements();
    }
}
Also used : LoopElement(org.iobserve.analysis.userbehavior.data.LoopElement)

Example 4 with LoopElement

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

the class LoopBranchModelCreator method detectLoopsWithinBranchSequence.

/**
 * Detects loops within a branch sequence 1. Finds all iterated segments within the given
 * sequence 2. For each obtained segment the loop count is determined 3. The loops are examined
 * if they overlap If there is an overlap between two loops, the loop that replaces less
 * sequence elements is filtered out 4. The loop elements are inserted into the sequence
 * Iterates until no new loops are found
 *
 * @param branchSequence
 *            that is examined for iterated behavior
 */
private void detectLoopsWithinBranchSequence(final List<ISequenceElement> branchSequence) {
    if (branchSequence.size() > 1) {
        final List<LoopElement> loopElements = new ArrayList<>();
        loopElements.clear();
        // The exit element of a sequence is not considered for the loop detection
        int branchSequenceSizeWithoutExitElement = branchSequence.size();
        if (branchSequence.get(branchSequence.size() - 1).getClass().equals(ExitElement.class)) {
            branchSequenceSizeWithoutExitElement = branchSequenceSizeWithoutExitElement - 1;
        }
        if (branchSequence != null && branchSequenceSizeWithoutExitElement > 0) {
            for (int indexOfElementInElementList = 0; indexOfElementInElementList < branchSequenceSizeWithoutExitElement; indexOfElementInElementList++) {
                // sequences of the branches
                if (branchSequence.get(indexOfElementInElementList).getClass().equals(BranchElement.class)) {
                    final BranchElement loopi = (BranchElement) branchSequence.get(indexOfElementInElementList);
                    for (int i = 0; i < loopi.getBranchTransitions().size(); i++) {
                        this.detectLoopsWithinBranchSequence(loopi.getBranchTransitions().get(i).getBranchSequence());
                    }
                }
                // If a loop is detected it is memorized
                for (int i = 0; i < (branchSequenceSizeWithoutExitElement - indexOfElementInElementList) / 2; i++) {
                    final int elementsToCheck = (branchSequenceSizeWithoutExitElement - indexOfElementInElementList) / 2 - i;
                    boolean isALoop = true;
                    final LoopElement loopElement = new LoopElement();
                    for (int k = 0; k < elementsToCheck; k++) {
                        final ISequenceElement element1 = branchSequence.get(indexOfElementInElementList + k);
                        final ISequenceElement element2 = branchSequence.get(indexOfElementInElementList + elementsToCheck + k);
                        if (element1.getClass().equals(CallElement.class) && element2.getClass().equals(CallElement.class)) {
                            if (!this.areSequenceElementsEqual(element1, element2)) {
                                isALoop = false;
                                break;
                            }
                        } else if (element1.getClass().equals(BranchElement.class) && element2.getClass().equals(BranchElement.class)) {
                            if (!this.areSequenceElementsEqual(element1, element2)) {
                                isALoop = false;
                                break;
                            }
                        } else {
                            isALoop = false;
                            break;
                        }
                        loopElement.addElementToLoopSequence(branchSequence.get(indexOfElementInElementList + k));
                    }
                    if (isALoop) {
                        loopElement.setStartIndexInBranchSequence(indexOfElementInElementList);
                        loopElement.setEndIndexInBranchSequence(indexOfElementInElementList + elementsToCheck + elementsToCheck - 1);
                        // Determines the number of loops for each loop
                        this.determineLoopCount(loopElement, branchSequence);
                        loopElements.add(loopElement);
                    }
                }
            }
            if (loopElements.size() > 0) {
                // Filters the loops from overlapping loops
                this.filterLoops(loopElements);
                // Find Loops within the loops
                for (final LoopElement loopElement : loopElements) {
                    this.detectLoopsWithinBranchSequence(loopElement.getLoopSequence());
                }
                // Inserts the loops into the branch
                this.insertLoopsIntoBranch(loopElements, branchSequence);
            }
        }
    }
}
Also used : LoopElement(org.iobserve.analysis.userbehavior.data.LoopElement) CallElement(org.iobserve.analysis.userbehavior.data.CallElement) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement) ArrayList(java.util.ArrayList) BranchElement(org.iobserve.analysis.userbehavior.data.BranchElement)

Example 5 with LoopElement

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

the class PcmUsageModelBuilder method transformSequenceToScenarioBehavior.

/**
 * Creates a scenario behavior corresponding to the passed sequence. The sequence can be a
 * branch sequence or a loop sequence. It creates a sequence of entry level system calls
 * including loops within the sequence. It sets the successors and predecessors.
 *
 * @param indexOfScenario
 *            states the index of the created scenario within the usage scenario
 * @param sequence
 *            that is transformed to a scenario behavior
 * @param branch
 *            contains the child branches of the branch whose behavior is created
 * @return the created scenario behavior
 */
private // NOCS
ScenarioBehaviour transformSequenceToScenarioBehavior(// NOCS
final int indexOfScenario, final List<ISequenceElement> sequence, final Branch branch) {
    final ScenarioBehaviour scenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    EntryLevelSystemCall lastESysCall = UsageModelFactory.createEmptyEntryLevelSystemCall();
    boolean isLastElementACall = false;
    Loop lastLoop = UsageModelFactory.createEmptyLoop();
    boolean isLastElementALoop = false;
    org.palladiosimulator.pcm.usagemodel.Branch lastLoopBranch = UsagemodelFactory.eINSTANCE.createBranch();
    boolean isLastElementALoopBranch = false;
    org.palladiosimulator.pcm.usagemodel.Branch lastBranch = UsagemodelFactory.eINSTANCE.createBranch();
    boolean isLastElementABranch = false;
    /**
     * Loops over all elements of the sequence and creates a corresponding scenario behavior by
     * connecting the elements via successor and predecessor connections.
     */
    for (final ISequenceElement branchElement : sequence) {
        // Element is a entryLevelSystemCall
        if (branchElement.getClass().equals(CallElement.class)) {
            EntryLevelSystemCall eSysCall = null;
            // Workaround TODO
            final String operationSignature = branchElement.getOperationSignature().replaceAll("\\(.*\\)", "()");
            final String[] operationSplit = operationSignature.split(" ");
            final Optional<Correspondent> optionCorrespondent = this.correspondenceModel.getCorrespondent(branchElement.getClassSignature(), operationSplit[operationSplit.length - 1]);
            if (optionCorrespondent.isPresent()) {
                final Correspondent correspondent = optionCorrespondent.get();
                if (PcmUsageModelBuilder.LOGGER.isDebugEnabled()) {
                    PcmUsageModelBuilder.LOGGER.debug("Usage: Found Correspondent: {}", correspondent.getPcmEntityName() + " " + correspondent.getPcmOperationName());
                }
                eSysCall = UsageModelFactory.createEntryLevelSystemCall(this.repositoryLookupModel, correspondent);
            }
            if (eSysCall != null) {
                if (isLastElementACall) {
                    UsageModelFactory.connect(lastESysCall, eSysCall);
                } else if (isLastElementALoop) {
                    UsageModelFactory.connect(lastLoop, eSysCall);
                } else if (isLastElementALoopBranch) {
                    UsageModelFactory.connect(lastLoopBranch, eSysCall);
                } else if (isLastElementABranch) {
                    UsageModelFactory.connect(lastBranch, eSysCall);
                } else {
                    UsageModelFactory.connect(start, eSysCall);
                }
                UsageModelFactory.addUserAction(scenarioBehaviour, eSysCall);
                lastESysCall = eSysCall;
                isLastElementACall = true;
                isLastElementALoop = false;
                isLastElementALoopBranch = false;
                isLastElementABranch = false;
            }
        } else if (branchElement.getClass().equals(LoopElement.class)) {
            // Element is a loop
            final Loop loop = this.createLoop(scenarioBehaviour, (LoopElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, loop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, loop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, loop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, loop);
            } else {
                UsageModelFactory.connect(start, loop);
            }
            lastLoop = loop;
            isLastElementALoop = true;
            isLastElementACall = false;
            isLastElementALoopBranch = false;
            isLastElementABranch = false;
        } else if (branchElement.getClass().equals(LoopBranchElement.class)) {
            // Element is a
            // looped Branch
            final org.palladiosimulator.pcm.usagemodel.Branch loopBranch = this.createLoopBranch(scenarioBehaviour, (LoopBranchElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, loopBranch);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, loopBranch);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, loopBranch);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, loopBranch);
            } else {
                UsageModelFactory.connect(start, loopBranch);
            }
            lastLoopBranch = loopBranch;
            isLastElementALoopBranch = true;
            isLastElementACall = false;
            isLastElementALoop = false;
            isLastElementABranch = false;
        } else if (branchElement.getClass().equals(BranchElement.class)) {
            // Element is a
            // Branch
            final org.palladiosimulator.pcm.usagemodel.Branch branchInter = this.createBranch(scenarioBehaviour, (BranchElement) branchElement);
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, branchInter);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, branchInter);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, branchInter);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, branchInter);
            } else {
                UsageModelFactory.connect(start, branchInter);
            }
            lastBranch = branchInter;
            isLastElementABranch = true;
            isLastElementALoopBranch = false;
            isLastElementACall = false;
            isLastElementALoop = false;
        } else {
            break;
        }
    }
    // checks if the branch got child branches
    if (branch == null) {
        if (isLastElementACall) {
            UsageModelFactory.connect(lastESysCall, stop);
        } else if (isLastElementALoop) {
            UsageModelFactory.connect(lastLoop, stop);
        } else if (isLastElementALoopBranch) {
            UsageModelFactory.connect(lastLoopBranch, stop);
        } else if (isLastElementABranch) {
            UsageModelFactory.connect(lastBranch, stop);
        } else {
            UsageModelFactory.connect(start, stop);
        }
    } else {
        final org.palladiosimulator.pcm.usagemodel.Branch branchUM = this.createChildBranch(scenarioBehaviour, indexOfScenario, branch);
        if (branchUM != null) {
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            } else {
                UsageModelFactory.connect(start, branchUM);
                UsageModelFactory.connect(branchUM, stop);
            }
        } else {
            if (isLastElementACall) {
                UsageModelFactory.connect(lastESysCall, stop);
            } else if (isLastElementALoop) {
                UsageModelFactory.connect(lastLoop, stop);
            } else if (isLastElementALoopBranch) {
                UsageModelFactory.connect(lastLoopBranch, stop);
            } else if (isLastElementABranch) {
                UsageModelFactory.connect(lastBranch, stop);
            } else {
                UsageModelFactory.connect(start, stop);
            }
        }
    }
    return scenarioBehaviour;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) ISequenceElement(org.iobserve.analysis.userbehavior.data.ISequenceElement) LoopElement(org.iobserve.analysis.userbehavior.data.LoopElement) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Branch(org.iobserve.analysis.userbehavior.data.Branch) Correspondent(org.iobserve.model.correspondence.Correspondent) BranchElement(org.iobserve.analysis.userbehavior.data.BranchElement) LoopBranchElement(org.iobserve.analysis.userbehavior.data.LoopBranchElement)

Aggregations

LoopElement (org.iobserve.analysis.userbehavior.data.LoopElement)5 ISequenceElement (org.iobserve.analysis.userbehavior.data.ISequenceElement)3 BranchElement (org.iobserve.analysis.userbehavior.data.BranchElement)2 CallElement (org.iobserve.analysis.userbehavior.data.CallElement)2 ArrayList (java.util.ArrayList)1 Branch (org.iobserve.analysis.userbehavior.data.Branch)1 LoopBranchElement (org.iobserve.analysis.userbehavior.data.LoopBranchElement)1 Correspondent (org.iobserve.model.correspondence.Correspondent)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