Search in sources :

Example 11 with EntryCallNode

use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.

the class UsageModelToBehaviorModelStage method traverseBranch.

private Map<EntryCallNode, Double> traverseBranch(final BehaviorModel behaviorModel, final Optional<Map<EntryCallNode, Double>> optPreviousNodes, final Branch branch) {
    // assign new probabilities to the nodes
    final Map<BranchTransition, Map<EntryCallNode, Double>> transitionMap = new HashMap<>();
    for (final BranchTransition transition : branch.getBranchTransitions_Branch()) {
        final Map<EntryCallNode, Double> branchMap = new HashMap<>();
        optPreviousNodes.ifPresent(previousNodes -> previousNodes.keySet().stream().forEach(node -> branchMap.put(node, transition.getBranchProbability())));
        transitionMap.put(transition, branchMap);
    }
    // traverse all branches and collect the end nodes
    return branch.getBranchTransitions_Branch().stream().map(transition -> this.traverseScenarioBehavior(transition.getBranchedBehaviour_BranchTransition(), behaviorModel, // all
    Optional.of(transitionMap.get(transition)))).collect(HashMap::new, Map::putAll, // collect endNodes
    Map::putAll);
}
Also used : BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) HashMap(java.util.HashMap) OutputPort(teetime.framework.OutputPort) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) List(java.util.List) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) Map(java.util.Map) Optional(java.util.Optional) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) Branch(org.palladiosimulator.pcm.usagemodel.Branch) Start(org.palladiosimulator.pcm.usagemodel.Start) Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) HashMap(java.util.HashMap) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with EntryCallNode

use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.

the class UsageModelToBehaviorModelStage method findLoopStart.

/**
 * Find first {@link EntryLevelSystemCall} element of a {@link Loop} body.
 *
 * @param loop
 *            loop
 * @return first found {@link EntryLevelSystemCall}, if found
 */
private Optional<EntryCallNode> findLoopStart(final AbstractUserAction action) {
    if (action instanceof Stop) {
        // LoopStart not found
        return Optional.empty();
    } else if (action instanceof EntryLevelSystemCall) {
        // found loop start
        final EntryLevelSystemCall entryLevelSystemCall = (EntryLevelSystemCall) action;
        final EntryCallNode entryCallNode = this.createEntryCallNode(entryLevelSystemCall);
        return Optional.of(entryCallNode);
    } else if (action instanceof Loop) {
        // search nested scenario
        final Loop loop = (Loop) action;
        final List<AbstractUserAction> userActions = loop.getBodyBehaviour_Loop().getActions_ScenarioBehaviour();
        if (!userActions.isEmpty()) {
            return this.findLoopStart(userActions.get(0));
        } else {
            return Optional.empty();
        }
    } else if (action instanceof Branch) {
        // will always found before
        return Optional.empty();
    } else {
        // next action
        return this.findLoopStart(action.getSuccessor());
    }
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) Stop(org.palladiosimulator.pcm.usagemodel.Stop) Branch(org.palladiosimulator.pcm.usagemodel.Branch)

Example 13 with EntryCallNode

use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.

the class UnionModelGenerationStrategy method generateModel.

