Skip to content

Commit

Permalink
Merge pull request #61 from clue/merge-cycle
Browse files Browse the repository at this point in the history
Merge Cycle into Walk
  • Loading branch information
clue committed Jul 15, 2013
2 parents be01ca5 + 4646d1a commit 2bd1477
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 133 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ you spot any mistakes.

## 0.7.0 (2013-xx-xx)

* BC break: Merge `Cycle` into `Walk` ([#61](https://github.com/clue/graph/issues/61)).
As such, its static factory methods had to be renamed. Update your references if applicable:

| Old name | New name |
|---|---|
| `Cycle::factoryFromPredecessorMap()` | `Walk::factoryCycleFromPredecessorMap()` |
| `Cycle::factoryFromVertices()` | `Walk::factoryCycleFromVertices()` |
| `Cycle::factoryFromEdges()` | `Walk::factoryCycleFromEdges()` |

* BC break: Each of the above methods (`Walk::factoryCycleFromPredecessorMap()`,
`Walk::factoryCycleFromVertices()`, `Walk::factoryCycleFromEdges()`) now
actually makes sure the returned `Walk` instance is actually a valid Cycle,
i.e. the start `Vertex` is the same as the end `Vertex` ([#61](https://github.com/clue/graph/issues/61))
* BC break: Each `Algorithm\ShortestPath` algorithm now consistenly does not
return a zero weight for the root Vertex and now supports loop edges on the root
Vertex ([#62](https://github.com/clue/graph/issues/62))
Expand All @@ -14,6 +27,7 @@ Vertex ([#62](https://github.com/clue/graph/issues/62))
([#62](https://github.com/clue/graph/issues/62))
* Feature: Add `Algorithm\ShortestPath::hasVertex(Vertex $vertex)` to check whether
a path to the given Vertex exists ([#62](https://github.com/clue/graph/issues/62)).
* Fix: Checking `Walk::isValid()` ([#61](https://github.com/clue/graph/issues/61))
* Fix: Missing import prevented
`Algorithm\ShortestPath\MooreBellmanFord::getCycleNegative()` from actually
throwing the right `UnderflowException` if no cycle was actually found
Expand Down
5 changes: 3 additions & 2 deletions lib/Fhaculty/Graph/Algorithm/DetectNegativeCycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function hasCycleNegative()
/**
* Searches all vertices for the first negative cycle
*
* @return Cycle
* @return Walk
* @throws UnderflowException if there's no negative cycle
* @uses AlgorithmSpMooreBellmanFord::getVerticesId()
*/
Expand Down Expand Up @@ -72,7 +73,7 @@ public function getCycleNegative()
* @return Graph
* @throws Exception if there's no negative cycle
* @uses AlgorithmDetectNegativeCycle::getCycleNegative()
* @uses Cycle::createGraph()
* @uses Walk::createGraph()
*/
public function createGraph()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Fhaculty\Graph\Algorithm\ShortestPath;

use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Cycle;
use Fhaculty\Graph\Walk;
use Fhaculty\Graph\Exception\NegativeCycleException;
use Fhaculty\Graph\Exception\UnderflowException;

Expand Down Expand Up @@ -97,7 +97,7 @@ public function getEdges()
// Check for negative cycles (only if last step didn't already finish anyway)
// something is still changing...
if ($changed && $changed = $this->bigStep($edges, $totalCostOfCheapestPathTo, $predecessorVertexOfCheapestPathTo)) {
$cycle = Cycle::factoryFromPredecessorMap($predecessorVertexOfCheapestPathTo, $changed, Edge::ORDER_WEIGHT);
$cycle = Walk::factoryCycleFromPredecessorMap($predecessorVertexOfCheapestPathTo, $changed, Edge::ORDER_WEIGHT);
throw new NegativeCycleException('Negative cycle found', 0, NULL, $cycle);
}

Expand All @@ -107,7 +107,7 @@ public function getEdges()
/**
* get negative cycle
*
* @return Cycle
* @return Walk
* @throws UnderflowException if there's no negative cycle
*/
public function getCycleNegative()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Fhaculty\Graph\Algorithm\TravelingSalesmanProblem;

use Fhaculty\Graph\Cycle;
use Fhaculty\Graph\Walk;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Algorithm\Base as AlgorithmBase;
Expand Down Expand Up @@ -40,14 +40,14 @@ abstract protected function getVertexStart();
/**
* get (first) best circle connecting all vertices
*
* @return Cycle
* @return Walk
* @uses AlgorithmTsp::getEdges()
* @uses AlgorithmTsp::getVertexStart()
* @uses Cycle::factoryFromEdges()
* @uses Walk::factoryCycleFromEdges()
*/
public function getCycle()
{
return Cycle::factoryFromEdges($this->getEdges(), $this->getVertexStart());
return Walk::factoryCycleFromEdges($this->getEdges(), $this->getVertexStart());
}

public function getWeight()
Expand Down
114 changes: 0 additions & 114 deletions lib/Fhaculty/Graph/Cycle.php

This file was deleted.

9 changes: 4 additions & 5 deletions lib/Fhaculty/Graph/Exception/NegativeCycleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

namespace Fhaculty\Graph\Exception;

use Fhaculty\Graph\Cycle;

use Fhaculty\Graph\Walk;
use Fhaculty\Graph;

class NegativeCycleException extends UnexpectedValueException implements Graph\Exception
{
/**
* instance of the cycle
*
* @var Cycle
* @var Walk
*/
private $cycle;

public function __construct($message, $code = NULL, $previous = NULL, Cycle $cycle)
public function __construct($message, $code = NULL, $previous = NULL, Walk $cycle)
{
parent::__construct($message, $code, $previous);
$this->cycle = $cycle;
}

/**
*
* @return Cycle
* @return Walk
*/
public function getCycle()
{
Expand Down

0 comments on commit 2bd1477

Please sign in to comment.