Skip to content

Commit 0b0bec1

Browse files
committed
Move Set directed helpers to new Algorithm\Directed
1 parent 327e431 commit 0b0bec1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Directed.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Fhaculty\Graph\Algorithm;
4+
5+
use Fhaculty\Graph\Set;
6+
use Fhaculty\Graph\Algorithm\Base;
7+
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
8+
9+
class Directed extends Base
10+
{
11+
private $set;
12+
13+
public function __construct(Set $graphOrWalk)
14+
{
15+
$this->set = $graphOrWalk;
16+
}
17+
18+
/**
19+
* checks whether the graph has any directed edges (aka digraph)
20+
*
21+
* @return boolean
22+
*/
23+
public function isDirected()
24+
{
25+
foreach ($this->set->getEdges() as $edge) {
26+
if ($edge instanceof EdgeDirected) {
27+
return true;
28+
}
29+
}
30+
31+
return false;
32+
}
33+
}

src/MaximumMatching/Flow.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Fhaculty\Graph\Algorithm\MaximumMatching;
44

5+
use Fhaculty\Graph\Algorithm\Directed;
6+
57
use Fhaculty\Graph\Exception\LogicException;
68

79
use Fhaculty\Graph\Exception\UnexpectedValueException;
@@ -14,7 +16,8 @@ class Flow extends Base
1416
{
1517
public function getEdges()
1618
{
17-
if ($this->graph->isDirected()) {
19+
$alg = new Directed($this->graph);
20+
if ($alg->isDirected()) {
1821
throw new UnexpectedValueException('Input graph contains directed edges');
1922
}
2023

0 commit comments

Comments
 (0)