Skip to content

Commit

Permalink
Merge pull request #314 from tienvx/bruteforce-algorithm-need-at-leas…
Browse files Browse the repository at this point in the history
…t-3-verticles

Bruteforce algorithm need at least 3 verticles
  • Loading branch information
tienvx committed Jul 7, 2019
2 parents 640e643 + 33d721d commit 2f315e2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Generator/AllPlacesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tienvx\Bundle\MbtBundle\Generator;

use Exception;
use Fhaculty\Graph\Exception as GraphException;
use Generator;
use Graphp\Algorithms\TravelingSalesmanProblem\Bruteforce;
use Psr\Cache\InvalidArgumentException;
Expand Down Expand Up @@ -33,16 +34,19 @@ public function getAvailableTransitions(Workflow $workflow, AbstractSubject $sub
{
$graph = $this->graphBuilder->build($workflow);
$algorithm = new Bruteforce($graph);
$edges = $algorithm->getEdges();
$edges = $edges->getVector();
while (!empty($edges)) {
$edge = array_shift($edges);
$transitionName = $edge->getAttribute('name');
if ($workflow->can($subject, $transitionName)) {
yield $transitionName;
} else {
break;
try {
$edges = $algorithm->getEdges();
$edges = $edges->getVector();
while (!empty($edges)) {
$edge = array_shift($edges);
$transitionName = $edge->getAttribute('name');
if ($workflow->can($subject, $transitionName)) {
yield $transitionName;
} else {
break;
}
}
} catch (GraphException $exception) {
}
}

Expand Down

0 comments on commit 2f315e2

Please sign in to comment.