Search in sources :

Example 6 with EntryCallEdge

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

the class GeneralStructureMetric method calculateEdgeDistance.

/**
 * Calculate edge distance.
 *
 * @param a
 *            first model
 * @param b
 *            second model
 */
private double calculateEdgeDistance(final BehaviorModel a, final BehaviorModel b) {
    // Get amount of shared egdges, count an edge with edge number n as n individual
    // edges
    double edgesInA = 0;
    double edgesInB = 0;
    double sharedEdges = 0;
    for (final EntryCallEdge edgeA : a.getEdges()) {
        edgesInA += edgeA.getCalls();
        for (final EntryCallEdge edgeB : b.getEdges()) {
            edgesInB += edgeB.getCalls();
            if (edgeA.equals(edgeB)) {
                sharedEdges += Math.min(edgeA.getCalls(), edgeB.getCalls());
                // There cannot be multiple edge instances with the same source and
                break;
            // target nodes
            // in a model
            }
        }
    }
    return (edgesInA + edgesInB - sharedEdges) / (edgesInA + edgesInB);
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge)

Example 7 with EntryCallEdge

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

the class ComparisonOutputStage method execute.

@Override
protected void execute(final ComparisonResult result) throws IOException {
    final BufferedWriter writer = Files.newBufferedWriter(this.outputFile.toPath(), StandardCharsets.UTF_8, StandardOpenOption.WRITE);
    final int baselineNodeCount = result.getBaselineNodes().size();
    final int testModelNodeCount = result.getTestModelNodes().size();
    final int missingNodeCount = result.getMissingNodes().size();
    final int additionalNodeCount = result.getAdditionalNodes().size();
    final int baselineEdgeCount = result.getBaselineEdges().size();
    final int testModelEdgeCount = result.getTestModelEdges().size();
    final int missingEdgeCount = result.getMissingEdgeCount();
    final int additionalEdgeCount = result.getAdditionalEdgeCount();
    writer.write("CP;" + this.outputFile.getName() + ";" + baselineNodeCount + ";" + baselineEdgeCount + ";" + testModelNodeCount + ";" + testModelEdgeCount + ";" + missingNodeCount + ";" + additionalNodeCount + ";" + missingEdgeCount + ";" + additionalEdgeCount + ";" + (double) missingNodeCount / (double) baselineNodeCount + ";" + (double) additionalNodeCount / (double) baselineNodeCount + ";" + (double) missingEdgeCount / (double) baselineEdgeCount + ";" + (double) additionalEdgeCount / (double) baselineEdgeCount + "\n");
    final List<EntryCallNode> allNodes = this.createAllNodesList(result.getBaselineNodes(), result.getTestModelNodes());
    final List<EntryCallEdge> allEdges = this.createAllEdgesList(result.getBaselineEdges(), result.getTestModelEdges());
    this.generateNodeCallInformation(writer, "baseline;" + this.outputFile.getName() + ";", allNodes, result.getBaselineNodes());
    this.generateNodeCallInformation(writer, "compared;" + this.outputFile.getName() + ";", allNodes, result.getTestModelNodes());
    writer.write("baseline;------------------------------------------ edges\n");
    writer.write("compared;------------------------------------------ edges\n");
    this.generateEdges(writer, "baseline;" + this.outputFile.getName() + ";", allEdges, result.getBaselineEdges());
    this.generateEdges(writer, "compared;" + this.outputFile.getName() + ";", allEdges, result.getTestModelEdges());
    writer.write("Nodes:\n\tmissing=" + result.getMissingNodes().size() + "\n\tadditional=" + result.getAdditionalNodes().size() + "\n");
    for (final EntryCallNode node : result.getMissingNodes()) {
        writer.write("\t - " + node.getSignature() + "\n");
    }
    for (final EntryCallNode node : result.getAdditionalNodes()) {
        writer.write("\t + " + node.getSignature() + "\n");
    }
    for (final EntryCallNode node : result.getSimilarNodes()) {
        writer.write("\t = " + node.getSignature() + "\n");
    }
    writer.write("Edges:\n\tmissing=" + result.getMissingEdgeCount() + "\n\tadditional=" + result.getAdditionalEdgeCount() + "\n");
    writer.write("Node differences:\n");
    for (final NodeDifference difference : result.getNodeDifferences()) {
        writer.write("\tNode " + difference.getReferenceNode().getSignature() + "\n");
        writer.write("\t\tMissing");
        String separator = "=";
        for (final CallInformation callInformation : difference.getMissingInformation()) {
            writer.write(separator + callInformation);
            separator = ", ";
        }
        writer.write("\n");
        writer.write("\t\tAdditional");
        separator = "=";
        for (final CallInformation callInformation : difference.getMissingInformation()) {
            writer.write(separator + callInformation);
            separator = ", ";
        }
        writer.write("\n");
    }
    writer.close();
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) NodeDifference(org.iobserve.evaluation.data.NodeDifference) BufferedWriter(java.io.BufferedWriter)

