/** * helper used to add $newFlow to original edges of $clonedEdges in graph $resultGraph * * @param Graph $resultGraph graph to look for original edges * @param Edges $clonedEdges set of cloned edges to be modified * @param number $newFlow flow to add * @uses Graph::getEdgeClone() * @uses Graph::getEdgeCloneInverted() * @uses Edge::getFlow() * @uses Edge::setFlow() */ protected function addFlow(Graph $resultGraph, Edges $clonedEdges, $newFlow) { foreach ($clonedEdges as $clonedEdge) { try { // get edge from clone $edge = $resultGraph->getEdgeClone($clonedEdge); // add flow $edge->setFlow($edge->getFlow() + $newFlow); // if the edge doesn't exist => use the residual edge } catch (UnderflowException $ignore) { $edge = $resultGraph->getEdgeCloneInverted($clonedEdge); // remove flow $edge->setFlow($edge->getFlow() - $newFlow); } } }