Skip to content

Commit 937ca8e

Browse files
committed
Base on BaseGraph and BaseSet
1 parent dd9f340 commit 937ca8e

16 files changed

+36
-259
lines changed

src/Balance.php

Lines changed: 2 additions & 19 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\Base;
5+
use Fhaculty\Graph\Algorithm\BaseGraph;
66
use Fhaculty\Graph\Graph;
77
use Fhaculty\Graph\Vertex;
88

@@ -15,25 +15,8 @@
1515
* @link http://en.wikipedia.org/wiki/Flow_network
1616
* @see Algorithm\Degree if you're looking for balanced degrees instead of balanced flows
1717
*/
18-
class Balance extends Base
18+
class Balance extends BaseGraph
1919
{
20-
/**
21-
* Graph to operate on
22-
*
23-
* @var Graph
24-
*/
25-
private $graph;
26-
27-
/**
28-
* instanciate new Balance algorithm
29-
*
30-
* @param Graph $graph graph to operate on
31-
*/
32-
public function __construct(Graph $graph)
33-
{
34-
$this->graph = $graph;
35-
}
36-
3720
public function getBalance()
3821
{
3922
$balance = 0;

src/Bipartit.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Exception\UnexpectedValueException;
67
use Fhaculty\Graph\Graph;
78
use Fhaculty\Graph\Vertex;
89

9-
class Bipartit extends Base
10+
class Bipartit extends BaseGraph
1011
{
11-
/**
12-
* input graph to operate on
13-
*
14-
* @var Graph
15-
*/
16-
private $graph;
17-
18-
public function __construct(Graph $graph)
19-
{
20-
$this->graph = $graph;
21-
}
22-
2312
/**
2413
* check whether this graph is bipartit
2514
*

src/Complete.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Graph;
67

78
/**
@@ -13,25 +14,8 @@
1314
* @link http://en.wikipedia.org/wiki/Complete_graph
1415
* @link http://mathworld.wolfram.com/CompleteGraph.html
1516
*/
16-
class Complete extends Base
17+
class Complete extends BaseGraph
1718
{
18-
/**
19-
* Graph to operate on
20-
*
21-
* @var Graph
22-
*/
23-
private $graph;
24-
25-
/**
26-
* instantiate new complete algorithm
27-
*
28-
* @param Graph $graph
29-
*/
30-
public function __construct(Graph $graph)
31-
{
32-
$this->graph = $graph;
33-
}
34-
3519
/**
3620
* checks whether this graph is complete (every vertex has an edge to any other vertex)
3721
*

src/ConnectedComponents.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Algorithm\Search\BreadthFirst as SearchBreadthFirst;
67

78
use Fhaculty\Graph\Exception\InvalidArgumentException;
89

910
use Fhaculty\Graph\Graph;
1011
use Fhaculty\Graph\Vertex;
1112

12-
class ConnectedComponents extends Base
13+
class ConnectedComponents extends BaseGraph
1314
{
14-
/**
15-
*
16-
* @var Graph
17-
*/
18-
private $graph;
19-
20-
/**
21-
*
22-
* @param Graph $graph
23-
*/
24-
public function __construct(Graph $graph)
25-
{
26-
$this->graph = $graph;
27-
}
28-
2915
/**
3016
* create subgraph with all vertices connected to given vertex (i.e. the connected component of ths given vertex)
3117
*

src/Degree.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5-
use Fhaculty\Graph\Algorithm\Base;
5+
use Fhaculty\Graph\Algorithm\BaseGraph;
66
use Fhaculty\Graph\Graph;
77
use Fhaculty\Graph\Vertex;
88
use Fhaculty\Graph\Exception\UnexpectedValueException;
99

1010
/**
1111
* Basic algorithms for working with the degrees of Graphs.
12-
*
12+
*
1313
* The degree (or valency) of a Vertex of a Graph is the number of Edges
1414
* incident to the Vertex, with Loops counted twice.
15-
*
15+
*
1616
* @link http://en.wikipedia.org/wiki/Degree_%28graph_theory%29
1717
* @link http://en.wikipedia.org/wiki/Regular_graph
1818
*/
19-
class Degree extends Base
19+
class Degree extends BaseGraph
2020
{
21-
/**
22-
* Graph to operate on
23-
*
24-
* @var Graph
25-
*/
26-
private $graph;
27-
28-
/**
29-
* instanciate new degree algorithm
30-
*
31-
* @param Graph $graph
32-
*/
33-
public function __construct(Graph $graph)
34-
{
35-
$this->graph = $graph;
36-
}
37-
3821
/**
3922
* get degree for k-regular-graph (only if each vertex has the same degree)
4023
*

src/DetectNegativeCycle.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Exception\UnderflowException;
67

78
use Fhaculty\Graph\Graph;
89
use Fhaculty\Graph\Vertex;
910
use Fhaculty\Graph\Exception\NegativeCycleException;
1011
use Fhaculty\Graph\Algorithm\ShortestPath\MooreBellmanFord as SpMooreBellmanFord;
1112

12-
class DetectNegativeCycle extends Base
13+
class DetectNegativeCycle extends BaseGraph
1314
{
14-
/**
15-
*
16-
* @var Graph
17-
*/
18-
private $graph;
19-
20-
/**
21-
*
22-
* @param Graph $graph
23-
*/
24-
public function __construct(Graph $graph)
25-
{
26-
$this->graph = $graph;
27-
}
28-
2915
/**
3016
* check if the input graph has any negative cycles
3117
*

src/Directed.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5-
use Fhaculty\Graph\Set;
6-
use Fhaculty\Graph\Algorithm\Base;
5+
use Fhaculty\Graph\Algorithm\BaseGraph;
76
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
8-
use Fhaculty\Graph\Graph;
9-
use Fhaculty\Graph\Walk;
107

118
/**
129
* Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks.
1310
*
1411
* @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Direction
1512
* @link http://en.wikipedia.org/wiki/Digraph_%28mathematics%29
1613
*/
17-
class Directed extends Base
14+
class Directed extends BaseSet
1815
{
19-
/**
20-
* Graph/Walk to operate on
21-
*
22-
* @var Set
23-
*/
24-
private $set;
25-
26-
/**
27-
* instanciate new directed algorithm
28-
*
29-
* @param Set|Graph|Walk $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
30-
*/
31-
public function __construct(Set $graphOrWalk)
32-
{
33-
$this->set = $graphOrWalk;
34-
}
35-
3616
/**
3717
* checks whether the graph has any directed edges (aka digraph)
3818
*

src/Eulerian.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Graph;
67

7-
class Eulerian extends Base
8+
class Eulerian extends BaseGraph
89
{
9-
/**
10-
*
11-
* @var Graph
12-
*/
13-
private $graph;
14-
15-
public function __construct(Graph $graph)
16-
{
17-
$this->graph = $graph;
18-
}
19-
2010
/**
2111
* check whether this graph has an eulerian cycle
2212
*

src/Groups.php

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

33
namespace Fhaculty\Graph\Algorithm;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Graph;
67

7-
class Groups extends Base
8+
class Groups extends BaseGraph
89
{
9-
/**
10-
* graph to operate on
11-
*
12-
* @var Graph
13-
*/
14-
private $graph;
15-
16-
/**
17-
* instanciate algorithm on given graph
18-
*
19-
* @param Graph $graph
20-
*/
21-
public function __construct(Graph $graph)
22-
{
23-
$this->graph = $graph;
24-
}
25-
2610
/**
2711
* count total number of different groups assigned to vertices
2812
*

src/MaximumMatching/Base.php

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

33
namespace Fhaculty\Graph\Algorithm\MaximumMatching;
44

5+
use Fhaculty\Graph\Algorithm\BaseGraph;
56
use Fhaculty\Graph\Graph;
67
use Fhaculty\Graph\Edge\Base as Edge;
7-
use Fhaculty\Graph\Algorithm\Base as AlgorithmBase;
88

9-
abstract class Base extends AlgorithmBase
9+
abstract class Base extends BaseGraph
1010
{
11-
/**
12-
* Origianl graph
13-
*
14-
* @var Graph
15-
*/
16-
protected $graph;
17-
18-
/**
19-
* The given graph where the algorithm should operate on
20-
*
21-
* @param Graph $graph
22-
* @throws Exception if the given graph is not balanced
23-
*/
24-
public function __construct(Graph $graph)
25-
{
26-
$this->graph = $graph;
27-
}
28-
2911
/**
3012
* Get the count of edges that are in the match
3113
*

0 commit comments

Comments
 (0)