Issues (34)

src/GraphInterface.php (1 issue)

1
<?php
2
3
namespace Graphp;
4
5
use Graphp\Graph\GraphTypeInterface;
6
use Graphp\Edge\EdgeInterface;
7
use Graphp\Edge\EdgeSetFactoryInterface;
8
use Graphp\Edge\EdgeSet;
9
use Graphp\Vertex\VertexInterface;
10
use Graphp\Vertex\VertexSet;
11
use Graphp\Util\SupplierInterface;
12
13
/**
14
 * Interface GraphInterface
15
 *
16
 * @package Graphp
17
 */
18
interface GraphInterface
19
{
20
    /**
21
     * Default edge weight
22
     *
23
     * @var float
24
     */
25
    public const DEFAULT_EDGE_WEIGHT = 1.0;
26
27
    /**
28
     * Get the graph type
29
     *
30
     * @return GraphTypeInterface
31
     */
32
    public function getType(): GraphTypeInterface;
33
34
    /**
35
     * Get all edges connecting the source vertext to the target vertex
36
     *
37
     * @return EdgeSet
38
     */
39
    public function getAllEdges(VertexInterface $sourceVertex, VertexInterface $targetVertex): EdgeSet;
40
    
41
    /**
42
     * Get an edge connecting the source vertext to the target vertex
43
     *
44
     * @return null|EdgeInterface
45
     */
46
    public function getEdge(VertexInterface $sourceVertex, VertexInterface $targetVertex): ?EdgeInterface;
47
    
48
    /**
49
     * Get the vertex supplier that the graph uses whenever it needs to create new vertices
50
     *
51
     * @return null|SupplierInterface
52
     */
53
    public function getVertexSupplier(): ?SupplierInterface;
54
55
    /**
56
     * Get the edge supplier that the graph uses whenever it needs to create new edges
57
     *
58
     * @return SupplierInterface
59
     */
60
    public function getEdgeSupplier(): SupplierInterface;
61
    
62
    /**
63
     * Create a new edge in the graph. Return the newly created edge if added to the graph.
64
     *
65
     * @return null|EdgeInterface
66
     */
67
    public function addEdge(
68
        VertexInterface $sourceVertex,
69
        VertexInterface $targetVertex,
70
        ?EdgeInterface $edge = null
71
    ): ?EdgeInterface;
72
    
73
    /**
74
     * Create and return a new vertex in the graph.
75
     *
76
     * @return null|VertexInterface
77
     */
78
    public function addVertex(VertexInterface $vertex): ?VertexInterface;
79
    
80
    /**
81
     * Check if the graph contains the given edge, specified either by two vertices or by the edge itself
82
     *
83
     * @param VertexInterface $sourceVertex - the source vertex
84
     * @param VertexInterface $targetVertex - the target vertex
85
     * @param EdgeInterface $edge - the edge
86
     *
87
     * @return bool
88
     */
89
    public function containsEdge(
90
        ?VertexInterface $sourceVertex = null,
91
        ?VertexInterface $targetVertex = null,
92
        ?EdgeInterface $edge = null
93
    ): bool;
94
    
95
    /**
96
     * Check if the graph contains the given vertex
97
     *
98
     * @return bool
99
     */
100
    public function containsVertex(VertexInterface $vertex): bool;
101
    
102
    /**
103
     * Get a set of all edges touching the specified vertex
104
     *
105
     * @param VertexInterface - the vertex
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
106
     *
107
     * @return EdgeSet
108
     */
109
    public function edgesOf(VertexInterface $vertex): EdgeSet;
110
    
111
    /**
112
     * Get a set of all edges incoming into the specified vertex
113
     *
114
     * @param VertexInterface $vertex - the vertex
115
     *
116
     * @return EdgeSet
117
     */
118
    public function incomingEdgesOf(VertexInterface $vertex): EdgeSet;
119
120
    /**
121
     * Get a set of all edges outgoing from the specified vertex
122
     *
123
     * @param VertexInterface $vertex - the vertex
124
     *
125
     * @return EdgeSet
126
     */
127
    public function outgoingEdgesOf(VertexInterface $vertex): EdgeSet;
128
    
129
    /**
130
     * Remove all edges specified by two vertices or the the list of edges themselves.
131
     * Return true, if graph was changed
132
     *
133
     * @param VertexInterface $vertex - the source vertex
134
     * @param VertexInterface $vertex - the target vertex
135
     * @param EdgeSet $edges - the edges
136
     *
137
     * @return bool
138
     */
139
    public function removeAllEdges(
140
        ?VertexInterface $sourceVertex = null,
141
        ?VertexInterface $targetVertex = null,
142
        EdgeSet $edges
143
    ): bool;
144
    
145
    /**
146
     * Remove all specified vertices contained in the graph.
147
     * Return true, if graph was changed
148
     *
149
     * @param VertexSet $vertices - the vertices
150
     *
151
     * @return bool
152
     */
153
    public function removeAllVertices(VertexSet $vertices): bool;
154
    
155
    /**
156
     * Remove the specifeid edge from the graph.
157
     * Return the edge, if it was removed
158
     *
159
     * @param VertexInterface $sourceVertex - the source vertex
160
     * @param VertexInterface $targetVertex - the target vertex
161
     * @param EdgeInterface $edge - the edge
162
     *
163
     * @return null|EdgeInterface
164
     */
165
    public function removeEdge(
166
        ?VertexInterface $sourceVertex = null,
167
        ?VertexInterface $targetVertex = null,
168
        ?EdgeInterface $edge = null
169
    ): ?EdgeInterface;
170
    
171
    /**
172
     * Remove the specifeid vertex from the graph.
173
     * Return the true, if it was removed
174
     *
175
     * @param VertexInterface $vertex - the vertex
176
     *
177
     * @return bool
178
     */
179
    public function removeVertex(VertexInterface $vertex): bool;
180
    
181
    /**
182
     * Get the set of edges contained in the graph
183
     *
184
     * @return EdgeSet
185
     */
186
    public function edgeSet(): EdgeSet;
187
188
    /**
189
     * Get the set of vertices contained in the graph
190
     *
191
     * @return VertexSet
192
     */
193
    public function vertexSet(): VertexSet;
194
    
195
    /**
196
     * Get the edge source vertex
197
     *
198
     * @param EdgeInterface $edge - the edge
199
     *
200
     * @return VertexInterface
201
     */
202
    public function getEdgeSource(EdgeInterface $edge): VertexInterface;
203
    
204
    /**
205
     * Get the edge target vertex
206
     *
207
     * @param EdgeInterface $edge - the edge
208
     *
209
     * @return VertexInterface
210
     */
211
    public function getEdgeTarget(EdgeInterface $edge): VertexInterface;
212
    
213
    /**
214
     * Get the edge weight
215
     *
216
     * @param EdgeInterface $edge - the edge
217
     *
218
     * @return null|float
219
     */
220
    public function getEdgeWeight(EdgeInterface $edge): ?float;
221
    
222
    /**
223
     * Set the edge weight
224
     *
225
     * @param EdgeInterface $edge - the edge
226
     * @param float $weight - the edge weight
227
     */
228
    public function setEdgeWeight(EdgeInterface $edge, ?float $weight = null): void;
229
}
230