diff --git a/composer.json b/composer.json index 7168e87..847d31c 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.3", - "clue/graph": "~0.9.0|~0.8.0" + "graphp/graph": "dev-master#fb198e4 as 1.0.0" }, "require-dev": { "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" diff --git a/src/BaseDual.php b/src/BaseDual.php index 7cce143..14e42de 100644 --- a/src/BaseDual.php +++ b/src/BaseDual.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\DualAggregate; -use Fhaculty\Graph\Walk; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\DualAggregate; +use Graphp\Graph\Walk; /** * Abstract base class for algorithms that operate on a given Set instance diff --git a/src/BaseGraph.php b/src/BaseGraph.php index 41e6589..48558b7 100644 --- a/src/BaseGraph.php +++ b/src/BaseGraph.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Graph; +use Graphp\Graph\Graph; /** * Abstract base class for algorithms that operate on a given Graph instance diff --git a/src/BaseVertex.php b/src/BaseVertex.php index a59dd81..234a4e4 100644 --- a/src/BaseVertex.php +++ b/src/BaseVertex.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Vertex; /** * Abstract base class for algorithms that operate on a given Vertex instance diff --git a/src/Bipartit.php b/src/Bipartit.php index 8dbace8..6998e19 100644 --- a/src/Bipartit.php +++ b/src/Bipartit.php @@ -2,8 +2,8 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; class Bipartit extends BaseGraph { diff --git a/src/ConnectedComponents.php b/src/ConnectedComponents.php index a3d3319..be481bc 100644 --- a/src/ConnectedComponents.php +++ b/src/ConnectedComponents.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Search\BreadthFirst as SearchBreadthFirst; +use Graphp\Graph\Exception\InvalidArgumentException; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Graph; +use Graphp\Graph\Vertex; /** * Algorithm for working with connected components diff --git a/src/Degree.php b/src/Degree.php index 1e996be..51d1658 100644 --- a/src/Degree.php +++ b/src/Degree.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Vertex; /** * Basic algorithms for working with the degrees of Graphs. diff --git a/src/DetectNegativeCycle.php b/src/DetectNegativeCycle.php index b0aa43d..8bba20b 100644 --- a/src/DetectNegativeCycle.php +++ b/src/DetectNegativeCycle.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Exception\NegativeCycleException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Walk; use Graphp\Algorithms\ShortestPath\MooreBellmanFord as SpMooreBellmanFord; +use Graphp\Graph\Exception\NegativeCycleException; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Graph; +use Graphp\Graph\Walk; class DetectNegativeCycle extends BaseGraph { diff --git a/src/Directed.php b/src/Directed.php index fc43e9b..cf64e05 100644 --- a/src/Directed.php +++ b/src/Directed.php @@ -2,8 +2,8 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Edge\Undirected as EdgeUndirected; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\EdgeUndirected; /** * Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks. diff --git a/src/Flow.php b/src/Flow.php index 6156b3b..54868d1 100644 --- a/src/Flow.php +++ b/src/Flow.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Vertex; /** * Basic algorithms for working with flow graphs diff --git a/src/Groups.php b/src/Groups.php index 49fea41..4b12f60 100644 --- a/src/Groups.php +++ b/src/Groups.php @@ -2,8 +2,8 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; class Groups extends BaseGraph { diff --git a/src/Loop.php b/src/Loop.php index 6b72fad..30ace8e 100644 --- a/src/Loop.php +++ b/src/Loop.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Vertex; /** * Basic algorithms for working with loop edges diff --git a/src/MaxFlow/EdmondsKarp.php b/src/MaxFlow/EdmondsKarp.php index 5fb83f6..bf3aae8 100644 --- a/src/MaxFlow/EdmondsKarp.php +++ b/src/MaxFlow/EdmondsKarp.php @@ -2,17 +2,17 @@ namespace Graphp\Algorithms\MaxFlow; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Base; use Graphp\Algorithms\ResidualGraph; use Graphp\Algorithms\ShortestPath\BreadthFirst; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\Exception\InvalidArgumentException; +use Graphp\Graph\Exception\OutOfBoundsException; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; class EdmondsKarp extends Base { diff --git a/src/MaximumMatching/Base.php b/src/MaximumMatching/Base.php index 4e08779..db1d36e 100644 --- a/src/MaximumMatching/Base.php +++ b/src/MaximumMatching/Base.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\MaximumMatching; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; use Graphp\Algorithms\BaseGraph; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; abstract class Base extends BaseGraph { diff --git a/src/MaximumMatching/Flow.php b/src/MaximumMatching/Flow.php index 159bf1c..2345e43 100644 --- a/src/MaximumMatching/Flow.php +++ b/src/MaximumMatching/Flow.php @@ -2,12 +2,12 @@ namespace Graphp\Algorithms\MaximumMatching; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Directed; use Graphp\Algorithms\Groups; use Graphp\Algorithms\MaxFlow\EdmondsKarp as MaxFlowEdmondsKarp; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; class Flow extends Base { @@ -42,16 +42,16 @@ public function getEdges() if ($group === $groupA) { // group A: source - $superSource->createEdgeTo($vertex)->setCapacity(1)->setFlow(0); + $graphFlow->createEdgeDirected($superSource, $vertex)->setCapacity(1)->setFlow(0); // temporarily create edges from A->B for flow graph $originalVertex = $this->graph->getVertex($vertex->getId()); foreach ($originalVertex->getVerticesEdgeTo() as $vertexTarget) { - $vertex->createEdgeTo($graphFlow->getVertex($vertexTarget->getId()))->setCapacity(1)->setFlow(0); + $graphFlow->createEdgeDirected($vertex, $graphFlow->getVertex($vertexTarget->getId()))->setCapacity(1)->setFlow(0); } } else { // group B: sink - $vertex->createEdgeTo($superSink)->setCapacity(1)->setFlow(0); + $graphFlow->createEdgeDirected($vertex, $superSink)->setCapacity(1)->setFlow(0); } } diff --git a/src/MinimumCostFlow/Base.php b/src/MinimumCostFlow/Base.php index 875e3f9..a26b433 100644 --- a/src/MinimumCostFlow/Base.php +++ b/src/MinimumCostFlow/Base.php @@ -5,10 +5,10 @@ use Graphp\Algorithms\BaseGraph; use Graphp\Algorithms\Weight as AlgorithmWeight; use Graphp\Algorithms\Flow as AlgorithmFlow; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; abstract class Base extends BaseGraph { diff --git a/src/MinimumCostFlow/CycleCanceling.php b/src/MinimumCostFlow/CycleCanceling.php index 2e6a416..923ef50 100644 --- a/src/MinimumCostFlow/CycleCanceling.php +++ b/src/MinimumCostFlow/CycleCanceling.php @@ -2,12 +2,12 @@ namespace Graphp\Algorithms\MinimumCostFlow; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Edges; use Graphp\Algorithms\DetectNegativeCycle; use Graphp\Algorithms\MaxFlow\EdmondsKarp as MaxFlowEdmondsKarp; use Graphp\Algorithms\ResidualGraph; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Edges; class CycleCanceling extends Base { @@ -29,12 +29,12 @@ public function createGraph() if ($balance > 0) { // positive balance => source capacity - $superSource->createEdgeTo($vertex)->setCapacity($balance); + $resultGraph->createEdgeDirected($superSource, $vertex)->setCapacity($balance); $sumBalance += $balance; } elseif ($balance < 0) { // negative balance => sink capacity (positive) - $vertex->createEdgeTo($superSink)->setCapacity(-$balance); + $resultGraph->createEdgeDirected($vertex, $superSink)->setCapacity(-$balance); } } diff --git a/src/MinimumCostFlow/SuccessiveShortestPath.php b/src/MinimumCostFlow/SuccessiveShortestPath.php index 1e93a79..180b5e9 100644 --- a/src/MinimumCostFlow/SuccessiveShortestPath.php +++ b/src/MinimumCostFlow/SuccessiveShortestPath.php @@ -2,15 +2,15 @@ namespace Graphp\Algorithms\MinimumCostFlow; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\ResidualGraph; use Graphp\Algorithms\ShortestPath\MooreBellmanFord as SpMooreBellmanFord; use Graphp\Algorithms\Search\BreadthFirst as SearchBreadthFirst; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; class SuccessiveShortestPath extends Base { diff --git a/src/MinimumSpanningTree/Base.php b/src/MinimumSpanningTree/Base.php index c583a7c..54286ad 100644 --- a/src/MinimumSpanningTree/Base.php +++ b/src/MinimumSpanningTree/Base.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\MinimumSpanningTree; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; use Graphp\Algorithms\Base as AlgorithmBase; +use Graphp\Graph\Edge; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; use SplPriorityQueue; /** diff --git a/src/MinimumSpanningTree/Kruskal.php b/src/MinimumSpanningTree/Kruskal.php index 5ce3e22..7239dc7 100644 --- a/src/MinimumSpanningTree/Kruskal.php +++ b/src/MinimumSpanningTree/Kruskal.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\MinimumSpanningTree; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; +use Graphp\Graph\Edge; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; use SplPriorityQueue; class Kruskal extends Base diff --git a/src/MinimumSpanningTree/Prim.php b/src/MinimumSpanningTree/Prim.php index 99de0e9..9d5511d 100644 --- a/src/MinimumSpanningTree/Prim.php +++ b/src/MinimumSpanningTree/Prim.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\MinimumSpanningTree; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Edge; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; use SplPriorityQueue; class Prim extends Base diff --git a/src/Parallel.php b/src/Parallel.php index a2983c8..e990124 100644 --- a/src/Parallel.php +++ b/src/Parallel.php @@ -2,10 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Edge\Directed as DirectedEdge; -use Fhaculty\Graph\Set\Edges; -use LogicException; +use Graphp\Graph\Edge; +use Graphp\Graph\EdgeDirected as EdgeDirected; +use Graphp\Graph\Set\Edges; /** * Basic algorithms for working with parallel edges @@ -52,11 +51,10 @@ public function hasEdgeParallelEdge(Edge $edge) * * @param Edge $edge * @return Edges - * @throws LogicException */ public function getEdgesParallelEdge(Edge $edge) { - if ($edge instanceof DirectedEdge) { + if ($edge instanceof EdgeDirected) { // get all edges between this edge's endpoints $edges = $edge->getVertexStart()->getEdgesTo($edge->getVertexEnd())->getVector(); } else { diff --git a/src/Property/WalkProperty.php b/src/Property/WalkProperty.php index a699f79..5c5d26c 100644 --- a/src/Property/WalkProperty.php +++ b/src/Property/WalkProperty.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms\Property; -use Fhaculty\Graph\Walk; use Graphp\Algorithms\Base as BaseAlgorithm; use Graphp\Algorithms\Loop as AlgorithmLoop; +use Graphp\Graph\Walk; /** * Simple algorithms for working with Walk properties diff --git a/src/ResidualGraph.php b/src/ResidualGraph.php index 676b2a0..32bb2d8 100644 --- a/src/ResidualGraph.php +++ b/src/ResidualGraph.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; +use Graphp\Graph\Edge; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; class ResidualGraph extends BaseGraph { diff --git a/src/Search/Base.php b/src/Search/Base.php index a979c45..968ebde 100644 --- a/src/Search/Base.php +++ b/src/Search/Base.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\Search; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\BaseVertex; +use Graphp\Graph\Exception\InvalidArgumentException; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; abstract class Base extends BaseVertex { diff --git a/src/Search/BreadthFirst.php b/src/Search/BreadthFirst.php index 818ab6a..8a33284 100644 --- a/src/Search/BreadthFirst.php +++ b/src/Search/BreadthFirst.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms\Search; -use Fhaculty\Graph\Set\Vertices; +use Graphp\Graph\Set\Vertices; class BreadthFirst extends Base { diff --git a/src/Search/DepthFirst.php b/src/Search/DepthFirst.php index 8276081..6b9d566 100644 --- a/src/Search/DepthFirst.php +++ b/src/Search/DepthFirst.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms\Search; -use Fhaculty\Graph\Set\Vertices; +use Graphp\Graph\Set\Vertices; class DepthFirst extends Base { diff --git a/src/ShortestPath/Base.php b/src/ShortestPath/Base.php index c6dd5b4..e095661 100644 --- a/src/ShortestPath/Base.php +++ b/src/ShortestPath/Base.php @@ -2,15 +2,15 @@ namespace Graphp\Algorithms\ShortestPath; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Walk; use Graphp\Algorithms\BaseVertex; +use Graphp\Graph\Edge; +use Graphp\Graph\Exception\InvalidArgumentException; +use Graphp\Graph\Exception\OutOfBoundsException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; +use Graphp\Graph\Walk; /** * Abstract base class for shortest path algorithms diff --git a/src/ShortestPath/BreadthFirst.php b/src/ShortestPath/BreadthFirst.php index de55dfe..4984a9b 100644 --- a/src/ShortestPath/BreadthFirst.php +++ b/src/ShortestPath/BreadthFirst.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\ShortestPath; -use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Set\Vertices; +use Graphp\Graph\Vertex; +use Graphp\Graph\Exception\OutOfBoundsException; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Set\Vertices; /** * Simple breadth-first shortest path algorithm diff --git a/src/ShortestPath/Dijkstra.php b/src/ShortestPath/Dijkstra.php index fc19104..7ce264c 100644 --- a/src/ShortestPath/Dijkstra.php +++ b/src/ShortestPath/Dijkstra.php @@ -2,8 +2,8 @@ namespace Graphp\Algorithms\ShortestPath; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Edges; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Edges; use SplPriorityQueue; /** diff --git a/src/ShortestPath/MooreBellmanFord.php b/src/ShortestPath/MooreBellmanFord.php index 8a2664a..0ce1f9b 100644 --- a/src/ShortestPath/MooreBellmanFord.php +++ b/src/ShortestPath/MooreBellmanFord.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms\ShortestPath; -use Fhaculty\Graph\Exception\NegativeCycleException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Walk; +use Graphp\Graph\Exception\NegativeCycleException; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; +use Graphp\Graph\Walk; /** * Moore-Bellman-Ford's shortest path algorithm diff --git a/src/Symmetric.php b/src/Symmetric.php index 57401cc..3e37930 100644 --- a/src/Symmetric.php +++ b/src/Symmetric.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; +use Graphp\Graph\EdgeDirected; /** * Basic algorithms for working with symmetric digraphs diff --git a/src/TopologicalSort.php b/src/TopologicalSort.php index 160391e..c9ad690 100644 --- a/src/TopologicalSort.php +++ b/src/TopologicalSort.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; /** * topological sorting / order, also known as toposort / topsort, commonly used in resolving dependencies diff --git a/src/TransposeGraph.php b/src/TransposeGraph.php index 28d61f4..eeaeedb 100644 --- a/src/TransposeGraph.php +++ b/src/TransposeGraph.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Graph; +use Graphp\Graph\EdgeDirected; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Graph; class TransposeGraph extends BaseGraph { diff --git a/src/TravelingSalesmanProblem/Base.php b/src/TravelingSalesmanProblem/Base.php index bf888bc..3fa9822 100644 --- a/src/TravelingSalesmanProblem/Base.php +++ b/src/TravelingSalesmanProblem/Base.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms\TravelingSalesmanProblem; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Walk; use Graphp\Algorithms\Base as AlgorithmBase; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; +use Graphp\Graph\Walk; abstract class Base extends AlgorithmBase { diff --git a/src/TravelingSalesmanProblem/Bruteforce.php b/src/TravelingSalesmanProblem/Bruteforce.php index b390794..40a3e65 100644 --- a/src/TravelingSalesmanProblem/Bruteforce.php +++ b/src/TravelingSalesmanProblem/Bruteforce.php @@ -2,13 +2,13 @@ namespace Graphp\Algorithms\TravelingSalesmanProblem; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\TravelingSalesmanProblem\MinimumSpanningTree as AlgorithmTspMst; +use Graphp\Graph\Edge; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; class Bruteforce extends Base { diff --git a/src/TravelingSalesmanProblem/MinimumSpanningTree.php b/src/TravelingSalesmanProblem/MinimumSpanningTree.php index 765b727..c273c83 100644 --- a/src/TravelingSalesmanProblem/MinimumSpanningTree.php +++ b/src/TravelingSalesmanProblem/MinimumSpanningTree.php @@ -2,10 +2,10 @@ namespace Graphp\Algorithms\TravelingSalesmanProblem; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Edges; use Graphp\Algorithms\MinimumSpanningTree\Kruskal as MstKruskal; use Graphp\Algorithms\Search\BreadthFirst as SearchDepthFirst; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Edges; class MinimumSpanningTree extends Base { diff --git a/src/TravelingSalesmanProblem/NearestNeighbor.php b/src/TravelingSalesmanProblem/NearestNeighbor.php index e439a74..4fde28c 100644 --- a/src/TravelingSalesmanProblem/NearestNeighbor.php +++ b/src/TravelingSalesmanProblem/NearestNeighbor.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms\TravelingSalesmanProblem; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Vertex; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Edges; +use Graphp\Graph\Vertex; use SplPriorityQueue; class NearestNeighbor extends Base diff --git a/src/Tree/Base.php b/src/Tree/Base.php index 0b564c6..6222102 100644 --- a/src/Tree/Base.php +++ b/src/Tree/Base.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms\Tree; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\BaseGraph; use Graphp\Algorithms\Degree; +use Graphp\Graph\Graph; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; /** * Abstract base class for tree algorithms diff --git a/src/Tree/BaseDirected.php b/src/Tree/BaseDirected.php index a7ff050..eecbd36 100644 --- a/src/Tree/BaseDirected.php +++ b/src/Tree/BaseDirected.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms\Tree; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Tree\Base as Tree; +use Graphp\Graph\Exception\UnderflowException; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; /** * Abstract algorithm base class for working with directed, rooted trees diff --git a/src/Tree/InTree.php b/src/Tree/InTree.php index 68160ef..8372deb 100644 --- a/src/Tree/InTree.php +++ b/src/Tree/InTree.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms\Tree; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Tree\BaseDirected as DirectedTree; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Vertex; /** * Alternative InTree implementation where Edges "point towards" root Vertex diff --git a/src/Tree/OutTree.php b/src/Tree/OutTree.php index 2a8a5ee..ccebee0 100644 --- a/src/Tree/OutTree.php +++ b/src/Tree/OutTree.php @@ -2,9 +2,9 @@ namespace Graphp\Algorithms\Tree; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Tree\BaseDirected as DirectedTree; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Vertex; /** * Usual OutTree implementation where Edges "point away" from root Vertex diff --git a/src/Tree/Undirected.php b/src/Tree/Undirected.php index d637dad..b1bb8db 100644 --- a/src/Tree/Undirected.php +++ b/src/Tree/Undirected.php @@ -2,11 +2,11 @@ namespace Graphp\Algorithms\Tree; -use Fhaculty\Graph\Edge\Undirected as UndirectedEdge; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Vertex; use Graphp\Algorithms\Tree\Base as Tree; +use Graphp\Graph\EdgeUndirected; +use Graphp\Graph\Exception\UnexpectedValueException; +use Graphp\Graph\Set\Vertices; +use Graphp\Graph\Vertex; /** * Undirected tree implementation @@ -133,7 +133,7 @@ private function getVerticesNeighbor(Vertex $vertex) { $vertices = array(); foreach ($vertex->getEdges() as $edge) { - if (!$edge instanceof UndirectedEdge) { + if (!$edge instanceof EdgeUndirected) { throw new UnexpectedValueException('Directed edge encountered'); } $vertices[] = $edge->getVertexToFrom($vertex); diff --git a/src/Weight.php b/src/Weight.php index 2de7be0..47c2455 100644 --- a/src/Weight.php +++ b/src/Weight.php @@ -2,7 +2,7 @@ namespace Graphp\Algorithms; -use Fhaculty\Graph\Graph; +use Graphp\Graph\Graph; /** * Basic algorithms for working with the (total) weight of a Graph/Walk diff --git a/tests/BipartitTest.php b/tests/BipartitTest.php index 1c36fd8..4534b0c 100644 --- a/tests/BipartitTest.php +++ b/tests/BipartitTest.php @@ -1,7 +1,7 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2); + $graph->createEdgeDirected($v1, $v2); $alg = new AlgorithmBipartit($graph); @@ -46,7 +46,7 @@ public function testGraphPairBipartitGroups(AlgorithmBipartit $alg) // create a cloned graph with groups assigned according to bipartition $graph = $alg->createGraphGroups(); - $this->assertInstanceOf('Fhaculty\Graph\Graph', $graph); + $this->assertInstanceOf('Graphp\Graph\Graph', $graph); $alg2 = new AlgorithmBipartit($graph); $this->assertTrue($alg2->isBipartitGroups()); @@ -59,9 +59,9 @@ public function testGraphTriangleCycleIsNotBipartit() $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v1->createEdgeTo($v2); - $v2->createEdgeTo($v3); - $v3->createEdgeTo($v1); + $graph->createEdgeDirected($v1, $v2); + $graph->createEdgeDirected($v2, $v3); + $graph->createEdgeDirected($v3, $v1); $alg = new AlgorithmBipartit($graph); diff --git a/tests/CompleteTest.php b/tests/CompleteTest.php index db69608..4a2ce01 100644 --- a/tests/CompleteTest.php +++ b/tests/CompleteTest.php @@ -1,7 +1,7 @@ createVertex(1)->createEdge($graph->createVertex(2)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmComplete($graph); @@ -39,7 +39,7 @@ public function testGraphSingleDirectedIsNotComplete() { // 1 -> 2 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmComplete($graph); @@ -53,10 +53,10 @@ public function testAdditionalEdgesToNotAffectCompleteness() // 2 -> 1 // 1 -> 1 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); - $graph->getVertex(1)->createEdge($graph->getVertex(2)); - $graph->getVertex(2)->createEdgeTo($graph->getVertex(1)); - $graph->getVertex(1)->createEdgeTo($graph->getVertex(1)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); + $graph->createEdgeUndirected($graph->getVertex(1), $graph->getVertex(2)); + $graph->createEdgeDirected($graph->getVertex(2), $graph->getVertex(1)); + $graph->createEdgeDirected($graph->getVertex(1), $graph->getVertex(1)); $alg = new AlgorithmComplete($graph); diff --git a/tests/ConnectedComponentsTest.php b/tests/ConnectedComponentsTest.php index 46a0fb6..55f293d 100644 --- a/tests/ConnectedComponentsTest.php +++ b/tests/ConnectedComponentsTest.php @@ -1,7 +1,7 @@ 3 <- 4 $graph = new Graph(); - $graph->createVertex(1)->createEdge($graph->createVertex(2)); - $graph->getVertex(2)->createEdgeTo($graph->createVertex(3)); - $graph->createVertex(4)->createEdgeTo($graph->getVertex(3)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); + $graph->createEdgeDirected($graph->getVertex(2), $graph->createVertex(3)); + $graph->createEdgeDirected($graph->createVertex(4), $graph->getVertex(3)); $alg = new AlgorithmConnected($graph); @@ -61,8 +61,8 @@ public function testComponents() $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); $v5 = $graph->createVertex(5); - $v1->createEdge($v2); - $v3->createEdgeTo($v4); + $graph->createEdgeUndirected($v1, $v2); + $graph->createEdgeDirected($v3, $v4); $alg = new AlgorithmConnected($graph); @@ -73,7 +73,7 @@ public function testComponents() $this->assertCount(3, $graphs); $ge = new Graph(); - $ge->createVertex(1)->createEdge($ge->createVertex(2)); + $ge->createEdgeUndirected($ge->createVertex(1), $ge->createVertex(2)); $this->assertGraphEquals($ge, $alg->createGraphComponentVertex($v2)); $ge = new Graph(); diff --git a/tests/DegreeTest.php b/tests/DegreeTest.php index 526eda4..095ca5f 100644 --- a/tests/DegreeTest.php +++ b/tests/DegreeTest.php @@ -1,9 +1,9 @@ createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v1->createEdgeTo($v2); - $v2->createEdgeTo($v3); + $graph->createEdgeDirected($v1, $v2); + $graph->createEdgeDirected($v2, $v3); $alg = new AlgorithmDegree($graph); diff --git a/tests/DetectNegativeCycleTest.php b/tests/DetectNegativeCycleTest.php index 7065946..3f90b09 100644 --- a/tests/DetectNegativeCycleTest.php +++ b/tests/DetectNegativeCycleTest.php @@ -1,7 +1,7 @@ 1 $graph = new Graph(); $v1 = $graph->createVertex(1); - $e1 = $v1->createEdgeTo($v1)->setWeight(-1); + $e1 = $graph->createEdgeDirected($v1, $v1)->setWeight(-1); $alg = new DetectNegativeCycle($graph); @@ -65,8 +65,8 @@ public function testNegativeCycle() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setWeight(-1); - $v2->createEdgeTo($v1)->setWeight(-2); + $graph->createEdgeDirected($v1, $v2)->setWeight(-1); + $graph->createEdgeDirected($v2, $v1)->setWeight(-2); $alg = new DetectNegativeCycle($graph); @@ -84,7 +84,7 @@ public function testNegativeUndirectedIsNegativeCycle() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2)->setWeight(-1); + $graph->createEdgeUndirected($v1, $v2)->setWeight(-1); $alg = new DetectNegativeCycle($graph); @@ -106,10 +106,10 @@ public function testNegativeCycleSubgraph() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); - $v1->createEdgeTo($v2)->setWeight(1); - $v2->createEdgeTo($v3)->setWeight(1); - $v3->createEdgeTo($v4)->setWeight(1); - $v4->createEdgeTo($v3)->setWeight(-2); + $graph->createEdgeDirected($v1, $v2)->setWeight(1); + $graph->createEdgeDirected($v2, $v3)->setWeight(1); + $graph->createEdgeDirected($v3, $v4)->setWeight(1); + $graph->createEdgeDirected($v4, $v3)->setWeight(-2); $alg = new DetectNegativeCycle($graph); @@ -133,9 +133,9 @@ public function testNegativeComponents() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); - $v1->createEdge($v2); - $v3->createEdgeTo($v4)->setWeight(-1); - $v4->createEdgeTo($v3)->setWeight(-2); + $graph->createEdgeUndirected($v1, $v2); + $graph->createEdgeDirected($v3, $v4)->setWeight(-1); + $graph->createEdgeDirected($v4, $v3)->setWeight(-2); $alg = new DetectNegativeCycle($graph); diff --git a/tests/DirectedTest.php b/tests/DirectedTest.php index d5a1ef8..321f026 100644 --- a/tests/DirectedTest.php +++ b/tests/DirectedTest.php @@ -1,7 +1,7 @@ createVertex(1)->createEdge($graph->createVertex(2)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmDirected($graph); @@ -33,7 +33,7 @@ public function testGraphDirected() { // 1 -> 2 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmDirected($graph); @@ -46,8 +46,8 @@ public function testGraphMixed() { // 1 -- 2 -> 3 $graph = new Graph(); - $graph->createVertex(1)->createEdge($graph->createVertex(2)); - $graph->getVertex(2)->createEdgeTo($graph->createVertex(3)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); + $graph->createEdgeDirected($graph->getVertex(2), $graph->createVertex(3)); $alg = new AlgorithmDirected($graph); diff --git a/tests/EulerianTest.php b/tests/EulerianTest.php index 8690630..5ab2ec9 100644 --- a/tests/EulerianTest.php +++ b/tests/EulerianTest.php @@ -1,7 +1,7 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2); + $graph->createEdgeUndirected($v1, $v2); $alg = new AlgorithmEulerian($graph); @@ -34,9 +34,9 @@ public function testGraphTriangleCycleIsNotBipartit() $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v1->createEdge($v2); - $v2->createEdge($v3); - $v3->createEdge($v1); + $graph->createEdgeUndirected($v1, $v2); + $graph->createEdgeUndirected($v2, $v3); + $graph->createEdgeUndirected($v3, $v1); $alg = new AlgorithmEulerian($graph); diff --git a/tests/FlowTest.php b/tests/FlowTest.php index db7d003..7e2ebaf 100644 --- a/tests/FlowTest.php +++ b/tests/FlowTest.php @@ -1,7 +1,7 @@ 2 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2))->setFlow(0); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(0); $alg = new AlgorithmFlow($graph); @@ -40,7 +40,7 @@ public function testEdgeWithZeroFlowIsConsideredFlow() public function testGraphSimple(Graph $graph) { // 1 -> 2 - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmFlow($graph); @@ -59,7 +59,7 @@ public function testGraphSimple(Graph $graph) public function testGraphWithUnweightedEdges(Graph $graph) { // additional flow edge: 2 -> 3 - $graph->getVertex(2)->createEdgeTo($graph->createVertex(3))->setFlow(10); + $graph->createEdgeDirected($graph->getVertex(2), $graph->createVertex(3))->setFlow(10); $alg = new AlgorithmFlow($graph); @@ -88,7 +88,7 @@ public function testVertexWithUndirectedEdgeHasInvalidFlow() { // 1 -- 2 $graph = new Graph(); - $graph->createVertex(1)->createEdge($graph->createVertex(2))->setFlow(10); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(10); $alg = new AlgorithmFlow($graph); diff --git a/tests/GroupsTest.php b/tests/GroupsTest.php index 8ce1c6d..5ee6311 100644 --- a/tests/GroupsTest.php +++ b/tests/GroupsTest.php @@ -1,7 +1,7 @@ createVertex(1)->setGroup(1); $v2 = $graph->createVertex(2)->setGroup(2); - $v1->createEdgeTo($v2); + $graph->createEdgeDirected($v1, $v2); $alg = new AlgorithmGroups($graph); @@ -45,9 +45,9 @@ public function testGraphTriangleCycleIsNotBipartit() $v1 = $graph->createVertex(1)->setGroup(1); $v2 = $graph->createVertex(2)->setGroup(2); $v3 = $graph->createVertex(3)->setGroup(1); - $v1->createEdgeTo($v2); - $v2->createEdgeTo($v3); - $v3->createEdgeTo($v1); + $graph->createEdgeDirected($v1, $v2); + $graph->createEdgeDirected($v2, $v3); + $graph->createEdgeDirected($v3, $v1); $alg = new AlgorithmGroups($graph); diff --git a/tests/LoopTest.php b/tests/LoopTest.php index 019c3d7..a9309b8 100644 --- a/tests/LoopTest.php +++ b/tests/LoopTest.php @@ -1,7 +1,7 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2); - $v2->createEdge($v1); + $graph->createEdgeDirected($v1, $v2); + $graph->createEdgeUndirected($v2, $v1); $alg = new AlgorithmLoop($graph); @@ -35,7 +35,7 @@ public function testGraphUndirectedLoop() { // 1 -- 1 $graph = new Graph(); - $graph->createVertex(1)->createEdge($v1 = $graph->getVertex(1)); + $graph->createEdgeUndirected($graph->createVertex(1), $v1 = $graph->getVertex(1)); $alg = new AlgorithmLoop($graph); @@ -47,7 +47,7 @@ public function testGraphDirectedLoop() { // 1 -> 1 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($v1 = $graph->getVertex(1)); + $graph->createEdgeDirected($graph->createVertex(1), $v1 = $graph->getVertex(1)); $alg = new AlgorithmLoop($graph); diff --git a/tests/MaxFlow/EdmondsKarpTest.php b/tests/MaxFlow/EdmondsKarpTest.php index 901069f..7c93a1c 100644 --- a/tests/MaxFlow/EdmondsKarpTest.php +++ b/tests/MaxFlow/EdmondsKarpTest.php @@ -1,7 +1,7 @@ createVertex(0); $v1 = $graph->createVertex(1); - $v0->createEdgeTo($v1)->setCapacity(10); + $graph->createEdgeDirected($v0, $v1)->setCapacity(10); // 0 -[10/10]-> 1 $alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1); @@ -32,9 +32,9 @@ public function testEdgesMultiplePaths() $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v0->createEdgeTo($v1)->setCapacity(5); - $v0->createEdgeTo($v2)->setCapacity(7); - $v2->createEdgeTo($v1)->setCapacity(9); + $graph->createEdgeDirected($v0, $v1)->setCapacity(5); + $graph->createEdgeDirected($v0, $v2)->setCapacity(7); + $graph->createEdgeDirected($v2, $v1)->setCapacity(9); // 0 -[5/5]---------> 1 // | ^ @@ -59,11 +59,11 @@ public function testEdgesMultiplePathsTwo() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v0->createEdgeTo($v1)->setCapacity(5); - $v0->createEdgeTo($v2)->setCapacity(7); - $v2->createEdgeTo($v1)->setCapacity(9); - $v1->createEdgeTo($v3)->setCapacity(10); - $v3->createEdgeTo($v2)->setCapacity(2); + $graph->createEdgeDirected($v0, $v1)->setCapacity(5); + $graph->createEdgeDirected($v0, $v2)->setCapacity(7); + $graph->createEdgeDirected($v2, $v1)->setCapacity(9); + $graph->createEdgeDirected($v1, $v3)->setCapacity(10); + $graph->createEdgeDirected($v3, $v2)->setCapacity(2); $alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v3); @@ -82,11 +82,11 @@ public function testEdgesMultiplePathsTree() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v0->createEdgeTo($v1)->setCapacity(4); - $v0->createEdgeTo($v2)->setCapacity(2); - $v1->createEdgeTo($v2)->setCapacity(3); - $v1->createEdgeTo($v3)->setCapacity(1); - $v2->createEdgeTo($v3)->setCapacity(6); + $graph->createEdgeDirected($v0, $v1)->setCapacity(4); + $graph->createEdgeDirected($v0, $v2)->setCapacity(2); + $graph->createEdgeDirected($v1, $v2)->setCapacity(3); + $graph->createEdgeDirected($v1, $v3)->setCapacity(1); + $graph->createEdgeDirected($v2, $v3)->setCapacity(6); $alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v3); @@ -98,8 +98,8 @@ public function testEdgesMultiplePathsTree() // $v0 = $graph->createVertex(0); // $v1 = $graph->createVertex(1); -// $v0->createEdgeTo($v1)->setCapacity(3.4); -// $v0->createEdgeTo($v1)->setCapacity(6.6); +// $graph->createEdgeDirected($v0, $v1)->setCapacity(3.4); +// $graph->createEdgeDirected($v0, $v1)->setCapacity(6.6); // $alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1); @@ -116,7 +116,7 @@ public function testEdgesUndirected() $v0 = $graph->createVertex(0); $v1 = $graph->createVertex(1); - $v1->createEdge($v0)->setCapacity(7); + $graph->createEdgeUndirected($v1, $v0)->setCapacity(7); // 0 -[7/7]- 1 $alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1); diff --git a/tests/MaximumMatching/FlowTest.php b/tests/MaximumMatching/FlowTest.php index 256c2b1..652fa53 100644 --- a/tests/MaximumMatching/FlowTest.php +++ b/tests/MaximumMatching/FlowTest.php @@ -1,7 +1,7 @@ createVertex(0)->setGroup(0)->createEdge($graph->createVertex(1)->setGroup(1)); + $edge = $graph->createEdgeUndirected($graph->createVertex(0)->setGroup(0), $graph->createVertex(1)->setGroup(1)); $alg = new Flow($graph); // correct number of edges @@ -32,7 +32,7 @@ public function testSingleEdge() // check $flowgraph = $alg->createGraph(); - $this->assertInstanceOf('Fhaculty\Graph\Graph', $flowgraph); + $this->assertInstanceOf('Graphp\Graph\Graph', $flowgraph); } /** @@ -42,7 +42,7 @@ public function testSingleEdge() public function testInvalidDirected() { $graph = new Graph(); - $graph->createVertex(0)->setGroup(0)->createEdgeTo($graph->createVertex(1)->setGroup(1)); + $graph->createEdgeDirected($graph->createVertex(0)->setGroup(0), $graph->createVertex(1)->setGroup(1)); $alg = new Flow($graph); $alg->getNumberOfMatches(); @@ -55,7 +55,7 @@ public function testInvalidDirected() public function testInvalidBipartit() { $graph = new Graph(); - $graph->createVertex(0)->setGroup(1)->createEdge($graph->createVertex(1)->setGroup(1)); + $graph->createEdgeUndirected($graph->createVertex(0)->setGroup(1), $graph->createVertex(1)->setGroup(1)); $alg = new Flow($graph); $alg->getNumberOfMatches(); diff --git a/tests/MinimumCostFlow/BaseMcfTest.php b/tests/MinimumCostFlow/BaseMcfTest.php index 778305b..aef3aa5 100644 --- a/tests/MinimumCostFlow/BaseMcfTest.php +++ b/tests/MinimumCostFlow/BaseMcfTest.php @@ -1,7 +1,7 @@ createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-2); - $v1->createEdgeTo($v2)->setWeight(2)->setCapacity(2); + $graph->createEdgeDirected($v1, $v2)->setWeight(2)->setCapacity(2); $alg = $this->createAlgorithm($graph); $this->assertEquals(4, $alg->getWeightFlow()); // 2x2 @@ -49,8 +49,8 @@ public function testMultipleSinks() $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-1); $v3 = $graph->createVertex(3)->setBalance(-1); - $v1->createEdgeTo($v2)->setWeight(2)->setCapacity(2); - $v1->createEdgeTo($v3)->setWeight(-5)->setCapacity(4); + $graph->createEdgeDirected($v1, $v2)->setWeight(2)->setCapacity(2); + $graph->createEdgeDirected($v1, $v3)->setWeight(-5)->setCapacity(4); $alg = $this->createAlgorithm($graph); $this->assertEquals(-3, $alg->getWeightFlow()); // 1*2 + 1*-5 @@ -65,10 +65,10 @@ public function testIntermediaryVertices() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4)->setBalance(-2); - $v1->createEdgeTo($v2)->setWeight(4)->setCapacity(1); - $v2->createEdgeTo($v4)->setWeight(-2)->setCapacity(6); - $v1->createEdgeTo($v3)->setWeight(5)->setCapacity(4); - $v3->createEdgeTo($v4)->setWeight(8)->setCapacity(6); + $graph->createEdgeDirected($v1, $v2)->setWeight(4)->setCapacity(1); + $graph->createEdgeDirected($v2, $v4)->setWeight(-2)->setCapacity(6); + $graph->createEdgeDirected($v1, $v3)->setWeight(5)->setCapacity(4); + $graph->createEdgeDirected($v3, $v4)->setWeight(8)->setCapacity(6); $alg = $this->createAlgorithm($graph); $this->assertEquals(15, $alg->getWeightFlow()); // 1*4 + 1*-2 + 1*5 + 1*8 @@ -82,9 +82,9 @@ public function testEdgeCapacities() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4)->setBalance(-2); - $v1->createEdgeTo($v2)->setWeight(4)->setCapacity(3); - $v2->createEdgeTo($v3)->setWeight(5)->setCapacity(4); - $v3->createEdgeTo($v4)->setWeight(-2)->setCapacity(6); + $graph->createEdgeDirected($v1, $v2)->setWeight(4)->setCapacity(3); + $graph->createEdgeDirected($v2, $v3)->setWeight(5)->setCapacity(4); + $graph->createEdgeDirected($v3, $v4)->setWeight(-2)->setCapacity(6); $alg = $this->createAlgorithm($graph); $this->assertEquals(14, $alg->getWeightFlow()); // 2*4 + 2*5 + 2*-2 @@ -102,11 +102,11 @@ public function testEdgeFlows() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4)->setBalance(-4); - $v1->createEdgeTo($v2)->setFlow(3)->setCapacity(4)->setWeight(2); - $v2->createEdgeTo($v4)->setFlow(3)->setCapacity(3)->setWeight(3); - $v1->createEdgeTo($v3)->setFlow(1)->setCapacity(2)->setWeight(2); - $v3->createEdgeTo($v4)->setFlow(1)->setCapacity(5)->setWeight(1); - $v2->createEdgeTo($v3)->setFlow(0)->setCapacity(2)->setWeight(1); + $graph->createEdgeDirected($v1, $v2)->setFlow(3)->setCapacity(4)->setWeight(2); + $graph->createEdgeDirected($v2, $v4)->setFlow(3)->setCapacity(3)->setWeight(3); + $graph->createEdgeDirected($v1, $v3)->setFlow(1)->setCapacity(2)->setWeight(2); + $graph->createEdgeDirected($v3, $v4)->setFlow(1)->setCapacity(5)->setWeight(1); + $graph->createEdgeDirected($v2, $v3)->setFlow(0)->setCapacity(2)->setWeight(1); $alg = $this->createAlgorithm($graph); $this->assertEquals(14, $alg->getWeightFlow()); // 4*1 + 2*2 + 2*1 + 2*2 @@ -121,7 +121,7 @@ public function testEdgeCapacityInsufficientFails() $graph = new Graph(); $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-2); - $v1->createEdgeTo($v2)->setCapacity(1); + $graph->createEdgeDirected($v1, $v2)->setCapacity(1); $alg = $this->createAlgorithm($graph); $alg->getWeightFlow(); @@ -136,7 +136,7 @@ public function testEdgeCapacityUnsetFails() $graph = new Graph(); $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-2); - $v1->createEdgeTo($v2); + $graph->createEdgeDirected($v1, $v2); $alg = $this->createAlgorithm($graph); $alg->getWeightFlow(); @@ -165,7 +165,7 @@ public function testUnbalancedFails() $graph = new Graph(); $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-3); - $v1->createEdgeTo($v2)->setCapacity(3); + $graph->createEdgeDirected($v1, $v2)->setCapacity(3); $alg = $this->createAlgorithm($graph); $alg->getWeightFlow(); @@ -180,7 +180,7 @@ public function testUndirectedFails() $graph = new Graph(); $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-2); - $v1->createEdge($v2)->setCapacity(2); + $graph->createEdgeUndirected($v1, $v2)->setCapacity(2); $alg = $this->createAlgorithm($graph); $alg->getWeightFlow(); @@ -195,7 +195,7 @@ public function testUndirectedNegativeCycleFails() $graph = new Graph(); $v1 = $graph->createVertex(1)->setBalance(2); $v2 = $graph->createVertex(2)->setBalance(-2); - $v1->createEdge($v2)->setCapacity(2)->setWeight(-1); + $graph->createEdgeUndirected($v1, $v2)->setCapacity(2)->setWeight(-1); $alg = $this->createAlgorithm($graph); $alg->getWeightFlow(); diff --git a/tests/MinimumCostFlow/CycleCancellingTest.php b/tests/MinimumCostFlow/CycleCancellingTest.php index d6aca10..841fc1a 100644 --- a/tests/MinimumCostFlow/CycleCancellingTest.php +++ b/tests/MinimumCostFlow/CycleCancellingTest.php @@ -1,7 +1,7 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2)->setWeight(3); + $graph->createEdgeUndirected($v1, $v2)->setWeight(3); $alg = $this->createAlg($v1); @@ -50,10 +50,10 @@ public function testSimpleGraph() $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); $v5 = $graph->createVertex(5); - $v1->createEdge($v2)->setWeight(6); - $v2->createEdge($v3)->setWeight(9); - $v3->createEdge($v4)->setWeight(7); - $v4->createEdge($v5)->setWeight(8); + $graph->createEdgeUndirected($v1, $v2)->setWeight(6); + $graph->createEdgeUndirected($v2, $v3)->setWeight(9); + $graph->createEdgeUndirected($v3, $v4)->setWeight(7); + $graph->createEdgeUndirected($v4, $v5)->setWeight(8); $alg = $this->createAlg($v1); @@ -71,9 +71,9 @@ public function testFindingCheapestEdge() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2)->setWeight(4); - $v1->createEdge($v2)->setWeight(3); - $v1->createEdge($v2)->setWeight(5); + $graph->createEdgeUndirected($v1, $v2)->setWeight(4); + $graph->createEdgeUndirected($v1, $v2)->setWeight(3); + $graph->createEdgeUndirected($v1, $v2)->setWeight(5); $alg = $this->createAlg($v1); $edges = $alg->getEdges(); @@ -92,17 +92,17 @@ public function testFindingCheapestTree() $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $v1->createEdge($v2)->setWeight(4); - $v2->createEdge($v3)->setWeight(5); - $v3->createEdge($v1)->setWeight(6); + $graph->createEdgeUndirected($v1, $v2)->setWeight(4); + $graph->createEdgeUndirected($v2, $v3)->setWeight(5); + $graph->createEdgeUndirected($v3, $v1)->setWeight(6); // 1 --[4]-- 2 -- [5] -- 3 $graphExpected = new Graph(); $ve1 = $graphExpected->createVertex(1); $ve2 = $graphExpected->createVertex(2); $ve3 = $graphExpected->createVertex(3); - $ve1->createEdge($ve2)->setWeight(4); - $ve2->createEdge($ve3)->setWeight(5); + $graphExpected->createEdgeUndirected($ve1, $ve2)->setWeight(4); + $graphExpected->createEdgeUndirected($ve2, $ve3)->setWeight(5); $alg = $this->createAlg($v1); $this->assertCount(2, $alg->getEdges()); @@ -119,10 +119,10 @@ public function testMixedGraphDirectionIsIgnored() $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); $v5 = $graph->createVertex(5); - $v1->createEdgeTo($v2)->setWeight(6); - $v2->createEdge($v3)->setWeight(7); - $v4->createEdge($v3)->setWeight(8); - $v5->createEdgeTo($v4)->setWeight(9); + $graph->createEdgeDirected($v1, $v2)->setWeight(6); + $graph->createEdgeUndirected($v2, $v3)->setWeight(7); + $graph->createEdgeUndirected($v4, $v3)->setWeight(8); + $graph->createEdgeDirected($v5, $v4)->setWeight(9); $alg = $this->createAlg($v1); @@ -142,8 +142,8 @@ public function testMultipleComponentsFail() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); - $v1->createEdge($v2)->setWeight(1); - $v3->createEdge($v4)->setWeight(1); + $graph->createEdgeUndirected($v1, $v2)->setWeight(1); + $graph->createEdgeUndirected($v3, $v4)->setWeight(1); $alg = $this->createAlg($v1); $alg->getEdges(); diff --git a/tests/MinimumSpanningTree/KruskalTest.php b/tests/MinimumSpanningTree/KruskalTest.php index 3e1f21d..d145b78 100644 --- a/tests/MinimumSpanningTree/KruskalTest.php +++ b/tests/MinimumSpanningTree/KruskalTest.php @@ -1,8 +1,8 @@ createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v2->createEdgeTo($v1); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v2, $v1); $alg = new AlgorithmParallel($graph); @@ -38,8 +38,8 @@ public function testDirectedParallelEdge() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v1->createEdgeTo($v2); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v1, $v2); $alg = new AlgorithmParallel($graph); @@ -55,8 +55,8 @@ public function testMixedParallelEdge() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v1->createEdge($v2); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeUndirected($v1, $v2); $alg = new AlgorithmParallel($graph); @@ -76,12 +76,12 @@ public function testMixedParallelEdgesMultiple() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v1->createEdgeTo($v2); - $e3 = $v1->createEdge($v2); - $e4 = $v1->createEdge($v2); - $e5 = $v2->createEdgeTo($v1); - $e6 = $v2->createEdgeTo($v1); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v1, $v2); + $e3 = $graph->createEdgeUndirected($v1, $v2); + $e4 = $graph->createEdgeUndirected($v1, $v2); + $e5 = $graph->createEdgeDirected($v2, $v1); + $e6 = $graph->createEdgeDirected($v2, $v1); $alg = new AlgorithmParallel($graph); diff --git a/tests/Property/PropertyGraphTest.php b/tests/Property/PropertyGraphTest.php index 32e0374..8d9eb9b 100644 --- a/tests/Property/PropertyGraphTest.php +++ b/tests/Property/PropertyGraphTest.php @@ -1,7 +1,7 @@ createVertex(1); - $e1 = $v1->createEdge($v1); + $e1 = $graph->createEdgeUndirected($v1, $v1); $walk = Walk::factoryFromEdges(array($e1), $v1); @@ -61,8 +61,8 @@ public function testCycle() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdge($v2); - $e2 = $v2->createEdge($v1); + $e1 = $graph->createEdgeUndirected($v1, $v2); + $e2 = $graph->createEdgeUndirected($v2, $v1); $walk = Walk::factoryFromEdges(array($e1, $e2), $v1); @@ -86,9 +86,9 @@ public function testCircuit() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v2->createEdgeTo($v1); - $e3 = $v2->createEdgeTo($v2); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v2, $v1); + $e3 = $graph->createEdgeDirected($v2, $v2); // 1 -> 2 -> 2 -> 1 $walk = Walk::factoryFromEdges(array($e1, $e3, $e2), $v1); @@ -107,9 +107,9 @@ public function testNonCircuit() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v2->createEdgeTo($v1); - $e3 = $v2->createEdgeTo($v2); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v2, $v1); + $e3 = $graph->createEdgeDirected($v2, $v2); // non-circuit: taking loop twice // 1 -> 2 -> 2 -> 2 -> 1 @@ -129,8 +129,8 @@ public function testDigon() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v2->createEdgeTo($v1); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v2, $v1); $walk = Walk::factoryFromEdges(array($e1, $e2), $v1); @@ -146,9 +146,9 @@ public function testTriangle() $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); - $e1 = $v1->createEdgeTo($v2); - $e2 = $v2->createEdgeTo($v3); - $e3 = $v3->createEdgeTo($v1); + $e1 = $graph->createEdgeDirected($v1, $v2); + $e2 = $graph->createEdgeDirected($v2, $v3); + $e3 = $graph->createEdgeDirected($v3, $v1); $walk = Walk::factoryFromEdges(array($e1, $e2, $e3), $v1); @@ -163,8 +163,8 @@ public function testSimplePathWithinGraph() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2); - $e2 = $v2->createEdge($v2); + $graph->createEdgeUndirected($v1, $v2); + $e2 = $graph->createEdgeUndirected($v2, $v2); // only use "2 -- 2" part $walk = Walk::factoryFromEdges(array($e2), $v2); diff --git a/tests/ResidualGraphTest.php b/tests/ResidualGraphTest.php index 3cd44f4..d109e3a 100644 --- a/tests/ResidualGraphTest.php +++ b/tests/ResidualGraphTest.php @@ -1,7 +1,7 @@ createVertex(0)->createEdgeTo($graph->createVertex(1))->setFlow(0) + $graph->createEdgeDirected($graph->createVertex(0), $graph->createVertex(1))->setFlow(0) ->setCapacity(2) ->setWeight(3); @@ -39,7 +39,7 @@ public function testEdgeUsed() { $graph = new Graph(); - $graph->createVertex(0)->createEdgeTo($graph->createVertex(1))->setFlow(2) + $graph->createEdgeDirected($graph->createVertex(0), $graph->createVertex(1))->setFlow(2) ->setCapacity(2) ->setWeight(3); @@ -47,7 +47,7 @@ public function testEdgeUsed() $residual = $alg->createGraph(); $expected = new Graph(); - $expected->createVertex(1)->createEdgeTo($expected->createVertex(0))->setFlow(0) + $expected->createEdgeDirected($expected->createVertex(1), $expected->createVertex(0))->setFlow(0) ->setCapacity(2) ->setWeight(-3); @@ -61,7 +61,7 @@ public function testEdgePartial() { $graph = new Graph(); - $graph->createVertex(0)->createEdgeTo($graph->createVertex(1))->setFlow(1) + $graph->createEdgeDirected($graph->createVertex(0), $graph->createVertex(1))->setFlow(1) ->setCapacity(2) ->setWeight(3); @@ -73,12 +73,12 @@ public function testEdgePartial() $expected->createVertex(1); // remaining edge - $expected->getVertex(0)->createEdgeTo($expected->getVertex(1))->setFlow(0) + $expected->createEdgeDirected($expected->getVertex(0), $expected->getVertex(1))->setFlow(0) ->setCapacity(1) ->setWeight(3); // back edge - $expected->getVertex(1)->createEdgeTo($expected->getVertex(0))->setFlow(0) + $expected->createEdgeDirected($expected->getVertex(1), $expected->getVertex(0))->setFlow(0) ->setCapacity(1) ->setWeight(-3); @@ -91,7 +91,7 @@ public function testResidualGraphCanOptionallyKeepNullCapacityForEdgeWithZeroFlo $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(0)->setCapacity(2); + $graph->createEdgeDirected($v1, $v2)->setFlow(0)->setCapacity(2); // 1 -[0/2]-> 2 // ^ | @@ -99,8 +99,8 @@ public function testResidualGraphCanOptionallyKeepNullCapacityForEdgeWithZeroFlo $expected = new Graph(); $v1 = $expected->createVertex(1); $v2 = $expected->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(0)->setCapacity(2); - $v2->createEdgeTo($v1)->setFlow(0)->setCapacity(0); + $expected->createEdgeDirected($v1, $v2)->setFlow(0)->setCapacity(2); + $expected->createEdgeDirected($v2, $v1)->setFlow(0)->setCapacity(0); $alg = new ResidualGraph($graph); $alg->setKeepNullCapacity(true); @@ -115,7 +115,7 @@ public function testResidualGraphCanOptionallyKeepNullCapacityForEdgeWithZeroCap $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(2)->setCapacity(2); + $graph->createEdgeDirected($v1, $v2)->setFlow(2)->setCapacity(2); // 1 -[0/0]-> 2 // ^ | @@ -123,8 +123,8 @@ public function testResidualGraphCanOptionallyKeepNullCapacityForEdgeWithZeroCap $expected = new Graph(); $v1 = $expected->createVertex(1); $v2 = $expected->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(0)->setCapacity(0); - $v2->createEdgeTo($v1)->setFlow(0)->setCapacity(2); + $expected->createEdgeDirected($v1, $v2)->setFlow(0)->setCapacity(0); + $expected->createEdgeDirected($v2, $v1)->setFlow(0)->setCapacity(2); $alg = new ResidualGraph($graph); $alg->setKeepNullCapacity(true); @@ -141,8 +141,8 @@ public function testParallelEdgesCanBeMerged() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(1)->setCapacity(2); - $v1->createEdgeTo($v2)->setFlow(2)->setCapacity(3); + $graph->createEdgeDirected($v1, $v2)->setFlow(1)->setCapacity(2); + $graph->createEdgeDirected($v1, $v2)->setFlow(2)->setCapacity(3); // 1 -[0/2]-> 2 // ^ | @@ -150,8 +150,8 @@ public function testParallelEdgesCanBeMerged() $expected = new Graph(); $v1 = $expected->createVertex(1); $v2 = $expected->createVertex(2); - $v1->createEdgeTo($v2)->setFlow(0)->setCapacity(2); - $v2->createEdgeTo($v1)->setFlow(0)->setCapacity(3); + $expected->createEdgeDirected($v1, $v2)->setFlow(0)->setCapacity(2); + $expected->createEdgeDirected($v2, $v1)->setFlow(0)->setCapacity(3); $alg = new ResidualGraph($graph); $alg->setMergeParallelEdges(true); @@ -168,7 +168,7 @@ public function testInvalidUndirected() { $graph = new Graph(); - $graph->createVertex()->createEdge($graph->createVertex())->setFlow(1) + $graph->createEdgeUndirected($graph->createVertex(), $graph->createVertex())->setFlow(1) ->setCapacity(2); $alg = new ResidualGraph($graph); @@ -183,7 +183,7 @@ public function testInvalidNoFlow() { $graph = new Graph(); - $graph->createVertex()->createEdgeTo($graph->createVertex())->setCapacity(1); + $graph->createEdgeDirected($graph->createVertex(), $graph->createVertex())->setCapacity(1); $alg = new ResidualGraph($graph); $alg->createGraph(); @@ -197,7 +197,7 @@ public function testInvalidNoCapacity() { $graph = new Graph(); - $graph->createVertex()->createEdgeTo($graph->createVertex())->setFlow(1); + $graph->createEdgeDirected($graph->createVertex(), $graph->createVertex())->setFlow(1); $alg = new ResidualGraph($graph); $alg->createGraph(); diff --git a/tests/Search/BreadthFirstTest.php b/tests/Search/BreadthFirstTest.php index 6c1d5c3..6fba9da 100644 --- a/tests/Search/BreadthFirstTest.php +++ b/tests/Search/BreadthFirstTest.php @@ -1,7 +1,7 @@ createVertex($e[0], true)->createEdgeTo($g->createVertex($e[1], true)); + $g->createEdgeDirected($g->createVertex($e[0], true), $g->createVertex($e[1], true)); } $a = new BreadthFirst($g->getVertex($subject)); if ($maxDepth !== null) { diff --git a/tests/ShortestPath/BaseShortestPathTest.php b/tests/ShortestPath/BaseShortestPathTest.php index e5d640d..a3844f3 100644 --- a/tests/ShortestPath/BaseShortestPathTest.php +++ b/tests/ShortestPath/BaseShortestPathTest.php @@ -1,8 +1,8 @@ 1 $graph = new Graph(); $v1 = $graph->createVertex(1); - $e1 = $v1->createEdgeTo($v1)->setWeight(4); + $e1 = $graph->createEdgeDirected($v1, $v1)->setWeight(4); $alg = $this->createAlg($v1); @@ -61,8 +61,8 @@ public function testGraphCycle() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2)->setWeight(4); - $e2 = $v2->createEdgeTo($v1)->setWeight(2); + $e1 = $graph->createEdgeDirected($v1, $v2)->setWeight(4); + $e2 = $graph->createEdgeDirected($v2, $v1)->setWeight(2); $alg = $this->createAlg($v1); @@ -122,7 +122,7 @@ public function testGraphUnweighted() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2); + $e1 = $graph->createEdgeDirected($v1, $v2); $alg = $this->createAlg($v1); @@ -143,8 +143,8 @@ public function testGraphTwoComponents() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); - $e1 = $v1->createEdgeTo($v2)->setWeight(10); - $v3->createEdgeTo($v4)->setWeight(20); + $e1 = $graph->createEdgeDirected($v1, $v2)->setWeight(10); + $graph->createEdgeDirected($v3, $v4)->setWeight(20); $alg = $this->createAlg($v1); diff --git a/tests/ShortestPath/BreadthFirstTest.php b/tests/ShortestPath/BreadthFirstTest.php index b2c183f..bc0d00a 100644 --- a/tests/ShortestPath/BreadthFirstTest.php +++ b/tests/ShortestPath/BreadthFirstTest.php @@ -1,8 +1,8 @@ createVertex(1); $v2 = $graph->createVertex(2); - $e1 = $v1->createEdgeTo($v2)->setWeight(10); - $v1->createEdgeTo($v2)->setWeight(-1); + $e1 = $graph->createEdgeDirected($v1, $v2)->setWeight(10); + $graph->createEdgeDirected($v1, $v2)->setWeight(-1); $alg = $this->createAlg($v1); diff --git a/tests/ShortestPath/DijkstraTest.php b/tests/ShortestPath/DijkstraTest.php index ce88a5b..7b7c9ef 100644 --- a/tests/ShortestPath/DijkstraTest.php +++ b/tests/ShortestPath/DijkstraTest.php @@ -1,8 +1,8 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setWeight(10); - $v1->createEdgeTo($v2)->setWeight(-1); + $graph->createEdgeDirected($v1, $v2)->setWeight(10); + $graph->createEdgeDirected($v1, $v2)->setWeight(-1); $alg = $this->createAlg($v1); diff --git a/tests/ShortestPath/MooreBellmanFordTest.php b/tests/ShortestPath/MooreBellmanFordTest.php index 7cf267b..0fadcce 100644 --- a/tests/ShortestPath/MooreBellmanFordTest.php +++ b/tests/ShortestPath/MooreBellmanFordTest.php @@ -1,8 +1,8 @@ createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdgeTo($v2)->setWeight(10); - $e2 = $v1->createEdgeTo($v2)->setWeight(-1); + $graph->createEdgeDirected($v1, $v2)->setWeight(10); + $e2 = $graph->createEdgeDirected($v1, $v2)->setWeight(-1); $alg = $this->createAlg($v1); @@ -52,13 +52,13 @@ public function testUndirectedNegativeWeightIsCycle() $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); - $v1->createEdge($v2)->setWeight(-10); + $graph->createEdgeUndirected($v1, $v2)->setWeight(-10); $alg = $this->createAlg($v1); $cycle = $alg->getCycleNegative(); - $this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle); + $this->assertInstanceOf('Graphp\Graph\Walk', $cycle); } public function testLoopNegativeWeightIsCycle() @@ -66,13 +66,13 @@ public function testLoopNegativeWeightIsCycle() // 1 -[-10]-> 1 $graph = new Graph(); $v1 = $graph->createVertex(1); - $v1->createEdge($v1)->setWeight(-10); + $graph->createEdgeUndirected($v1, $v1)->setWeight(-10); $alg = $this->createAlg($v1); $cycle = $alg->getCycleNegative(); - $this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle); + $this->assertInstanceOf('Graphp\Graph\Walk', $cycle); } public function testNegativeComponentHasCycle() @@ -85,9 +85,9 @@ public function testNegativeComponentHasCycle() $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); - $v1->createEdgeTo($v2)->setWeight(1); - $v3->createEdgeTo($v4)->setWeight(-1); - $v4->createEdgeTo($v3)->setWeight(-2); + $graph->createEdgeDirected($v1, $v2)->setWeight(1); + $graph->createEdgeDirected($v3, $v4)->setWeight(-1); + $graph->createEdgeDirected($v4, $v3)->setWeight(-2); // second component has a cycle $alg = $this->createAlg($v3); diff --git a/tests/SymmetricTest.php b/tests/SymmetricTest.php index be128eb..c1544cb 100644 --- a/tests/SymmetricTest.php +++ b/tests/SymmetricTest.php @@ -1,7 +1,7 @@ 2 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmSymmetric($graph); @@ -40,8 +40,8 @@ public function testGraphAntiparallelIsSymmetricr() { // 1 -> 2 -> 1 $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); - $graph->getVertex(2)->createEdgeTo($graph->getVertex(1)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); + $graph->createEdgeDirected($graph->getVertex(2), $graph->getVertex(1)); $alg = new AlgorithmSymmetric($graph); @@ -52,7 +52,7 @@ public function testGraphSingleUndirectedIsSymmetricr() { // 1 -- 2 $graph = new Graph(); - $graph->createVertex(1)->createEdge($graph->createVertex(2)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new AlgorithmSymmetric($graph); diff --git a/tests/TopologicalSortTest.php b/tests/TopologicalSortTest.php index b0e39d2..ce5e3c4 100644 --- a/tests/TopologicalSortTest.php +++ b/tests/TopologicalSortTest.php @@ -1,7 +1,7 @@ assertInstanceOf('Fhaculty\Graph\Set\Vertices', $alg->getVertices()); + $this->assertInstanceOf('Graphp\Graph\Set\Vertices', $alg->getVertices()); $this->assertTrue($alg->getVertices()->isEmpty()); } @@ -29,7 +29,7 @@ public function testGraphIsolated() public function testGraphSimple() { $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new TopologicalSort($graph); @@ -42,7 +42,7 @@ public function testGraphSimple() public function testFailUndirected() { $graph = new Graph(); - $graph->createVertex(1)->createEdge($graph->createVertex(2)); + $graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2)); $alg = new TopologicalSort($graph); $alg->getVertices(); @@ -54,7 +54,7 @@ public function testFailUndirected() public function testFailLoop() { $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->getVertex(1)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->getVertex(1)); $alg = new TopologicalSort($graph); $alg->getVertices(); @@ -66,8 +66,8 @@ public function testFailLoop() public function testFailCycle() { $graph = new Graph(); - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2)); - $graph->getVertex(2)->createEdgeTo($graph->getVertex(1)); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2)); + $graph->createEdgeDirected($graph->getVertex(2), $graph->getVertex(1)); $alg = new TopologicalSort($graph); $alg->getVertices(); diff --git a/tests/TravelingSalesmanProblem/BruteforceTest.php b/tests/TravelingSalesmanProblem/BruteforceTest.php index 92f1131..bb43e3c 100644 --- a/tests/TravelingSalesmanProblem/BruteforceTest.php +++ b/tests/TravelingSalesmanProblem/BruteforceTest.php @@ -1,7 +1,7 @@ createVertex(); $b = $graph->createVertex(); $c = $graph->createVertex(); - $a->createEdgeTo($b)->setWeight(1); - $b->createEdgeTo($c)->setWeight(2); - $c->createEdgeTo($a)->setWeight(3); + $graph->createEdgeDirected($a, $b)->setWeight(1); + $graph->createEdgeDirected($b, $c)->setWeight(2); + $graph->createEdgeDirected($c, $a)->setWeight(3); $alg = new Bruteforce($graph); @@ -26,9 +26,9 @@ public function testSetUpperLimitMstSetsExactLimitForSimpleCycle() $a = $graph->createVertex(); $b = $graph->createVertex(); $c = $graph->createVertex(); - $a->createEdgeTo($b)->setWeight(1); - $b->createEdgeTo($c)->setWeight(2); - $c->createEdgeTo($a)->setWeight(3); + $graph->createEdgeDirected($a, $b)->setWeight(1); + $graph->createEdgeDirected($b, $c)->setWeight(2); + $graph->createEdgeDirected($c, $a)->setWeight(3); $alg = new Bruteforce($graph); $alg->setUpperLimitMst(); diff --git a/tests/Tree/BaseDirectedTest.php b/tests/Tree/BaseDirectedTest.php index 975718d..4713392 100644 --- a/tests/Tree/BaseDirectedTest.php +++ b/tests/Tree/BaseDirectedTest.php @@ -1,8 +1,8 @@ v1 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->getVertex('v1')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->getVertex('v1')); $tree = $this->createTreeAlg($graph); @@ -164,7 +164,7 @@ public function testGraphWithLoopCanNotGetSubgraph() { // v1 -> v1 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->getVertex('v1')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->getVertex('v1')); $tree = $this->createTreeAlg($graph); @@ -175,7 +175,7 @@ public function testGraphWithUndirectedEdgeIsNotTree() { // v1 -- v2 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); $tree = $this->createTreeAlg($graph); @@ -186,9 +186,9 @@ public function testGraphWithMixedEdgesIsNotTree() { // v1 -> v2 -- v3 -> v4 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2')); - $graph->getVertex('v2')->createEdge($graph->createVertex('v3')); - $graph->getVertex('v3')->createEdgeTo($graph->createVertex('v4')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->getVertex('v2'), $graph->createVertex('v3')); + $graph->createEdgeDirected($graph->getVertex('v3'), $graph->createVertex('v4')); $tree = $this->createTreeAlg($graph); diff --git a/tests/Tree/InTreeTest.php b/tests/Tree/InTreeTest.php index 91b7ec5..3d05496 100644 --- a/tests/Tree/InTreeTest.php +++ b/tests/Tree/InTreeTest.php @@ -1,7 +1,7 @@ createVertex(); $c1 = $graph->createVertex(); - $c1->createEdgeTo($root); + $graph->createEdgeDirected($c1, $root); $c2 = $graph->createVertex(); - $c2->createEdgeTo($root); + $graph->createEdgeDirected($c2, $root); return $graph; } @@ -29,9 +29,9 @@ protected function createGraphNonTree() { // v1 -> v2 <- v3 -> v4 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2')); - $graph->createVertex('v3')->createEdgeTo($graph->getVertex('v2')); - $graph->getVertex('v3')->createEdgeTo($graph->createVertex('v4')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeDirected($graph->createVertex('v3'), $graph->getVertex('v2')); + $graph->createEdgeDirected($graph->getVertex('v3'), $graph->createVertex('v4')); return $graph; } @@ -40,8 +40,8 @@ protected function createGraphParallelEdge() { // v1 <- v2, v1 <- v2 $graph = new Graph(); - $graph->createVertex('v2')->createEdgeTo($graph->createVertex('v1')); - $graph->getVertex('v2')->createEdgeTo($graph->getVertex('v1')); + $graph->createEdgeDirected($graph->createVertex('v2'), $graph->createVertex('v1')); + $graph->createEdgeDirected($graph->getVertex('v2'), $graph->getVertex('v1')); return $graph; } diff --git a/tests/Tree/OutTreeTest.php b/tests/Tree/OutTreeTest.php index c828986..af973a0 100644 --- a/tests/Tree/OutTreeTest.php +++ b/tests/Tree/OutTreeTest.php @@ -1,7 +1,7 @@ createVertex(); $c1 = $graph->createVertex(); - $root->createEdgeTo($c1); + $graph->createEdgeDirected($root, $c1); $c2 = $graph->createVertex(); - $root->createEdgeTo($c2); + $graph->createEdgeDirected($root, $c2); return $graph; } @@ -29,9 +29,9 @@ protected function createGraphNonTree() { // v1 -> v3 <- v2 -> v4 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v3')); - $graph->createVertex('v2')->createEdgeTo($graph->getVertex('v3')); - $graph->getVertex('v2')->createEdgeTo($graph->createVertex('v4')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->createVertex('v3')); + $graph->createEdgeDirected($graph->createVertex('v2'), $graph->getVertex('v3')); + $graph->createEdgeDirected($graph->getVertex('v2'), $graph->createVertex('v4')); return $graph; } @@ -40,8 +40,8 @@ protected function createGraphParallelEdge() { // v1 -> v2, v1 -> v2 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2')); - $graph->getVertex('v1')->createEdgeTo($graph->getVertex('v2')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeDirected($graph->getVertex('v1'), $graph->getVertex('v2')); return $graph; } diff --git a/tests/Tree/UndirectedTest.php b/tests/Tree/UndirectedTest.php index 2b1e368..1306c9e 100644 --- a/tests/Tree/UndirectedTest.php +++ b/tests/Tree/UndirectedTest.php @@ -1,7 +1,7 @@ createVertex('v1')->createEdge($graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); $tree = $this->createTree($graph); $this->assertTrue($tree->isTree()); @@ -48,8 +48,8 @@ public function testGraphSimpleLine() { // v1 -- v2 -- v3 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->createVertex('v2')); - $graph->getVertex('v2')->createEdge($graph->createVertex('v3')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->getVertex('v2'), $graph->createVertex('v3')); $tree = $this->createTree($graph); $this->assertTrue($tree->isTree()); @@ -61,8 +61,8 @@ public function testGraphPairParallelIsNotTree() { // v1 -- v2 -- v1 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->createVertex('v2')); - $graph->getVertex('v1')->createEdge($graph->getVertex('v2')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->getVertex('v1'), $graph->getVertex('v2')); $tree = $this->createTree($graph); $this->assertFalse($tree->isTree()); @@ -72,7 +72,7 @@ public function testGraphLoopIsNotTree() { // v1 -- v1 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->getVertex('v1')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->getVertex('v1')); $tree = $this->createTree($graph); $this->assertFalse($tree->isTree()); @@ -82,9 +82,9 @@ public function testGraphCycleIsNotTree() { // v1 -- v2 -- v3 -- v1 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->createVertex('v2')); - $graph->getVertex('v2')->createEdge($graph->createVertex('v3')); - $graph->getVertex('v3')->createEdge($graph->getVertex('v1')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeUndirected($graph->getVertex('v2'), $graph->createVertex('v3')); + $graph->createEdgeUndirected($graph->getVertex('v3'), $graph->getVertex('v1')); $tree = $this->createTree($graph); $this->assertFalse($tree->isTree()); @@ -94,7 +94,7 @@ public function testGraphDirectedIsNotTree() { // v1 -> v2 $graph = new Graph(); - $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2')); + $graph->createEdgeDirected($graph->createVertex('v1'), $graph->createVertex('v2')); $tree = $this->createTree($graph); $this->assertFalse($tree->isTree()); @@ -104,8 +104,8 @@ public function testGraphMixedIsNotTree() { // v1 -- v2 -> v3 $graph = new Graph(); - $graph->createVertex('v1')->createEdge($graph->createVertex('v2')); - $graph->getVertex('v2')->createEdgeTo($graph->createVertex('v3')); + $graph->createEdgeUndirected($graph->createVertex('v1'), $graph->createVertex('v2')); + $graph->createEdgeDirected($graph->getVertex('v2'), $graph->createVertex('v3')); $tree = $this->createTree($graph); $this->assertFalse($tree->isTree()); diff --git a/tests/WeightTest.php b/tests/WeightTest.php index 30eb960..b20375d 100644 --- a/tests/WeightTest.php +++ b/tests/WeightTest.php @@ -1,7 +1,7 @@ 2 - $graph->createVertex(1)->createEdgeTo($graph->createVertex(2))->setWeight(3)->setFlow(4); + $graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2))->setWeight(3)->setFlow(4); $alg = new AlgorithmWeight($graph); @@ -46,7 +46,7 @@ public function testGraphSimple(Graph $graph) */ public function testGraphWithUnweightedEdges(Graph $graph) { - $graph->createVertex(5)->createEdgeTo($graph->createVertex(6))->setFlow(7); + $graph->createEdgeDirected($graph->createVertex(5), $graph->createVertex(6))->setFlow(7); $alg = new AlgorithmWeight($graph); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 095800a..60b5908 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,9 +1,9 @@ getVertexStart()->getId() . ' -> ' . $edge->getVertexEnd()->getId(); } else { $vertices = $edge->getVertices()->getIds();