package uk.ac.aber.cs31920.assignment.implementation.solvers;

import uk.ac.aber.cs31920.assignment.implementation.datastructures.Edge;
import uk.ac.aber.cs31920.assignment.implementation.datastructures.GraphNode;
import uk.ac.aber.cs31920.assignment.implementation.datastructures.MaxFlowGraph;

import java.util.ArrayList;
import java.util.List;

/**
 * Calculates residuals of a graph, goes through each node and sets their residuals assuming they aren't
 * in the flow, those that are then get revisited and altered taking flow into account.
 */
public class ResidualCalculator {
    public static void calculateResidualOfEdgesNodes(Edge edge){
        edge.parent.removeResidualChildIfExists(edge.child);
        edge.child.addResidualChild(edge.parent);
    }


    public static void calculateResidualNetwork(GraphNode root, List<Edge> flow, MaxFlowGraph fullGraph){
        List<GraphNode> allNodes = fullGraph.fullGraph;

        for (GraphNode node : allNodes){node.resetResidualNetwork();}

        for (Edge edge : flow) {
            calculateResidualOfEdgesNodes(edge);
        }
    }
}
