3
3
namespace Fhaculty \Graph \Algorithm \Property ;
4
4
5
5
use Fhaculty \Graph \Walk ;
6
+ use Fhaculty \Graph \Set \Edges ;
6
7
use Fhaculty \Graph \Algorithm \Base as BaseAlgorithm ;
7
8
use Fhaculty \Graph \Algorithm \Loop as AlgorithmLoop ;
8
9
@@ -60,8 +61,8 @@ public function __construct(Walk $walk)
60
61
*/
61
62
public function isCycle ()
62
63
{
63
- $ vertices = $ this ->walk ->getVerticesSequence ();
64
- return (reset ($ vertices ) === end ($ vertices ) && $ this ->walk ->getEdges ());
64
+ $ vertices = $ this ->walk ->getVertices ()-> getVector ();
65
+ return (reset ($ vertices ) === end ($ vertices ) && ! $ this ->walk ->getEdges ()-> isEmpty ());
65
66
}
66
67
67
68
/**
@@ -114,7 +115,7 @@ public function isCircuit()
114
115
*/
115
116
public function isPath ()
116
117
{
117
- return !$ this ->hasArrayDuplicates ($ this ->walk ->getEdgesSequence ());
118
+ return !$ this ->hasArrayDuplicates ($ this ->walk ->getEdges ()-> getVector ());
118
119
}
119
120
120
121
/**
@@ -138,7 +139,7 @@ public function isPath()
138
139
*/
139
140
public function hasCycle ()
140
141
{
141
- return $ this ->hasArrayDuplicates ($ this ->walk ->getVerticesSequence ());
142
+ return $ this ->hasArrayDuplicates ($ this ->walk ->getVertices ()-> getVector ());
142
143
}
143
144
144
145
/**
@@ -215,9 +216,9 @@ public function isDigon()
215
216
// exactly 2 edges
216
217
return ($ this ->walk ->getNumberOfEdges () === 2 &&
217
218
// no duplicate edges
218
- !$ this ->hasArrayDuplicates ($ this ->walk ->getEdgesSequence ()) &&
219
+ !$ this ->hasArrayDuplicates ($ this ->walk ->getEdges ()-> getVector ()) &&
219
220
// exactly two distinct vertices
220
- count ($ this ->walk ->getVertices ()) === 2 &&
221
+ count ($ this ->walk ->getVertices ()-> getVerticesDistinct () ) === 2 &&
221
222
// this is actually a cycle
222
223
$ this ->isCycle ());
223
224
}
@@ -239,7 +240,7 @@ public function isTriangle()
239
240
// exactly 3 (implicitly distinct) edges
240
241
return ($ this ->walk ->getNumberOfEdges () === 3 &&
241
242
// exactly three distinct vertices
242
- count ($ this ->walk ->getVertices ()) === 3 &&
243
+ count ($ this ->walk ->getVertices ()-> getVerticesDistinct () ) === 3 &&
243
244
// this is actually a cycle
244
245
$ this ->isCycle ());
245
246
}
@@ -293,7 +294,7 @@ public function isTriangle()
293
294
*/
294
295
public function isSimple ()
295
296
{
296
- $ vertices = $ this ->walk ->getVerticesSequence ();
297
+ $ vertices = $ this ->walk ->getVertices ()-> getVector ();
297
298
// ignore starting vertex for cycles as it's always the same as ending vertex
298
299
if ($ this ->isCycle ()) {
299
300
unset($ vertices [0 ]);
@@ -314,12 +315,12 @@ public function isSimple()
314
315
*/
315
316
public function isHamiltonian ()
316
317
{
317
- $ vertices = $ this ->walk ->getVerticesSequence ();
318
+ $ vertices = $ this ->walk ->getVertices ()-> getVector ();
318
319
// ignore starting vertex for cycles as it's always the same as ending vertex
319
320
if ($ this ->isCycle ()) {
320
321
unset($ vertices [0 ]);
321
322
}
322
- return $ this ->isArrayContentsEqual ($ vertices , $ this ->walk ->getGraph ()->getVertices ());
323
+ return $ this ->isArrayContentsEqual ($ vertices , $ this ->walk ->getGraph ()->getVertices ()-> getVector () );
323
324
}
324
325
325
326
/**
@@ -332,7 +333,7 @@ public function isHamiltonian()
332
333
*/
333
334
public function isEulerian ()
334
335
{
335
- return $ this ->isArrayContentsEqual ($ this ->walk ->getEdgesSequence () , $ this ->walk ->getGraph ()->getEdges ());
336
+ return $ this ->isArrayContentsEqual ($ this ->walk ->getEdges ()-> getVector () , $ this ->walk ->getGraph ()->getEdges ()-> getVector ());
336
337
}
337
338
338
339
/**
0 commit comments