From 139726812318e99f2763511995ac875bd0d152a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 13 Jul 2013 11:23:24 +0200 Subject: [PATCH 1/5] Remove Graph::getVertexFirst() --- lib/Fhaculty/Graph/Graph.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/Fhaculty/Graph/Graph.php b/lib/Fhaculty/Graph/Graph.php index 12392d65..1434bca7 100644 --- a/lib/Fhaculty/Graph/Graph.php +++ b/lib/Fhaculty/Graph/Graph.php @@ -332,23 +332,6 @@ public function hasVertex($id) return $this->vertices->hasVertexId($id); } - /** - * return first vertex found - * - * some algorithms do not need a particular vertex, but merely a (random) - * starting point. this is a convenience function to just pick the first - * vertex from the list of known vertices. - * - * @return Vertex first vertex found in this graph - * @throws UnderflowException if Graph has no vertices - * @see Vertices::getVertexOrder() if you need to apply ordering first - * @uses Vertices::getVertexFirst() - */ - public function getVertexFirst() - { - return $this->vertices->getVertexFirst(); - } - /** * adds a new Edge to the Graph (MUST NOT be called manually!) * From 88fa0aa0b9ac0d4d6c2d353c70f41099e00215d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 13 Jul 2013 11:24:39 +0200 Subject: [PATCH 2/5] Update references to Graph::getVertexFirst() --- lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php | 2 +- lib/Fhaculty/Graph/Algorithm/Degree.php | 2 +- .../Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php | 6 +++--- .../TravelingSalesmanProblem/MinimumSpanningTree.php | 4 ++-- lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php | 4 ++-- tests/Fhaculty/Graph/Algorithm/Tree/BaseDirectedTest.php | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php b/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php index 3da187b5..8b2c6463 100644 --- a/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php +++ b/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php @@ -70,7 +70,7 @@ private function createSearch(Vertex $vertex) public function isSingle() { try { - $vertex = $this->graph->getVertexFirst(); + $vertex = $this->graph->getVertices()->getVertexFirst(); } catch (UnderflowException $e) { // no first vertex => empty graph => has zero components diff --git a/lib/Fhaculty/Graph/Algorithm/Degree.php b/lib/Fhaculty/Graph/Algorithm/Degree.php index 07a49dd5..7ca1f34c 100644 --- a/lib/Fhaculty/Graph/Algorithm/Degree.php +++ b/lib/Fhaculty/Graph/Algorithm/Degree.php @@ -31,7 +31,7 @@ class Degree extends BaseGraph public function getDegree() { // get initial degree of any start vertex to compare others to - $degree = $this->getDegreeVertex($this->graph->getVertexFirst()); + $degree = $this->getDegreeVertex($this->graph->getVertices()->getVertexFirst()); foreach ($this->graph->getVertices() as $vertex) { /** @var $vertex Vertex */ diff --git a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php index 00b02f55..e829acec 100644 --- a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php +++ b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php @@ -92,7 +92,8 @@ public function setUpperLimitMst() protected function getVertexStart() { - return $this->graph->getVertexFirst(); + // actual start doesn't really matter as we're only considering complete graphs here + return $this->graph->getVertices()->getVertexFirst(); } protected function getGraph() @@ -116,8 +117,7 @@ public function getEdges() // numEdges 3-12 should work $this->bestWeight = $this->upperLimit; - // actual start doesn't really matter as we're only considering complete graphs here - $this->startVertex = $this->graph->getVertexFirst(); + $this->startVertex = $this->getVertexStart(); $result = $this->step($this->startVertex, 0, diff --git a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php index a2992dad..8d7ac510 100644 --- a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php +++ b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php @@ -23,7 +23,7 @@ public function __construct(Graph $inputGraph) protected function getVertexStart() { - return $this->graph->getVertexFirst(); + return $this->graph->getVertices()->VertexFirst(); } protected function getGraph() @@ -43,7 +43,7 @@ public function getEdges() $minimumSpanningTreeAlgorithm = new MstKruskal($this->graph); $minimumSpanningTree = $minimumSpanningTreeAlgorithm->createGraph(); - $alg = new SearchDepthFirst($minimumSpanningTree->getVertexFirst()); + $alg = new SearchDepthFirst($minimumSpanningTree->getVertices()->getVertexFirst()); // Depth first search in minmum spanning tree (for the eulerian path) $startVertex = NULL; diff --git a/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php b/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php index 01157d9b..f5fc3cd8 100644 --- a/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php +++ b/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php @@ -50,7 +50,7 @@ class Undirected extends Tree * * @return boolean * @uses Vertices::isEmpty() to skip null Graphs (a Graph with no Vertices is *NOT* a valid tree) - * @uses Graph::getVertexFirst() to get get get random "root" Vertex to start search from + * @uses Vertices::getVertexFirst() to get get get random "root" Vertex to start search from * @uses self::getVerticesSubtreeRecursive() to count number of vertices connected to root */ public function isTree() @@ -60,7 +60,7 @@ public function isTree() } // every vertex can represent a root vertex, so just pick one - $root = $this->graph->getVertexFirst(); + $root = $this->graph->getVertices()->getVertexFirst(); $vertices = array(); try { diff --git a/tests/Fhaculty/Graph/Algorithm/Tree/BaseDirectedTest.php b/tests/Fhaculty/Graph/Algorithm/Tree/BaseDirectedTest.php index 0c433dc1..0ed3cb52 100644 --- a/tests/Fhaculty/Graph/Algorithm/Tree/BaseDirectedTest.php +++ b/tests/Fhaculty/Graph/Algorithm/Tree/BaseDirectedTest.php @@ -75,7 +75,7 @@ public function testEmptyGraphDoesNotHaveHeight(BaseDirected $tree) public function testGraphTree() { $graph = $this->createGraphTree(); - $root = $graph->getVertexFirst(); + $root = $graph->getVertices()->getVertexFirst(); $nonRoot = $graph->getVertices()->getMap(); unset($nonRoot[$root->getId()]); From 051e779dedabfaeaeab21ecfbd12548fad2682c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 13 Nov 2013 11:45:06 +0100 Subject: [PATCH 3/5] Remove Walk::getVertexSource() and Walk::getVertexTarget() --- lib/Fhaculty/Graph/Walk.php | 37 ++++++++++--------------------- tests/Fhaculty/Graph/WalkTest.php | 22 +++++++++--------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/lib/Fhaculty/Graph/Walk.php b/lib/Fhaculty/Graph/Walk.php index 4beaed6c..e04f483b 100644 --- a/lib/Fhaculty/Graph/Walk.php +++ b/lib/Fhaculty/Graph/Walk.php @@ -143,8 +143,8 @@ public static function factoryCycleFromVertices($vertices, $by = null, $desc = f { $cycle = self::factoryFromVertices($vertices, $by, $desc); - $first = $cycle->getVertexSource(); - $last = $cycle->getVertexTarget(); + $first = $cycle->getVertices()->getVertexFirst(); + $last = $cycle->getVertices()->getVertexLast(); // additional edge from last vertex to first vertex if ($last !== $first) { @@ -178,7 +178,7 @@ public static function factoryCycleFromEdges($edges, Vertex $startVertex) $cycle = self::factoryFromEdges($edges, $startVertex); // ensure this walk is actually a cycle by checking start = end - if ($cycle->getVertexTarget() !== $startVertex) { + if ($cycle->getVertices()->getVertexLast() !== $startVertex) { throw new InvalidArgumentException('The given array of edges does not represent a cycle'); } @@ -207,12 +207,13 @@ protected function __construct($vertices, $edges) * return original graph * * @return Graph - * @uses Walk::getVertexSource() + * @uses self::getVertices() + * @uses Vertices::getVertexFirst() * @uses Vertex::getGraph() */ public function getGraph() { - return $this->getVertexSource()->getGraph(); + return $this->getVertices()->getVertexFirst()->getGraph(); } /** @@ -259,6 +260,12 @@ public function getEdges() * If you need to return set a of all unique Vertices of walk, use * `Walk::getVertices()->getVerticesDistinct()` instead. * + * If you need to return the source vertex (first vertex of walk), use + * `Walk::getVertices()->getVertexFirst()` instead. + * + * If you need to return the target/destination vertex (last vertex of walk), use + * `Walk::getVertices()->getVertexLast()` instead. + * * @return Vertices */ public function getVertices() @@ -266,26 +273,6 @@ public function getVertices() return $this->vertices; } - /** - * return source vertex (first vertex of walk) - * - * @return Vertex - */ - public function getVertexSource() - { - return $this->vertices->getVertexFirst(); - } - - /** - * return target vertex (last vertex of walk) - * - * @return Vertex - */ - public function getVertexTarget() - { - return $this->vertices->getVertexLast(); - } - /** * get alternating sequence of vertex, edge, vertex, edge, ..., vertex * diff --git a/tests/Fhaculty/Graph/WalkTest.php b/tests/Fhaculty/Graph/WalkTest.php index e0f0239f..33d1e26c 100644 --- a/tests/Fhaculty/Graph/WalkTest.php +++ b/tests/Fhaculty/Graph/WalkTest.php @@ -28,8 +28,8 @@ public function testWalkPath() $this->assertEquals(3, count($walk->getVertices())); $this->assertEquals(2, count($walk->getEdges())); - $this->assertSame($v1, $walk->getVertexSource()); - $this->assertSame($v3, $walk->getVertexTarget()); + $this->assertSame($v1, $walk->getVertices()->getVertexFirst()); + $this->assertSame($v3, $walk->getVertices()->getVertexLast()); $this->assertSame(array($v1, $e1, $v2, $e2, $v3), $walk->getAlternatingSequence()); $this->assertTrue($walk->isValid()); @@ -46,7 +46,7 @@ public function testWalkPath() public function testWalkPathInvalidateByDestroyingVertex(Walk $walk) { // delete v3 - $walk->getVertexTarget()->destroy(); + $walk->getVertices()->getVertexLast()->destroy(); $this->assertFalse($walk->isValid()); } @@ -66,8 +66,8 @@ public function testWalkWithinGraph() $this->assertEquals(2, count($walk->getVertices())); $this->assertEquals(1, count($walk->getEdges())); - $this->assertSame($v1, $walk->getVertexSource()); - $this->assertSame($v2, $walk->getVertexTarget()); + $this->assertSame($v1, $walk->getVertices()->getVertexFirst()); + $this->assertSame($v2, $walk->getVertices()->getVertexLast()); $this->assertSame(array($v1, $e1, $v2), $walk->getAlternatingSequence()); $this->assertTrue($walk->isValid()); @@ -98,8 +98,8 @@ public function testWalkLoop() $this->assertEquals(2, count($walk->getVertices())); $this->assertEquals(1, count($walk->getEdges())); - $this->assertSame($v1, $walk->getVertexSource()); - $this->assertSame($v1, $walk->getVertexTarget()); + $this->assertSame($v1, $walk->getVertices()->getVertexFirst()); + $this->assertSame($v1, $walk->getVertices()->getVertexLast()); $this->assertTrue($walk->isValid()); return $walk; @@ -131,8 +131,8 @@ public function testWalkLoopCycle() $this->assertEquals(2, count($walk->getVertices())); $this->assertEquals(1, count($walk->getEdges())); - $this->assertSame($v1, $walk->getVertexSource()); - $this->assertSame($v1, $walk->getVertexTarget()); + $this->assertSame($v1, $walk->getVertices()->getVertexFirst()); + $this->assertSame($v1, $walk->getVertices()->getVertexLast()); $this->assertTrue($walk->isValid()); } @@ -150,8 +150,8 @@ public function testWalkCycleFromVerticesAutocomplete() $this->assertEquals(3, count($walk->getVertices())); $this->assertEquals(2, count($walk->getEdges())); - $this->assertSame($v1, $walk->getVertexSource()); - $this->assertSame($v1, $walk->getVertexTarget()); + $this->assertSame($v1, $walk->getVertices()->getVertexFirst()); + $this->assertSame($v1, $walk->getVertices()->getVertexLast()); $this->assertTrue($walk->isValid()); } From d6b47d14ccffb597fe6c49635482cac5c56e89c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 13 Nov 2013 12:06:44 +0100 Subject: [PATCH 4/5] Fix invalid reference to Vertices::getVertexFirst() --- .../Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php index 8d7ac510..e8049117 100644 --- a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php +++ b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/MinimumSpanningTree.php @@ -23,7 +23,7 @@ public function __construct(Graph $inputGraph) protected function getVertexStart() { - return $this->graph->getVertices()->VertexFirst(); + return $this->graph->getVertices()->getVertexFirst(); } protected function getGraph() From 599503186d7fa8bcd143397d31bd768603d61325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 25 Dec 2013 01:53:52 +0100 Subject: [PATCH 5/5] Add removed `getVertexFirst()` to CHANGELOG --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 809a7220..b6c72108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,16 @@ you spot any mistakes. * Fix: Throwing an `UnexpectedValueException` if writing GraphViz Dot script to a temporary file fails and remove its debugging output ([#77](https://github.com/clue/graph/issues/77) and [#78](https://github.com/clue/graph/issues/78) @Metabor) + +* BC break: Remove unneeded alias definitions of `getVertexFirst()`, + `getVertexSource()` and `getVertexTarget()` + [#76]https://github.com/clue/graph/issues/76)): + + | Old name | New name | + |---|---| + | `Graph::getVertexFirst()` | `Graph::getVertices()->getVertexFirst()` | + | `Walk::getVertexSource()` | `Walk::getVertices()->getVertexFirst()` | + | `Walk::getVertexTarget()` | `Walk::getVertices()->getVertexLast()` | ## 0.7.0 (2013-09-11)