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 Pseudograph |
13
|
|
|
* |
14
|
|
|
* @package Graphp\Graph\Types |
15
|
|
|
*/ |
16
|
|
|
class Pseudograph extends AbstractGraph |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Create a new pseudograph |
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
|
2 |
|
public function __construct( |
27
|
|
|
?string $edgeClass = null, |
28
|
|
|
?SupplierInterface $vertexSupplier = null, |
29
|
|
|
?SupplierInterface $edgeSupplier = null, |
30
|
|
|
?bool $weighted = null |
31
|
|
|
) { |
32
|
2 |
|
$builder = new GraphTypeBuilder(); |
33
|
2 |
|
$graphType = $builder->undirected() |
34
|
2 |
|
->allowSelfLoops(true) |
35
|
2 |
|
->allowMultipleEdges(true) |
36
|
2 |
|
->weighted($weighted) |
37
|
2 |
|
->build(); |
38
|
2 |
|
if (!is_null($edgeClass)) { |
39
|
2 |
|
$util = new SupplierUtil(); |
40
|
2 |
|
$edgeSupplier = $util->createSupplier($edgeClass); |
41
|
2 |
|
parent::__construct( |
42
|
2 |
|
$vertexSupplier, |
43
|
2 |
|
$edgeSupplier, |
44
|
2 |
|
$graphType |
45
|
|
|
); |
46
|
|
|
} else { |
47
|
|
|
parent::__construct( |
48
|
|
|
$vertexSupplier, |
49
|
|
|
$edgeSupplier, |
50
|
|
|
$graphType |
51
|
|
|
); |
52
|
|
|
} |
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Create a pseudograph 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 Pseudograph($edgeClass)); |
67
|
|
|
} |
68
|
|
|
return new GraphBuilder(new Pseudograph(null, $edgeSupplier)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|