File tree Expand file tree Collapse file tree 16 files changed +36
-259
lines changed Expand file tree Collapse file tree 16 files changed +36
-259
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
- use Fhaculty \Graph \Algorithm \Base ;
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Graph ;
7
7
use Fhaculty \Graph \Vertex ;
8
8
15
15
* @link http://en.wikipedia.org/wiki/Flow_network
16
16
* @see Algorithm\Degree if you're looking for balanced degrees instead of balanced flows
17
17
*/
18
- class Balance extends Base
18
+ class Balance extends BaseGraph
19
19
{
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
-
37
20
public function getBalance ()
38
21
{
39
22
$ balance = 0 ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Exception \UnexpectedValueException ;
6
7
use Fhaculty \Graph \Graph ;
7
8
use Fhaculty \Graph \Vertex ;
8
9
9
- class Bipartit extends Base
10
+ class Bipartit extends BaseGraph
10
11
{
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
-
23
12
/**
24
13
* check whether this graph is bipartit
25
14
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Graph ;
6
7
7
8
/**
13
14
* @link http://en.wikipedia.org/wiki/Complete_graph
14
15
* @link http://mathworld.wolfram.com/CompleteGraph.html
15
16
*/
16
- class Complete extends Base
17
+ class Complete extends BaseGraph
17
18
{
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
-
35
19
/**
36
20
* checks whether this graph is complete (every vertex has an edge to any other vertex)
37
21
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Algorithm \Search \BreadthFirst as SearchBreadthFirst ;
6
7
7
8
use Fhaculty \Graph \Exception \InvalidArgumentException ;
8
9
9
10
use Fhaculty \Graph \Graph ;
10
11
use Fhaculty \Graph \Vertex ;
11
12
12
- class ConnectedComponents extends Base
13
+ class ConnectedComponents extends BaseGraph
13
14
{
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
-
29
15
/**
30
16
* create subgraph with all vertices connected to given vertex (i.e. the connected component of ths given vertex)
31
17
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
- use Fhaculty \Graph \Algorithm \Base ;
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Graph ;
7
7
use Fhaculty \Graph \Vertex ;
8
8
use Fhaculty \Graph \Exception \UnexpectedValueException ;
9
9
10
10
/**
11
11
* Basic algorithms for working with the degrees of Graphs.
12
- *
12
+ *
13
13
* The degree (or valency) of a Vertex of a Graph is the number of Edges
14
14
* incident to the Vertex, with Loops counted twice.
15
- *
15
+ *
16
16
* @link http://en.wikipedia.org/wiki/Degree_%28graph_theory%29
17
17
* @link http://en.wikipedia.org/wiki/Regular_graph
18
18
*/
19
- class Degree extends Base
19
+ class Degree extends BaseGraph
20
20
{
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
-
38
21
/**
39
22
* get degree for k-regular-graph (only if each vertex has the same degree)
40
23
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Exception \UnderflowException ;
6
7
7
8
use Fhaculty \Graph \Graph ;
8
9
use Fhaculty \Graph \Vertex ;
9
10
use Fhaculty \Graph \Exception \NegativeCycleException ;
10
11
use Fhaculty \Graph \Algorithm \ShortestPath \MooreBellmanFord as SpMooreBellmanFord ;
11
12
12
- class DetectNegativeCycle extends Base
13
+ class DetectNegativeCycle extends BaseGraph
13
14
{
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
-
29
15
/**
30
16
* check if the input graph has any negative cycles
31
17
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
- use Fhaculty \Graph \Set ;
6
- use Fhaculty \Graph \Algorithm \Base ;
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
7
6
use Fhaculty \Graph \Edge \Directed as EdgeDirected ;
8
- use Fhaculty \Graph \Graph ;
9
- use Fhaculty \Graph \Walk ;
10
7
11
8
/**
12
9
* Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks.
13
10
*
14
11
* @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Direction
15
12
* @link http://en.wikipedia.org/wiki/Digraph_%28mathematics%29
16
13
*/
17
- class Directed extends Base
14
+ class Directed extends BaseSet
18
15
{
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
-
36
16
/**
37
17
* checks whether the graph has any directed edges (aka digraph)
38
18
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Graph ;
6
7
7
- class Eulerian extends Base
8
+ class Eulerian extends BaseGraph
8
9
{
9
- /**
10
- *
11
- * @var Graph
12
- */
13
- private $ graph ;
14
-
15
- public function __construct (Graph $ graph )
16
- {
17
- $ this ->graph = $ graph ;
18
- }
19
-
20
10
/**
21
11
* check whether this graph has an eulerian cycle
22
12
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Graph ;
6
7
7
- class Groups extends Base
8
+ class Groups extends BaseGraph
8
9
{
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
-
26
10
/**
27
11
* count total number of different groups assigned to vertices
28
12
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm \MaximumMatching ;
4
4
5
+ use Fhaculty \Graph \Algorithm \BaseGraph ;
5
6
use Fhaculty \Graph \Graph ;
6
7
use Fhaculty \Graph \Edge \Base as Edge ;
7
- use Fhaculty \Graph \Algorithm \Base as AlgorithmBase ;
8
8
9
- abstract class Base extends AlgorithmBase
9
+ abstract class Base extends BaseGraph
10
10
{
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
-
29
11
/**
30
12
* Get the count of edges that are in the match
31
13
*
You can’t perform that action at this time.
0 commit comments