1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graphp\Graph\Types; |
4
|
|
|
|
5
|
|
|
use Graphp\Graph\AbstractGraph; |
6
|
|
|
use Graphp\Graph\Builder\GraphTypeBuilder; |
7
|
|
|
use Graphp\Graph\Builder\GraphBuilder; |
8
|
|
|
use Graphp\Util\SupplierUtil; |
9
|
|
|
use Graphp\Util\SupplierInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DefaultDirectedGraph |
13
|
|
|
* |
14
|
|
|
* @package Graphp\Graph\Types |
15
|
|
|
*/ |
16
|
|
|
class DefaultDirectedGraph extends AbstractGraph |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Create a new default directed graph |
20
|
|
|
* |
21
|
|
|
* @param string $edgeClass - the edge class |
22
|
|
|
* @param SupplierInterface $vertexSupplier - the vertex supplier |
23
|
|
|
* @param SupplierInterface $edgeSupplier - the edge supplier |
24
|
|
|
* @param bool $weighted - if the graph is weighted |
25
|
|
|
*/ |
26
|
20 |
|
public function __construct( |
27
|
|
|
?string $edgeClass = null, |
28
|
|
|
?SupplierInterface $vertexSupplier = null, |
29
|
|
|
?SupplierInterface $edgeSupplier = null, |
30
|
|
|
?bool $weighted = null |
31
|
|
|
) { |
32
|
20 |
|
$builder = new GraphTypeBuilder(); |
33
|
20 |
|
$graphType = $builder->directed() |
34
|
20 |
|
->allowSelfLoops(true) |
35
|
20 |
|
->allowMultipleEdges(false) |
36
|
20 |
|
->allowCycles(false) |
37
|
20 |
|
->weighted($weighted) |
38
|
20 |
|
->build(); |
39
|
20 |
|
if (!is_null($edgeClass)) { |
40
|
20 |
|
$util = new SupplierUtil(); |
41
|
20 |
|
$edgeSupplier = $util->createSupplier($edgeClass); |
42
|
20 |
|
parent::__construct( |
43
|
20 |
|
$vertexSupplier, |
44
|
20 |
|
$edgeSupplier, |
45
|
20 |
|
$graphType |
46
|
|
|
); |
47
|
|
|
} else { |
48
|
|
|
parent::__construct( |
49
|
|
|
$vertexSupplier, |
50
|
|
|
$edgeSupplier, |
51
|
|
|
$graphType |
52
|
|
|
); |
53
|
|
|
} |
54
|
20 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create a default directed graph builder |
58
|
|
|
* |
59
|
|
|
* @param string $edgeClass - the edge class |
60
|
|
|
* @param SupplierInterface $edgeSupplier - the edge supplier |
61
|
|
|
* |
62
|
|
|
* @return GraphBuilder |
63
|
|
|
*/ |
64
|
|
|
public function createBuilder(?string $edgeClass = null, ?SupplierInterface $edgeSupplier = null): GraphBuilder |
65
|
|
|
{ |
66
|
|
|
if (!is_null($edgeClass)) { |
67
|
|
|
return new GraphBuilder(new DefaultDirectedGraph($edgeClass)); |
68
|
|
|
} |
69
|
|
|
return new GraphBuilder(new DefaultDirectedGraph(null, $edgeSupplier)); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|