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);
/** * 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; }
@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; } });
continue; final DefaultWeightedEdge edge = graph.addEdge(filename.toString(), k.second); if (edge != null) graph.setEdgeWeight(edge, k.first);
continue; final DefaultWeightedEdge edge = graph.addEdge(filename.toString(), k.second); if (edge != null) graph.setEdgeWeight(edge, k.first);
@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; }
final DefaultWeightedEdge edge = graph.addEdge(s0, s1); graph.setEdgeWeight(edge, weight);
final DefaultWeightedEdge edge = graph.addEdge(s0, s1); graph.setEdgeWeight(edge, weight);
graph.addVertex( source ); graph.addVertex( target ); final DefaultWeightedEdge edge = graph.addEdge( source, target ); graph.setEdgeWeight( edge, cost );
graph.addVertex( source ); graph.addVertex( target ); final DefaultWeightedEdge edge = graph.addEdge( source, target ); graph.setEdgeWeight( edge, cost );
final DefaultWeightedEdge edge = graph.addEdge(source, targetNode.getValue()); graph.setEdgeWeight(edge, squareDist);
final DefaultWeightedEdge edge = graph.addEdge(source, targetNode.getValue()); graph.setEdgeWeight(edge, squareDist);
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); } }
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; }
final DefaultWeightedEdge edge = graph.addEdge( source, target );
final DefaultWeightedEdge edge = graph.addEdge( source, target );
sourcePartitionMinimumCut = sourcePartition; gomoryHuTree.addEdge(source, target, edge); // Place edge back
final DefaultWeightedEdge edge = graph.addEdge( source, target ); graph.setEdgeWeight( edge, 1 ); source = target;