|
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 DirectedPseudograph |
|
13
|
|
|
* |
|
14
|
|
|
* @package Graphp\Graph\Types |
|
15
|
|
|
*/ |
|
16
|
|
|
class DirectedPseudograph 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
|
5 |
|
public function __construct( |
|
27
|
|
|
?string $edgeClass = null, |
|
28
|
|
|
?SupplierInterface $vertexSupplier = null, |
|
29
|
|
|
?SupplierInterface $edgeSupplier = null, |
|
30
|
|
|
?bool $weighted = null |
|
31
|
|
|
) { |
|
32
|
5 |
|
$builder = new GraphTypeBuilder(); |
|
33
|
5 |
|
$graphType = $builder->directed() |
|
34
|
5 |
|
->allowSelfLoops(true) |
|
35
|
5 |
|
->allowMultipleEdges(true) |
|
36
|
5 |
|
->weighted($weighted) |
|
37
|
5 |
|
->build(); |
|
38
|
5 |
|
if (!is_null($edgeClass)) { |
|
39
|
5 |
|
$util = new SupplierUtil(); |
|
40
|
5 |
|
$edgeSupplier = $util->createSupplier($edgeClass); |
|
41
|
5 |
|
parent::__construct( |
|
42
|
5 |
|
$vertexSupplier, |
|
43
|
5 |
|
$edgeSupplier, |
|
44
|
5 |
|
$graphType |
|
45
|
|
|
); |
|
46
|
|
|
} else { |
|
47
|
|
|
parent::__construct( |
|
48
|
|
|
$vertexSupplier, |
|
49
|
|
|
$edgeSupplier, |
|
50
|
|
|
$graphType |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
5 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Create a default directed graph builder |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $edgeClass - the edge class |
|
59
|
|
|
* @param SupplierInterface $edgeSupplier - the edge supplier |
|
60
|
|
|
* |
|
61
|
|
|
* @return GraphBuilder |
|
62
|
|
|
*/ |
|
63
|
|
|
public function createBuilder(?string $edgeClass = null, ?SupplierInterface $edgeSupplier = null): GraphBuilder |
|
64
|
|
|
{ |
|
65
|
|
|
if (!is_null($edgeClass)) { |
|
66
|
|
|
return new GraphBuilder(new DirectedPseudograph($edgeClass)); |
|
67
|
|
|
} |
|
68
|
|
|
return new GraphBuilder(new DirectedPseudograph(null, $edgeSupplier)); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|