/** * 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); }
@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; } });
if (graph.getEdgeWeight(e) < 10) graph.removeEdge(e);
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; }
V source = gomoryHuTree.getEdgeSource(edge); V target = gomoryHuTree.getEdgeTarget(edge); double edgeWeight = gomoryHuTree.getEdgeWeight(edge);
model.addEdge( source, target, graph.getEdgeWeight( edge ) );
model.addEdge( source, target, graph.getEdgeWeight( edge ) );