List<Set<Group>> equivGroups = new ConnectivityInspector<>(equivs).connectedSets(); for(Set<Group> equivGroup: equivGroups) { Integer fixedP = getFixedParallelism(equivGroup);
List<Set<Node>> connectedComponents = new ConnectivityInspector<>(graph).connectedSets(); for(int i=0; i<connectedComponents.size(); i++) { String groupId = "bg" + i;
private static void completeDRPC(DefaultDirectedGraph<Node, IndexedEdge> graph, Map<String, List<Node>> colocate, UniqueIdGen gen) { List<Set<Node>> connectedComponents = new ConnectivityInspector<>(graph).connectedSets(); for(Set<Node> g: connectedComponents) { checkValidJoins(g); } TridentTopology helper = new TridentTopology(graph, colocate, gen); for(Set<Node> g: connectedComponents) { SpoutNode drpcNode = getDRPCSpoutNode(g); if(drpcNode!=null) { Stream lastStream = new Stream(helper, null, getLastAddedNode(g)); Stream s = new Stream(helper, null, drpcNode); helper.multiReduce( s.project(new Fields("return-info")) .batchGlobal(), lastStream.batchGlobal(), new ReturnResultsReducer(), new Fields()); } } }
/** * Uses DFS approach to create a List of track segments from the overall * result of step 1 * <p> * We have recorded the tracks as edges in the track graph, we now turn them * into multiple explicit sets of Spots, sorted by their {@link Spot#FRAME}. */ private void compileTrackSegments() { final ConnectivityInspector<Spot, DefaultWeightedEdge> inspector = new ConnectivityInspector<>(graph); final List<Set<Spot>> unsortedSegments = inspector.connectedSets(); trackSegments = new ArrayList<>(unsortedSegments.size()); for (final Set<Spot> set : unsortedSegments) { final SortedSet<Spot> sortedSet = new TreeSet<>(Spot.frameComparator); sortedSet.addAll(set); trackSegments.add(sortedSet); } }
/** * Uses DFS approach to create a List of track segments from the overall * result of step 1 * <p> * We have recorded the tracks as edges in the track graph, we now turn them * into multiple explicit sets of Spots, sorted by their {@link Spot#FRAME}. */ private void compileTrackSegments() { final ConnectivityInspector<Spot, DefaultWeightedEdge> inspector = new ConnectivityInspector<>(graph); final List<Set<Spot>> unsortedSegments = inspector.connectedSets(); trackSegments = new ArrayList<>(unsortedSegments.size()); for (final Set<Spot> set : unsortedSegments) { final SortedSet<Spot> sortedSet = new TreeSet<>(Spot.frameComparator); sortedSet.addAll(set); trackSegments.add(sortedSet); } }
public Set<String> analyse() { UndirectedGraph<Vertex, Object> graph = createGraph(); // sort by ascending size return new ConnectivityInspector<>(graph).connectedSets().stream() .sorted(new Comparator<Set<Vertex>>() { @Override public int compare(Set<Vertex> o1, Set<Vertex> o2) { return o2.size() - o1.size(); } }) .map(s -> s.stream().map(v -> v.equipmentId).collect(Collectors.<String>toSet())) .collect(Collectors.toList()) .get(0); } }
public ProcessModel getProcessModel() { List<Set<ProcessModelElement>> connectedSets = connectivityInspector.connectedSets(); List<ProcessModelElementGroup> processModelElementGroups = new ArrayList<ProcessModelElementGroup>(); for (Set<ProcessModelElement> connectedSet : connectedSets) { ProcessModelElementGroup group = new ProcessModelElementGroup(connectedSet, controlDT); processModelElementGroups.add(group); } return new ProcessModel(processModelElementGroups); }
@Override public int calculateOrder(AFPChain selfAlignment, Atom[] ca) throws RefinerFailedException { // Construct the alignment graph with jgrapht Graph<Integer, DefaultEdge> graph = SymmetryTools .buildSymmetryGraph(selfAlignment); // Find the maximally connected components of the graph ConnectivityInspector<Integer, DefaultEdge> inspector = new ConnectivityInspector<Integer, DefaultEdge>(graph); List<Set<Integer>> components = inspector.connectedSets(); // The order maximizes the residues aligned Map<Integer, Integer> counts = new HashMap<Integer, Integer>(); for (Set<Integer> c : components) { if (counts.containsKey(c.size())) counts.put(c.size(), counts.get(c.size()) + c.size()); else counts.put(c.size(), c.size()); } int maxCounts = 0; int order = 1; for (Integer ord : counts.keySet()) { if (counts.get(ord) > maxCounts) { order = ord; maxCounts = counts.get(ord); } } return order; }
/** Returns the connected components of the given graph * * @param nodes List of nodes * @param links List of links * @return see above */ public static List<Set<Node>> getConnectedComponents (Collection<Node> nodes, List<Link> links) { org.jgrapht.Graph<Node, Link> graph = JGraphTUtils.getGraphFromLinkMap(nodes, links); final ConnectivityInspector<Node, Link> inspector = new ConnectivityInspector<Node, Link>((DirectedGraph<Node,Link>) graph); return inspector.connectedSets(); }
public void build() { // CGMES standard: // "a PowerTransformer is contained in one Substation but it can connect a Terminal to // another Substation" // Ends of transformers need to be in the same substation in the IIDM model. // We will map some CGMES substations to a single IIDM substation // when they are connected by transformers, // that is, when there are at least one power transformer that has terminals on both // substations UndirectedGraph<String, Object> g = graphSubstationsTransformers(); new ConnectivityInspector<>(g).connectedSets().stream() .filter(substationIds -> substationIds.size() > 1) .forEach(substationIds -> { String selectedSubstationId = representativeSubstationId(substationIds); for (String substationId : substationIds) { if (!substationId.equals(selectedSubstationId)) { mapping.put(substationId, selectedSubstationId); } } }); if (!mapping.isEmpty()) { LOG.warn("Substation id mapping needed for {} substations: {}", mapping.size(), mapping); } }
/** * @return Returns the largest connected component as a new graph. If the base graph already is connected, it simply returns the whole graph. */ public CategoryGraph getLargestConnectedComponent() throws WikiApiException { ConnectivityInspector connectInspect = new ConnectivityInspector<Integer, DefaultEdge>(graph); // if the graph is connected, simply return the whole graph if (connectInspect.isGraphConnected()) { return this; } // else, get the largest connected component List<Set<Integer>> connectedComponentList = connectInspect.connectedSets(); logger.info(connectedComponentList.size() + " connected components."); int i = 0; int maxSize = 0; Set<Integer> largestComponent = new HashSet<Integer>(); for (Set<Integer> connectedComponent : connectedComponentList) { i++; if (connectedComponent.size() > maxSize) { maxSize = connectedComponent.size(); largestComponent = connectedComponent; } } double largestComponentRatio = largestComponent.size() * 100 / this.getNumberOfNodes(); logger.info ("Largest component contains " + largestComponentRatio + "% (" + largestComponent.size() + "/" + this.getNumberOfNodes() + ") of the nodes in the graph."); return CategoryGraphManager.getCategoryGraph(wiki, largestComponent); }
private static List<Set<VUCent>> getConnectedComponents(Graph<VUCent, Edge> graph, String orientation) { LOGGER.info("Calculating connected components... "); final long start = System.currentTimeMillis(); List<Set<VUCent>> sets; if (parseGlobalOrientation(orientation).equals(UNDIRECTED)) { sets = new ConnectivityInspector<VUCent, Edge>( (UndirectedGraph<VUCent, Edge>) graph).connectedSets(); } else { sets = new GabowStrongConnectivityInspector<VUCent, Edge>( (DirectedGraph) graph).stronglyConnectedSets(); } logTime(LOGGER, start); return sets; }
private static List<Set<VUCent>> getConnectedComponents(Graph<VUCent, Edge> graph, String orientation) { LOGGER.info("Calculating connected components... "); final long start = System.currentTimeMillis(); List<Set<VUCent>> sets; if (parseGlobalOrientation(orientation).equals(UNDIRECTED)) { sets = new ConnectivityInspector<VUCent, Edge>( (UndirectedGraph<VUCent, Edge>) graph).connectedSets(); } else { sets = new StrongConnectivityInspector<VUCent, Edge>( (DirectedGraph) graph).stronglyConnectedSets(); } logTime(LOGGER, start); return sets; }
private static List<Set<VUCent>> getConnectedComponents(Graph<VUCent, Edge> graph, String orientation) { LOGGER.info("Calculating connected components... "); final long start = System.currentTimeMillis(); List<Set<VUCent>> sets; if (parseGlobalOrientation(orientation).equals(UNDIRECTED)) { sets = new ConnectivityInspector<VUCent, Edge>( (UndirectedGraph<VUCent, Edge>) graph).connectedSets(); } else { sets = new StrongConnectivityInspector<VUCent, Edge>( (DirectedGraph) graph).stronglyConnectedSets(); } logTime(LOGGER, start); return sets; }
private List<Set<String>> getClusters(List<String> dir1, List<String> dir2, Matrix scores) { UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); for (String f : dir1) graph.addVertex(f); if (dir1 != dir2) for (String f : dir2) graph.addVertex(f); final double[][] matrixData = scores.getArray(); for (int r=0; r<matrixData.length; r++) { for (int c=r; c<matrixData[0].length; c++) { String f1 = dir1.get(r); String f2 = dir2.get(c); if ( matrixData[r][c] != 0 && f1!=f2 ) { graph.addEdge(f1, f2); } } } ConnectivityInspector<String, DefaultEdge> conn = new ConnectivityInspector<String, DefaultEdge>(graph); return conn.connectedSets(); }
private List<Set<String>> getClusters(List<String> dir1, List<String> dir2, Matrix scores) { UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); for (String f : dir1) graph.addVertex(f); if (dir1 != dir2) for (String f : dir2) graph.addVertex(f); final double[][] matrixData = scores.getArray(); for (int r=0; r<matrixData.length; r++) { for (int c=r; c<matrixData[0].length; c++) { String f1 = dir1.get(r); String f2 = dir2.get(c); if ( matrixData[r][c] != 0 && f1!=f2 ) { graph.addEdge(f1, f2); } } } ConnectivityInspector<String, DefaultEdge> conn = new ConnectivityInspector<String, DefaultEdge>(graph); return conn.connectedSets(); }
/** * Retrieve the map of best clefs, organized per kind. * * @param isFirstPass true for first pass only * @return the bestMap found */ private Map<ClefKind, ClefInter> getBestMap (boolean isFirstPass) { List<Glyph> parts = getParts(isFirstPass); // Formalize parts relationships in a global graph SimpleGraph<Glyph, GlyphLink> graph = Glyphs.buildLinks(parts, params.maxPartGap); List<Set<Glyph>> sets = new ConnectivityInspector<>(graph).connectedSets(); logger.debug("Staff#{} sets: {}", staff.getId(), sets.size()); // Best inter per clef kind Map<ClefKind, ClefInter> bestMap = new EnumMap<>(ClefKind.class); for (Set<Glyph> set : sets) { // Use only the subgraph for this set SimpleGraph<Glyph, GlyphLink> subGraph = GlyphCluster.getSubGraph(set, graph, false); ClefAdapter adapter = new ClefAdapter(subGraph, bestMap); new GlyphCluster(adapter, null).decompose(); int trials = adapter.trials; logger.debug("Staff#{} clef parts:{} trials:{}", staff.getId(), set.size(), trials); } // Discard poor candidates as much as possible if (bestMap.size() > 1) { purgeClefs(bestMap); } return bestMap; }
private static void verifyTracks( final SimpleWeightedGraph< Spot, DefaultWeightedEdge > graph, final List< List< Spot >> groups, final int nFrames ) { // Check that we have the right number of vertices assertEquals( "The tracking result graph has the wrong number of vertices, ", 2 * nFrames, graph.vertexSet().size() ); // Check that we have the right number of tracks final ConnectivityInspector< Spot, DefaultWeightedEdge > inspector = new ConnectivityInspector< >( graph ); final int nTracks = inspector.connectedSets().size(); assertEquals( "Did not get the right number of tracks, ", 2, nTracks ); // Check that the tracks are right: the group1 must contain exactly the // spot of one track for ( final List< Spot > group : groups ) { // System.out.print("\nTrack: "); final Set< Spot > track1 = inspector.connectedSetOf( group.get( 0 ) ); for ( final Spot spot : group ) { final boolean removed = track1.remove( spot ); assertTrue( "Failed to find spot " + spot + " in track.", removed ); // System.out.print(spot+"-"); } assertEquals( "Track has some unexpected spots", 0, track1.size() ); } } }
public ActionClusterFinder(TreeContext src, TreeContext dst, List<Action> actions) { this.src = src; this.dst = dst; this.actions = actions; graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (Action a: actions) graph.addVertex(a); for (Action a1: actions) { for (Action a2: actions) { if (a1 != a2) { if (embeddedInserts(a1, a2) || sameValueUpdates(a1, a2) || sameParentMoves(a1, a2) || embeddedDeletes(a1, a2)) graph.addEdge(a1, a2); } } } ConnectivityInspector alg = new ConnectivityInspector(graph); clusters = alg.connectedSets(); }
private static void completeDRPC(DefaultDirectedGraph<Node, IndexedEdge> graph, Map<String, List<Node>> colocate, UniqueIdGen gen) { List<Set<Node>> connectedComponents = new ConnectivityInspector<Node, IndexedEdge>(graph).connectedSets(); for(Set<Node> g: connectedComponents) { checkValidJoins(g); } TridentTopology helper = new TridentTopology(graph, colocate, gen); for(Set<Node> g: connectedComponents) { SpoutNode drpcNode = getDRPCSpoutNode(g); if(drpcNode!=null) { Stream lastStream = new Stream(helper, null, getLastAddedNode(g)); Stream s = new Stream(helper, null, drpcNode); helper.multiReduce( s.project(new Fields("return-info")) .batchGlobal(), lastStream.batchGlobal(), new ReturnResultsReducer(), new Fields()); } } }