use of org.psjava.algo.graph.flownetwork.MaximumFlowAlgorithm in project cassandra by apache.
the class RangeFetchMapCalculator method getRangeFetchMapForNonTrivialRanges.
@VisibleForTesting
Multimap<InetAddressAndPort, Range<Token>> getRangeFetchMapForNonTrivialRanges() {
// Get the graph with edges between ranges and their source endpoints
MutableCapacityGraph<Vertex, Integer> graph = getGraph();
// Add source and destination vertex and edges
addSourceAndDestination(graph, getDestinationLinkCapacity(graph));
int flow = 0;
MaximumFlowAlgorithmResult<Integer, CapacityEdge<Vertex, Integer>> result = null;
// We might not be working on all ranges
while (flow < getTotalRangeVertices(graph)) {
if (flow > 0) {
// We could not find a path with previous graph. Bump the capacity b/w endpoint vertices and destination by 1
incrementCapacity(graph, 1);
}
MaximumFlowAlgorithm fordFulkerson = FordFulkersonAlgorithm.getInstance(DFSPathFinder.getInstance());
result = fordFulkerson.calc(graph, sourceVertex, destinationVertex, IntegerNumberSystem.getInstance());
int newFlow = result.calcTotalFlow();
// We are not making progress which should not happen
assert newFlow > flow;
flow = newFlow;
}
return getRangeFetchMapFromGraphResult(graph, result);
}
Aggregations