Example 8 with EntryCallEdge

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

the class ComparisonOutputStage method createAllEdgesList.

private List<EntryCallEdge> createAllEdgesList(final List<EntryCallEdge> baselineEdges, final List<EntryCallEdge> testModelEdges) {
    final List<EntryCallEdge> result = new ArrayList<>();
    for (final EntryCallEdge edge : baselineEdges) {
        final EntryCallEdge duplicateEdge = new EntryCallEdge();
        duplicateEdge.setCalls(edge.getCalls());
        duplicateEdge.setSource(edge.getSource());
        duplicateEdge.setTarget(edge.getTarget());
        result.add(duplicateEdge);
    }
    for (final EntryCallEdge edge : testModelEdges) {
        if (!this.edgeExists(baselineEdges, edge)) {
            result.add(edge);
        } else {
            final EntryCallEdge duplicateEdge = this.findEdge(result, edge);
            duplicateEdge.addCalls(edge.getCalls());
        }
    }
    return result;
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) ArrayList(java.util.ArrayList)

Example 9 with EntryCallEdge

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

the class ModelComparisonStageTest method createTestModel.

private BehaviorModel createTestModel() {
    final BehaviorModel model = new BehaviorModel();
    model.addNode(this.nodeAtest, false);
    model.addNode(this.nodeBtest, false);
    model.addNode(this.nodeDtest, false);
    final EntryCallEdge edgeAB = new EntryCallEdge(this.nodeAtest, this.nodeBtest);
    edgeAB.addCalls(4);
    model.addEdge(edgeAB, false);
    final EntryCallEdge edgeBA = new EntryCallEdge(this.nodeBtest, this.nodeAtest);
    edgeBA.addCalls(3);
    model.addEdge(edgeBA, false);
    final EntryCallEdge edgeBD = new EntryCallEdge(this.nodeBtest, this.nodeDtest);
    edgeBA.addCalls(1);
    model.addEdge(edgeBD, false);
    return model;
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 10 with EntryCallEdge

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

the class ModelComparisonStageTest method checkEdgeLists.

private void checkEdgeLists(final String label, final String direction, final List<EntryCallEdge> leftEdges, final List<EntryCallEdge> rightEdges) {
    for (final EntryCallEdge left : leftEdges) {
        boolean match = false;
        for (final EntryCallEdge right : rightEdges) {
            if (left.getSource().getSignature().equals(right.getSource().getSignature()) && left.getTarget().getSignature().equals(right.getTarget().getSignature())) {
                Assert.assertTrue(label + ": Edges count mismatch for " + left.getSource().getSignature() + " -> " + left.getTarget().getSignature(), left.getCalls() == right.getCalls());
                match = true;
                break;
            }
        }
        Assert.assertTrue(label + ": Edges present in " + direction + " model. Missing " + left.getSource().getSignature() + " -> " + left.getTarget().getSignature(), match);
    }
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge)

Aggregations

EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)15 BehaviorModel (org.iobserve.analysis.behavior.models.extended.BehaviorModel)8 EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)8 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Optional (java.util.Optional)2 NodeDifference (org.iobserve.evaluation.data.NodeDifference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)1 ComparisonResult (org.iobserve.evaluation.data.ComparisonResult)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1