Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/Fhaculty/Graph/Algorithm/DetectNegativeCycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use Fhaculty\Graph\Algorithm\BaseGraph;
use Fhaculty\Graph\Exception\UnderflowException;

use Fhaculty\Graph\Graph;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Walk;
use Fhaculty\Graph\Exception\NegativeCycleException;
use Fhaculty\Graph\Algorithm\ShortestPath\MooreBellmanFord as SpMooreBellmanFord;
use Fhaculty\Graph\Algorithm\ShortestPath\SingleSource\MooreBellmanFord;

class DetectNegativeCycle extends BaseGraph
{
Expand Down Expand Up @@ -41,18 +40,18 @@ public function hasCycleNegative()
*/
public function getCycleNegative()
{
$alg = new MooreBellmanFord();

// remember vertices already visited, as they can not lead to a new cycle
$verticesVisited = array();
// check for all vertices
foreach ($this->graph->getVertices()->getMap() as $vid => $vertex) {
// skip vertices already visited
if (!isset($verticesVisited[$vid])) {
// start MBF algorithm on current vertex
$alg = new SpMooreBellmanFord($vertex);

try {
// start MBF algorithm on current vertex
// try to get all connected vertices (or throw new cycle)
foreach ($alg->getVertices()->getIds() as $vid) {
foreach ($alg->createResult($vertex)->getVertices()->getIds() as $vid) {
// getting connected vertices succeeded, so skip over all of them
$verticesVisited[$vid] = true;
// no cycle found, check next vertex...
Expand Down
7 changes: 4 additions & 3 deletions lib/Fhaculty/Graph/Algorithm/MaxFlow/EdmondsKarp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Fhaculty\Graph\Exception\OutOfBoundsException;

use Fhaculty\Graph\Algorithm\ShortestPath\BreadthFirst;
use Fhaculty\Graph\Algorithm\ShortestPath\SingleSource\BreadthFirst;

use Fhaculty\Graph\Exception\InvalidArgumentException;

Expand Down Expand Up @@ -71,15 +71,16 @@ public function createGraph()
$idA = $this->startVertex->getId();
$idB = $this->destinationVertex->getId();

$alg = new BreadthFirst();

do {
// Generate new residual graph and repeat
$residualAlgorithm = new ResidualGraph($graphResult);
$graphResidual = $residualAlgorithm->createGraph();

// 1. Search _shortest_ (number of hops and cheapest) path from s -> t
$alg = new BreadthFirst($graphResidual->getVertex($idA));
try {
$pathFlow = $alg->getWalkTo($graphResidual->getVertex($idB));
$pathFlow = $alg->createResult($graphResidual->getVertex($idA))->getWalkTo($graphResidual->getVertex($idB));
} catch (OutOfBoundsException $e) {
$pathFlow = NULL;
}
Expand Down
287 changes: 0 additions & 287 deletions lib/Fhaculty/Graph/Algorithm/ShortestPath/Base.php

This file was deleted.

Loading