Search in sources :

Example 1 with MaximumFlowAlgorithm

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);
}
Also used : BigInteger(java.math.BigInteger) MaximumFlowAlgorithm(org.psjava.algo.graph.flownetwork.MaximumFlowAlgorithm) CapacityEdge(org.psjava.ds.graph.CapacityEdge) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BigInteger (java.math.BigInteger)1 MaximumFlowAlgorithm (org.psjava.algo.graph.flownetwork.MaximumFlowAlgorithm)1 CapacityEdge (org.psjava.ds.graph.CapacityEdge)1