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