@Override
public BehaviorModel generateModel(final BehaviorModel[] models) {
    final BehaviorModel newModel = new BehaviorModel();
    for (final BehaviorModel model : models) {
        /**
         * We add nodes first so we don't get duplicate nodes from the same model
         */
        for (final EntryCallNode node : model.getNodes()) {
            final Optional<EntryCallNode> matchingNode = newModel.findNode(node.getSignature());
            if (matchingNode.isPresent()) {
                Optional<CallInformation> matchingInfo;
                for (final CallInformation info : node.getEntryCallInformation()) {
                    matchingInfo = matchingNode.get().findCallInformation(info.getInformationSignature(), info.getInformationParameter());
                    if (matchingInfo.isPresent()) {
                        final int newCount = Math.max(info.getCount(), matchingInfo.get().getCount());
                        matchingInfo.get().setCount(newCount);
                    } else {
                        matchingNode.get().mergeCallInformation(new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount()));
                    }
                }
            } else {
                // Copy node and add it
                final EntryCallNode newNode = new EntryCallNode();
                newNode.setSignature(node.getSignature());
                for (final CallInformation info : node.getEntryCallInformation()) {
                    final CallInformation newInfo = new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount());
                    newNode.mergeCallInformation(newInfo);
                }
                newModel.addNode(newNode, false);
            }
        }
        for (final EntryCallEdge edge : model.getEdges()) {
            final Optional<EntryCallEdge> matchingEdge = newModel.findEdge(edge.getSource().getSignature(), edge.getTarget().getSignature());
            if (matchingEdge.isPresent()) {
                matchingEdge.get().setCalls(Math.max(matchingEdge.get().getCalls(), edge.getCalls()));
            } else {
                newModel.addEdge(new EntryCallEdge(edge.getSource(), edge.getTarget(), edge.getCalls()), false);
            }
        }
    }
    return newModel;
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 14 with EntryCallNode

use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.

the class JPetStoreParameterMetric method getDistance.

@Override
public double getDistance(final BehaviorModel a, final BehaviorModel b) {
    // If a node is not shared by the other behavior model, it will be compared to
    // this empty dummy node
    final EntryCallNode dummyNode = new EntryCallNode();
    double distance = 0;
    double comparisons = 0;
    EntryCallNode matchingNode;
    for (final EntryCallNode nodeA : a.getNodes()) {
        matchingNode = b.findNode(nodeA.getSignature()).orElse(dummyNode);
        distance += this.getNodeDistance(nodeA, matchingNode);
        comparisons++;
    }
    // for which we cannot find matches with the dummy node.
    for (final EntryCallNode nodeB : b.getNodes()) {
        matchingNode = b.findNode(nodeB.getSignature()).orElse(null);
        if (matchingNode == null) {
            // We already compared it in the first loop if it's not null
            distance += this.getNodeDistance(nodeB, dummyNode);
            comparisons++;
        }
    }
    return comparisons > 0 ? distance / comparisons : 0;
}
Also used : EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode)

Example 15 with EntryCallNode

use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.

the class BehaviorModelVisualizationStage method createNodes.

/**
 * Create new nodes at visualisation backend.
 *
 * @param entryCallNodes
 *            entryCallNodes
 */
private void createNodes(final Collection<EntryCallNode> entryCallNodes, final long modelId) {
    final ArrayNode nodes = this.objectMapper.createArrayNode();
    for (final EntryCallNode entryCallNode : entryCallNodes) {
        final ObjectNode json = this.objectMapper.createObjectNode();
        json.put("id", 0);
        json.put("name", this.signatureStrategy.getSignature(entryCallNode));
        final ObjectNode extras = this.objectMapper.createObjectNode();
        for (final CallInformation callInformation : entryCallNode.getEntryCallInformation()) {
            extras.put(callInformation.getInformationSignature(), callInformation.getInformationParameter());
        }
        json.put("extra", extras);
        // TODO visualizations doesn't accept lists.
        // TODO is this a requirement request?
        nodes.add(json);
        final JsonNode node = this.postElement(json, this.getNodeUrl(modelId));
        this.nodeMap.put(entryCallNode.getSignature(), node);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)19 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)9 EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)9 BehaviorModel (org.iobserve.analysis.behavior.models.extended.BehaviorModel)6 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)3 Branch (org.palladiosimulator.pcm.usagemodel.Branch)3 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)3 Loop (org.palladiosimulator.pcm.usagemodel.Loop)3 Stop (org.palladiosimulator.pcm.usagemodel.Stop)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)2 NodeDifference (org.iobserve.evaluation.data.NodeDifference)2 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)2 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)2