public int getDistance(MethodDescription start, MethodDescription end) { if (!(g.containsVertex(start) && g.containsVertex(end))) { return -1; } DijkstraShortestPath<MethodDescription, DefaultEdge> sp = new DijkstraShortestPath<MethodDescription, DefaultEdge>( g, start, end); double pathLength = sp.getPathLength(); System.out.println("DistanceGraph.getDistance() " + sp.getPathEdgeList()); if (pathLength == Double.POSITIVE_INFINITY) { pathLength = 0; Set<String> allSupers = hierarchy.getAllSupers(end.getClassName()); for (String sup : allSupers) { MethodDescription super1 = end.getSuper(sup); int distance = getDistance(start, super1); if (distance > 0) { return distance; } } } if (pathLength < 0.) { pathLength = 0; } return (int) pathLength; }
public DistanceGraph(ConnectionData data, Hierarchy hierarchy) { // this.data = data; this.hierarchy = hierarchy; allMethods = data.getAllMethods(); g = new SimpleGraph<MethodDescription, DefaultEdge>(DefaultEdge.class); Set<Tuple> connections = data.getConnections(); for (Tuple tuple : connections) { MethodDescription start = tuple.getStart(); MethodDescription end = tuple.getEnd(); if (!start.equals(end)) { if (!g.containsVertex(start)) { g.addVertex(start); } if (!g.containsVertex(end)) { g.addVertex(end); } g.addEdge(start, end); } } }
Vertex v1 = new Vertex(branchId, substationId1, topoId); Vertex v2 = new Vertex(branchId, substationId2, topoId); if (graph.containsVertex(v1) && graph.containsVertex(v2)) { graph.addEdge(v1, v2); Vertex v1 = new Vertex(branchId, substationId1, topoId1); Vertex v2 = new Vertex(branchId, substationId2, topoId2); if (graph.containsVertex(v1) && graph.containsVertex(v2)) { graph.addEdge(v1, v2);