Seminarthema 10 präsentiert von David Ruitter
=
Kapazität - Fluss
Solange es noch augmentierende Pfade gibt
O(|V ||E|²)
public static int maxFlow(Flownetwork flownetwork) {
List pathToSink;
int totalFlow = 0;
while(!(pathToSink = flownetwork.getAugmentingPath())
.isEmpty()) {
// Erhöhen des totalFlows um path Bottleneck
...
}
return totalFlow;
}
public List getAugmentingPath() {
var queue = new ArrayDeque();
var explored = new HashSet();
// Key is the child vertex and value the parent of the child
var childParent = new HashMap();
queue.offer(source);
explored.add(source.getLabel());
while(!queue.isEmpty()) {
Vertex currentVertex = queue.poll();
// Pfad rekonstruieren sobald gefunden
...
Collection edgesFromCurrentVertex = currentVertex.getEdges();
for (Edge edge : edgesFromCurrentVertex)
if (edge.hasRemainingCapacity() &&
!explored.contains(edge.to().getLabel())) {
queue.push(edge.to());
explored.add(edge.to().getLabel());
childParent.put(edge.to(), edge.from());
}
}
return List.of();
}