public function createGraph()
    {
        $newgraph = $this->graph->createGraphCloneEdgeless();

        foreach ($this->graph->getEdges() as $edge) {
            if (!($edge instanceof EdgeDirected)) {
                throw new UnexpectedValueException('Edge is undirected');
            }

            $flow = $edge->getFlow();
            if ($flow === NULL) {
                throw new UnexpectedValueException('Flow not set');
            }

            $capacity = $edge->getCapacity();
            if ($capacity === NULL) {
                throw new UnexpectedValueException('Capacity not set');
            }

            // capacity is still available, clone remaining capacity into new edge
            if ($this->keepNullCapacity || $flow < $capacity) {
                $newEdge = $newgraph->createEdgeClone($edge)->setFlow(0)->setCapacity($capacity - $flow);

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }

            // flow is set, clone current flow as capacity for back-flow into new inverted edge (opposite direction)
            if ($this->keepNullCapacity || $flow > 0) {
                $newEdge = $newgraph->createEdgeCloneInverted($edge)->setFlow(0)->setCapacity($flow);

                // if weight is set, use negative weight for back-edges
                if ($newEdge->getWeight() !== NULL) {
                    $newEdge->setWeight(-$newEdge->getWeight());
                }

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }
        }

        return $newgraph;
    }
public function createGraph()
    {
        $newgraph = $this->graph->createGraphCloneEdgeless();

        foreach ($this->graph->getEdges() as $edge) {
            if (!($edge instanceof EdgeDirected)) {
                throw new UnexpectedValueException('Edge is undirected');
            }

            $flow = $edge->getFlow();
            if ($flow === NULL) {
                throw new UnexpectedValueException('Flow not set');
            }

            $capacity = $edge->getCapacity();
            if ($capacity === NULL) {
                throw new UnexpectedValueException('Capacity not set');
            }

            // capacity is still available, clone remaining capacity into new edge
            if ($this->keepNullCapacity || $flow < $capacity) {
                $newEdge = $newgraph->createEdgeClone($edge)->setFlow(0)->setCapacity($capacity - $flow);

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }

            // flow is set, clone current flow as capacity for back-flow into new inverted edge (opposite direction)
            if ($this->keepNullCapacity || $flow > 0) {
                $newEdge = $newgraph->createEdgeCloneInverted($edge)->setFlow(0)->setCapacity($flow);

                // if weight is set, use negative weight for back-edges
                if ($newEdge->getWeight() !== NULL) {
                    $newEdge->setWeight(-$newEdge->getWeight());
                }

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }
        }

        return $newgraph;
    }
public function createGraph ( ) { $ newgraph = $ this -> graph -> createGraphCloneEdgeless ( ) ; foreach ( $ this -> graph -> getEdges ( ) as $ edge ) { if ( ! ( $ edge instanceof EdgeDirected ) ) { throw new UnexpectedValueException ( 'Edge is undirected' ) ; } $ flow = $ edge -> getFlow ( ) ; if ( $ flow === NULL ) { throw new UnexpectedValueException ( 'Flow not set' ) ; } $ capacity = $ edge -> getCapacity ( ) ; if ( $ capacity === NULL ) { throw new UnexpectedValueException ( 'Capacity not set' ) ; } // capacity is still available, clone remaining capacity into new edge if ( $ this -> keepNullCapacity || $ flow < $ capacity ) { $ newEdge = $ newgraph -> createEdgeClone ( $ edge ) -> setFlow ( 0 ) -> setCapacity ( $ capacity - $ flow ) ; if ( $ this -> mergeParallelEdges ) { $ this -> mergeParallelEdges ( $ newEdge ) ; } } // flow is set, clone current flow as capacity for back-flow into new inverted edge (opposite direction) if ( $ this -> keepNullCapacity || $ flow > 0 ) { $ newEdge = $ newgraph -> createEdgeCloneInverted ( $ edge ) -> setFlow ( 0 ) -> setCapacity ( $ flow ) ; // if weight is set, use negative weight for back-edges if ( $ newEdge -> getWeight ( ) !== NULL ) { $ newEdge -> setWeight ( - $ newEdge -> getWeight ( ) ) ; } if ( $ this -> mergeParallelEdges ) { $ this -> mergeParallelEdges ( $ newEdge ) ; } } } return $ newgraph ; }
create residual graph

@throws UnexpectedValueException if input graph has undirected edges or flow/capacity is not set
@return Graph
@uses Graph::createGraphCloneEdgeless()
@uses Graph::createEdgeClone()
@uses Graph::createEdgeCloneInverted()
create residual graph