Skip to content

Commit 9170044

Browse files
committed
Merge branch 'master' into fix-algo-minimumcostflow
Conflicts: lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php
2 parents cbc691c + 23985a2 commit 9170044

38 files changed

Lines changed: 592 additions & 229 deletions

CHANGELOG.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,50 @@ This file is a manually maintained list of changes for each release. Feel free
44
to add your changes here when sending pull requests. Also send corrections if
55
you spot any mistakes.
66

7-
## 0.7.0 (2013-xx-xx)
7+
## 0.8.0 (2013-xx-xx)
8+
9+
* BC break: Rename `Algorithm\Directed::isDirected()` to remove its ambiguity
10+
in regards to mixed and/or empty graphs
11+
([#80](https://github.com/clue/graph/issues/80))
12+
13+
| Old name | New name |
14+
|---|---|
15+
| `Algorithm\Directed::isDirected()` | `Algorithm\Directed::hasDirected()` |
16+
17+
* Feature:: Add new `Algorithm\Directed::hasUndirected()` and
18+
`Algorithm\Directed::isMixed()` in order to complement the renamed
19+
`Algorithm\Directed::hasDirected()`
20+
([#80](https://github.com/clue/graph/issues/80))
21+
22+
* BC break: `Walk::factoryCycleFromVertices()` no longer tries to auto-complete
23+
a cycle if the first vertex does not match the last one, but now throws an
24+
`InvalidArgumentException` instead ([#87](https://github.com/clue/graph/issues/87)
25+
26+
* Feature: Support loop `Walk`s, i.e. a walk with only a single edge from
27+
vertex A back to A ([#87](https://github.com/clue/graph/issues/87)
28+
29+
* Fix: Stricter checks for invalid cycles, such as one with an invalid
30+
predecessor-map or no edges at all ([#87](https://github.com/clue/graph/issues/87)
31+
32+
* Fix: The `Algorithm\ShortestPath\MooreBellmanFord` now also works for unweighted
33+
edges. This also fixes an issue where `Algorithm\DetectNegativeCycle` didn't work
34+
for unweighted edges. ([#81](https://github.com/clue/graph/issues/81)
35+
36+
* Fix: Throwing an `UnexpectedValueException` if writing GraphViz Dot script
37+
to a temporary file fails and remove its debugging output
38+
([#77](https://github.com/clue/graph/issues/77) and [#78](https://github.com/clue/graph/issues/78) @Metabor)
39+
40+
* BC break: Remove unneeded alias definitions of `getVertexFirst()`,
41+
`getVertexSource()` and `getVertexTarget()`
42+
[#76]https://github.com/clue/graph/issues/76)):
43+
44+
| Old name | New name |
45+
|---|---|
46+
| `Graph::getVertexFirst()` | `Graph::getVertices()->getVertexFirst()` |
47+
| `Walk::getVertexSource()` | `Walk::getVertices()->getVertexFirst()` |
48+
| `Walk::getVertexTarget()` | `Walk::getVertices()->getVertexLast()` |
49+
50+
## 0.7.0 (2013-09-11)
851

952
* Feature: Add new `Set\Vertices` and `Set\Edges` classes that handle common
1053
operations on a Set of multiple `Vertex` and `Edge` instances respectively.
@@ -75,6 +118,20 @@ you spot any mistakes.
75118
accordingly.
76119
([#72](https://github.com/clue/graph/issues/72))
77120

121+
* BC break: Remove all occurances of `getNumberOfVertices()` and
122+
`getNumberOfEdges()` ([#75](https://github.com/clue/graph/issues/75) and
123+
[#48](https://github.com/clue/graph/issues/48)):
124+
125+
| Old name | New name |
126+
|---|---|
127+
| `$set->getNumberOfVertices()` | `count($set->getVertices())` |
128+
| `$set->getNumberOfEdges()` | `count($set->getEdges())` |
129+
130+
* BC break: Replace base `Set` class with `Set\DualAggregate` interface. This
131+
is unlikely to affect you, but might potentially break your custom
132+
inheritance or polymorphism for algorithms.
133+
([#75](https://github.com/clue/graph/issues/75))
134+
78135
* Feature: Add `Algorithm\ShortestPath\Base::hasVertex(Vertex $vertex)` to check whether
79136
a path to the given Vertex exists ([#62](https://github.com/clue/graph/issues/62)).
80137

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The recommended way to install this library is [through composer](http://getcomp
8181
```JSON
8282
{
8383
"require": {
84-
"clue/graph": "dev-master"
84+
"clue/graph": "0.7.*"
8585
}
8686
}
8787
```
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Fhaculty\Graph\Algorithm;
44

55
use Fhaculty\Graph\Algorithm\Base;
6-
use Fhaculty\Graph\Set;
6+
use Fhaculty\Graph\Set\DualAggregate;
77
use Fhaculty\Graph\Graph;
88
use Fhaculty\Graph\Walk;
99

@@ -12,12 +12,12 @@
1212
*
1313
* @see Set
1414
*/
15-
abstract class BaseSet extends Base
15+
abstract class BaseDual extends Base
1616
{
1717
/**
1818
* Set to operate on
1919
*
20-
* @var Set
20+
* @var DualAggregate
2121
*/
2222
protected $set;
2323

@@ -26,7 +26,7 @@ abstract class BaseSet extends Base
2626
*
2727
* @param Graph|Walk|Set $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
2828
*/
29-
public function __construct(Set $graphOrWalk)
29+
public function __construct(DualAggregate $graphOrWalk)
3030
{
3131
$this->set = $graphOrWalk;
3232
}

lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,20 @@ private function createSearch(Vertex $vertex)
6565
* connected here.
6666
*
6767
* @return boolean
68-
* @uses AlgorithmSearchBreadthFirst::getNumberOfVertices()
6968
* @see self::getNumberOfComponents()
7069
*/
7170
public function isSingle()
7271
{
7372
try {
74-
$vertex = $this->graph->getVertexFirst();
73+
$vertex = $this->graph->getVertices()->getVertexFirst();
7574
}
7675
catch (UnderflowException $e) {
7776
// no first vertex => empty graph => has zero components
7877
return false;
7978
}
8079
$alg = $this->createSearch($vertex);
8180

82-
return ($this->graph->getNumberOfVertices() === $alg->getNumberOfVertices());
81+
return (count($this->graph->getVertices()) === count($alg->getVertices()));
8382
}
8483

8584
/**

lib/Fhaculty/Graph/Algorithm/Degree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Degree extends BaseGraph
3131
public function getDegree()
3232
{
3333
// get initial degree of any start vertex to compare others to
34-
$degree = $this->getDegreeVertex($this->graph->getVertexFirst());
34+
$degree = $this->getDegreeVertex($this->graph->getVertices()->getVertexFirst());
3535

3636
foreach ($this->graph->getVertices() as $vertex) {
3737
/** @var $vertex Vertex */

lib/Fhaculty/Graph/Algorithm/Directed.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44

55
use Fhaculty\Graph\Algorithm\BaseGraph;
66
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
7+
use Fhaculty\Graph\Edge\Undirected as EdgeUndirected;
78

89
/**
910
* Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks.
1011
*
1112
* @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Direction
1213
* @link http://en.wikipedia.org/wiki/Digraph_%28mathematics%29
1314
*/
14-
class Directed extends BaseSet
15+
class Directed extends BaseDual
1516
{
1617
/**
17-
* checks whether the graph has any directed edges (aka digraph)
18+
* checks whether the graph has any directed edges
19+
*
20+
* This method is intentionally not named "isDirected()" (aka digraph),
21+
* because that might be misleading in regards to empty and/or mixed graphs.
1822
*
1923
* @return boolean
2024
*/
21-
public function isDirected()
25+
public function hasDirected()
2226
{
2327
foreach ($this->set->getEdges() as $edge) {
2428
if ($edge instanceof EdgeDirected) {
@@ -28,4 +32,35 @@ public function isDirected()
2832

2933
return false;
3034
}
35+
36+
/**
37+
* checks whether the graph has any undirected edges
38+
*
39+
* This method is intentionally not named "isUndirected()",
40+
* because that might be misleading in regards to empty and/or mixed graphs.
41+
*
42+
* @return boolean
43+
*/
44+
public function hasUndirected()
45+
{
46+
foreach ($this->set->getEdges() as $edge) {
47+
if ($edge instanceof EdgeUndirected) {
48+
return true;
49+
}
50+
}
51+
52+
return false;
53+
}
54+
55+
/**
56+
* checks whether this is a mixed graph (contains both directed and undirected edges)
57+
*
58+
* @return boolean
59+
* @uses self::hasDirected()
60+
* @uses self::hasUndirected()
61+
*/
62+
public function isMixed()
63+
{
64+
return ($this->hasDirected() && $this->hasUndirected());
65+
}
3166
}

lib/Fhaculty/Graph/Algorithm/Flow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @link http://en.wikipedia.org/wiki/Flow_network
1919
* @see Algorithm\Balance
2020
*/
21-
class Flow extends BaseSet
21+
class Flow extends BaseDual
2222
{
2323
/**
2424
* check if this graph has any flow set (any edge has a non-NULL flow)

lib/Fhaculty/Graph/Algorithm/Loop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Fhaculty\Graph\Algorithm;
44

5-
use Fhaculty\Graph\Algorithm\BaseSet;
5+
use Fhaculty\Graph\Algorithm\BaseDual;
66
use Fhaculty\Graph\Edge\Base as Edge;
77
use Fhaculty\Graph\Vertex;
88

@@ -14,7 +14,7 @@
1414
*
1515
* @link http://en.wikipedia.org/wiki/Loop_%28graph_theory%29
1616
*/
17-
class Loop extends BaseSet
17+
class Loop extends BaseDual
1818
{
1919
/**
2020
* checks whether this graph has any loops (edges from vertex to itself)

lib/Fhaculty/Graph/Algorithm/MaximumMatching/Flow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Flow extends Base
1818
public function getEdges()
1919
{
2020
$alg = new Directed($this->graph);
21-
if ($alg->isDirected()) {
21+
if ($alg->hasDirected()) {
2222
throw new UnexpectedValueException('Input graph contains directed edges');
2323
}
2424

lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getEdges()
125125

126126
// definition of spanning tree: number of edges = number of vertices - 1
127127
// above algorithm does not check isolated edges or may otherwise return multiple connected components => force check
128-
if (count($returnEdges) !== ($this->graph->getNumberOfVertices() - 1)) {
128+
if (count($returnEdges) !== (count($this->graph->getVertices()) - 1)) {
129129
throw new UnexpectedValueException('Graph is not connected');
130130
}
131131

0 commit comments

Comments
 (0)