protected WeightedGraph<Figure, DefaultWeightedEdge> extractNetwork(JCas jcas, Annotation range) { SimpleWeightedGraph<Figure, DefaultWeightedEdge> graph = new SimpleWeightedGraph<Figure, DefaultWeightedEdge>( DefaultWeightedEdge.class); for (Figure figure : JCasUtil.select(jcas, Figure.class)) { if (!graph.containsVertex(figure)) { graph.addVertex(figure); } } for (Scene scene : JCasUtil.select(jcas, Scene.class)) { List<Speaker> speakers = JCasUtil.selectCovered(Speaker.class, scene); for (Speaker s1 : speakers) { Figure gf1 = s1.getFigure(); if (gf1 != null) for (Speaker s2 : speakers) { Figure gf2 = s2.getFigure(); if (gf2 != null) if (graph.containsEdge(gf1, gf2)) { DefaultWeightedEdge edge = graph.getEdge(gf1, gf2); double w = graph.getEdgeWeight(edge); graph.setEdgeWeight(edge, w + 1.0); } else { if (gf1 != gf2) graph.addEdge(gf1, gf2); } } } ; } return graph; }
Set<DefaultWeightedEdge> edges = new LinkedHashSet<>(gomoryHuTree.edgeSet()); for (DefaultWeightedEdge edge : edges) { V source = gomoryHuTree.getEdgeSource(edge); V target = gomoryHuTree.getEdgeTarget(edge); double edgeWeight = gomoryHuTree.getEdgeWeight(edge); gomoryHuTree.removeEdge(edge); // Temporarily remove edge Set<V> sourcePartition = new ConnectivityInspector<>(gomoryHuTree).connectedSetOf(source); sourcePartitionMinimumCut = sourcePartition; gomoryHuTree.addEdge(source, target, edge); // Place edge back
/** * Reset any link created in the graph result in this tracker, effectively * creating a new graph, containing the spots but no edge. */ public void reset() { graph = new SimpleWeightedGraph<>(DefaultWeightedEdge.class); final Iterator<Spot> it = spots.iterator(true); while (it.hasNext()) { graph.addVertex(it.next()); } }
@Override public boolean execute(int hashIndex, Set<WriteableImageOutput> itemSet) { for (final WriteableImageOutput item : itemSet) { if (!graph.containsVertex(item)) { graph.addVertex(item); } } final List<WriteableImageOutput> itemList = new ArrayList<WriteableImageOutput>(); itemList.addAll(itemSet); for (int i = 0; i < itemList.size(); i++) { final WriteableImageOutput itemA = itemList.get(i); for (int j = i + 1; j < itemList.size(); j++) { final WriteableImageOutput itemB = itemList.get(j); DefaultWeightedEdge edge = graph.getEdge(itemA, itemB); if (edge == null) { edge = graph.addEdge(itemA, itemB); graph.setEdgeWeight(edge, 1); } else { graph.setEdgeWeight(edge, graph.getEdgeWeight(edge) + 1); } } } return true; } });
/** * Calculates the minimum cut in the graph, that is, the minimum cut over all $s-t$ pairs. The * same result can be obtained with the {@link org.jgrapht.alg.StoerWagnerMinimumCut} * implementation. After invoking this method, the source/sink partitions corresponding to the * minimum cut can be queried through the {@link #getSourcePartition()} and * {@link #getSinkPartition()} methods. After computing the Gomory-Hu Cut tree, this method runs * in $O(N)$ time. * * @return weight of the minimum cut in the graph */ public double calculateMinCut() { if (this.gomoryHuTree == null) this.gomoryHuTree = this.getGomoryHuTree(); DefaultWeightedEdge cheapestEdge = gomoryHuTree .edgeSet().stream().min(Comparator.comparing(gomoryHuTree::getEdgeWeight)) .orElseThrow(() -> new RuntimeException("graph is empty?!")); lastInvokedSource = gomoryHuTree.getEdgeSource(cheapestEdge); lastInvokedTarget = gomoryHuTree.getEdgeTarget(cheapestEdge); sourcePartitionLastInvokedSource = null; return gomoryHuTree.getEdgeWeight(cheapestEdge); }
System.out.println("done"); final SimpleWeightedGraph<String, DefaultWeightedEdge> graph = new SimpleWeightedGraph<String, DefaultWeightedEdge>( DefaultWeightedEdge.class); final File filename = new File(String.format("/Users/jsh2/Data/ukbench/full/ukbench0%04d.jpg", i)); graph.addVertex(filename.toString()); continue; final DefaultWeightedEdge edge = graph.addEdge(filename.toString(), k.second); if (edge != null) graph.setEdgeWeight(edge, k.first);
graph = new SimpleWeightedGraph<>( DefaultWeightedEdge.class ); for ( final List< Spot > branch : branches ) graph.addVertex( spot ); graph.addEdge( previous, spot ); previous = spot; graph.addEdge( link.get( 0 ), link.get( 1 ) );
TrackModel() { this( new SimpleWeightedGraph< Spot, DefaultWeightedEdge >( DefaultWeightedEdge.class ) ); }
final Spot start = segmentStart.first(); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(end, start); graph.setEdgeWeight(edge, weight); final Spot middle = mergingMiddlePoints.get(j - numTrackSegments); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(end, middle); graph.setEdgeWeight(edge, weight); final Spot mother = splittingMiddlePoints.get(i - numTrackSegments); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(mother, start); graph.setEdgeWeight(edge, weight);
public static void addConnectionToGraph(Connection connection, double connectionWeight, SimpleWeightedGraph<ConnectionPoint3D, DefaultWeightedEdge> graphToUpdate) { ConnectionPoint3D source = connection.getSourcePoint(); ConnectionPoint3D target = connection.getTargetPoint(); if (!source.epsilonEquals(target, 1.0e-3)) { graphToUpdate.addVertex(source); graphToUpdate.addVertex(target); DefaultWeightedEdge edge = new DefaultWeightedEdge(); graphToUpdate.addEdge(source, target, edge); graphToUpdate.setEdgeWeight(edge, connectionWeight); } }
/** * Returns the Equivalent Flow Tree as an actual tree (graph). Note that this tree is not * necessarily unique. The edge weights represent the flow values/cut weights. This method runs * in $O(n)$ time * * @return Equivalent Flow Tree */ public SimpleWeightedGraph<V, DefaultWeightedEdge> getEquivalentFlowTree() { if (p == null) // Lazy invocation of the algorithm this.calculateEquivalentFlowTree(); SimpleWeightedGraph<V, DefaultWeightedEdge> equivalentFlowTree = new SimpleWeightedGraph<>(DefaultWeightedEdge.class); Graphs.addAllVertices(equivalentFlowTree, vertexList); for (int i = 1; i < N; i++) { DefaultWeightedEdge e = equivalentFlowTree.addEdge(vertexList.get(i), vertexList.get(neighbors[i])); equivalentFlowTree.setEdgeWeight(e, flowMatrix[i][neighbors[i]]); } return equivalentFlowTree; }
final SimpleWeightedGraph<WriteableImageOutput, DefaultWeightedEdge> graph = new SimpleWeightedGraph<WriteableImageOutput, DefaultWeightedEdge>( DefaultWeightedEdge.class); for (final TIntObjectHashMap<Set<WriteableImageOutput>> set : this.database) { final Set<DefaultWeightedEdge> edges = new HashSet<DefaultWeightedEdge>(graph.edgeSet()); for (final DefaultWeightedEdge e : edges) { if (graph.getEdgeWeight(e) < 10) graph.removeEdge(e);
@Override public Set<V> getSourcePartition() { if (sourcePartitionLastInvokedSource != null) return sourcePartitionLastInvokedSource; if (this.gomoryHuTree == null) this.gomoryHuTree = this.getGomoryHuTree(); Set<DefaultWeightedEdge> pathEdges = this.findPathBetween(gomoryHuTree, lastInvokedSource, lastInvokedTarget); DefaultWeightedEdge cheapestEdge = pathEdges.stream().min(Comparator.comparing(gomoryHuTree::getEdgeWeight)).orElseThrow( () -> new RuntimeException("path is empty?!")); // Remove the selected edge from the gomoryHuTree graph. The resulting graph consists of 2 // components V source = gomoryHuTree.getEdgeSource(cheapestEdge); V target = gomoryHuTree.getEdgeTarget(cheapestEdge); gomoryHuTree.removeEdge(cheapestEdge); // Return the vertices in the component with the source vertex sourcePartitionLastInvokedSource = new ConnectivityInspector<>(gomoryHuTree).connectedSetOf(lastInvokedSource); // Restore the internal tree structure by putting the edge back gomoryHuTree.addEdge(source, target, cheapestEdge); return sourcePartitionLastInvokedSource; }
if ( !graph.containsVertex( spot ) ) if ( !graph.containsEdge( source, target ) ) for ( final DefaultWeightedEdge edge : graph.edgeSet() ) final Spot source = graph.getEdgeSource( edge ); final Spot target = graph.getEdgeTarget( edge ); if ( !graph.containsEdge( source, target ) )
while (v != source) { V pred = predecessorMap.get(v); edges.add(tree.getEdge(v, pred)); v = pred;
System.out.println("done"); final SimpleWeightedGraph<String, DefaultWeightedEdge> graph = new SimpleWeightedGraph<String, DefaultWeightedEdge>( DefaultWeightedEdge.class); final File filename = new File(String.format("/Users/jsh2/Data/ukbench/full/ukbench0%04d.jpg", i)); graph.addVertex(filename.toString()); continue; final DefaultWeightedEdge edge = graph.addEdge(filename.toString(), k.second); if (edge != null) graph.setEdgeWeight(edge, k.first);
graph = new SimpleWeightedGraph<>( DefaultWeightedEdge.class ); for ( final List< Spot > branch : branches ) graph.addVertex( spot ); graph.addEdge( previous, spot ); previous = spot; graph.addEdge( link.get( 0 ), link.get( 1 ) );
TrackModel() { this( new SimpleWeightedGraph< Spot, DefaultWeightedEdge >( DefaultWeightedEdge.class ) ); }
final Spot start = segmentStart.first(); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(end, start); graph.setEdgeWeight(edge, weight); final Spot middle = mergingMiddlePoints.get(j - numTrackSegments); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(end, middle); graph.setEdgeWeight(edge, weight); final Spot mother = splittingMiddlePoints.get(i - numTrackSegments); weight = segmentCosts[i][j]; final DefaultWeightedEdge edge = graph.addEdge(mother, start); graph.setEdgeWeight(edge, weight);
graph.addVertex( source ); graph.addVertex( target ); final DefaultWeightedEdge edge = graph.addEdge( source, target ); graph.setEdgeWeight( edge, cost );