From d57d36415991e94409d072115b72140fbe98f4ea Mon Sep 17 00:00:00 2001 From: letournel <4dr13n.l370urn3l@gmail.com> Date: Wed, 9 Dec 2015 00:19:06 +0100 Subject: [PATCH] fix: minor fixes, tu and php 7.0 support --- .travis.yml | 4 +- README.md | 6 +- composer.json | 2 + .../ShortestDistance/FloydWarshall.php | 2 +- .../TravelingSalesman/Christofides.php | 1 + .../TravelingSalesman/LinKernighan.php | 1 + src/Algorithms/TravelingSalesman/kOpt.php | 12 +--- tests/Converters/Grid/ASCIISyntaxTest.php | 70 ++++++++++++++++--- 8 files changed, 74 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 06c22a0..37588db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,11 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 + - 7.1 before_script: - composer install --dev script: - - phpunit \ No newline at end of file + - phpunit diff --git a/README.md b/README.md index 8f9327e..13a2783 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,11 @@ Zero Roadmap ------- -- New SSP solving algorithms +- New SSP solving algorithms: +[Kruskal](http://en.wikipedia.org/wiki/Kruskal%27s_algorithm) +[MooreBellmanFord](http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm) +[Prim](http://en.wikipedia.org/wiki/Prim%27s_algorithm) +or others - New TSP solving algorithms: [Christofides](http://en.wikipedia.org/wiki/Christofides_algorithm), diff --git a/composer.json b/composer.json index a6fd3cd..b1bfeaa 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,8 @@ { "name" : "letournel/path-finder", "description" : "Path finder algorithm", + "keywords": ["graph algorithms", "shortest path", "travelling salesman", "astar", "dijkstra", "floydwarshall", "nearest neighbour", "2opt", "3opt"], + "license": "MIT", "authors" : [{ "name" : "Adrien Letournel", "email" : "4dr13n.l370urn3l@gmail.com" diff --git a/src/Algorithms/ShortestDistance/FloydWarshall.php b/src/Algorithms/ShortestDistance/FloydWarshall.php index c6e1f10..6831892 100644 --- a/src/Algorithms/ShortestDistance/FloydWarshall.php +++ b/src/Algorithms/ShortestDistance/FloydWarshall.php @@ -28,7 +28,7 @@ public function __construct(Distance $distance) public function setGrid(NodeGrid $grid) { $this->grid = $grid; - $this->distanceGraph = new NodeGraph($grid->buildWalkableNodesList(), false); + $this->distanceGraph = new NodeGraph($grid->buildWalkableNodesList()); } public function computeLength(Node $source, Node $target) diff --git a/src/Algorithms/TravelingSalesman/Christofides.php b/src/Algorithms/TravelingSalesman/Christofides.php index 7ddde74..b1a5531 100644 --- a/src/Algorithms/TravelingSalesman/Christofides.php +++ b/src/Algorithms/TravelingSalesman/Christofides.php @@ -22,5 +22,6 @@ public function setGraph(NodeGraph $graph) public function computeRoute() { + throw new \RuntimeException('Not implemented'); } } diff --git a/src/Algorithms/TravelingSalesman/LinKernighan.php b/src/Algorithms/TravelingSalesman/LinKernighan.php index 0311f40..0463268 100644 --- a/src/Algorithms/TravelingSalesman/LinKernighan.php +++ b/src/Algorithms/TravelingSalesman/LinKernighan.php @@ -22,5 +22,6 @@ public function setGraph(NodeGraph $graph) public function computeRoute() { + throw new \RuntimeException('Not implemented'); } } diff --git a/src/Algorithms/TravelingSalesman/kOpt.php b/src/Algorithms/TravelingSalesman/kOpt.php index c217e5d..ea693fe 100644 --- a/src/Algorithms/TravelingSalesman/kOpt.php +++ b/src/Algorithms/TravelingSalesman/kOpt.php @@ -4,6 +4,7 @@ use Letournel\PathFinder\AlgorithmTravelingSalesman; use Letournel\PathFinder\Core\NodeGraph; +use Letournel\PathFinder\Core\NodePath; class kOpt implements AlgorithmTravelingSalesman { @@ -28,15 +29,6 @@ public function setGraph(NodeGraph $graph) public function computeRoute() { - if(! $this->graph instanceof NodeGraph) - { - throw new \RuntimeException('Invalid Graph'); - } - if(! $this->existingRoute instanceof NodePath) - { - throw new \RuntimeException('Invalid ExistingRoute'); - } - - return $this->existingRoute; + throw new \RuntimeException('Not implemented'); } } diff --git a/tests/Converters/Grid/ASCIISyntaxTest.php b/tests/Converters/Grid/ASCIISyntaxTest.php index b1a9158..210a303 100644 --- a/tests/Converters/Grid/ASCIISyntaxTest.php +++ b/tests/Converters/Grid/ASCIISyntaxTest.php @@ -2,7 +2,9 @@ namespace Letournel\PathFinder\Tests\Converters\Grid; +use Letournel\PathFinder\Core\Node; use Letournel\PathFinder\Core\NodeGrid; +use Letournel\PathFinder\Core\NodePath; use Letournel\PathFinder\Converters\Grid\ASCIISyntax; class ASCIISyntaxTest extends \PHPUnit_Framework_TestCase @@ -28,23 +30,38 @@ public function testConvertToSyntax($expectedSyntax, NodeGrid $grid) { $converter = new ASCIISyntax(); $syntax = $converter->convertToSyntax($grid); + $expectedSyntax = $this->removePath($expectedSyntax); $this->assertSame( $expectedSyntax, $syntax ); } - + + /** + * @dataProvider providerExemples + */ + public function testConvertToSyntaxWithPath($expectedSyntax, NodeGrid $grid, NodePath $path) + { + $converter = new ASCIISyntax(); + $syntax = $converter->convertToSyntaxWithPath($grid, $path); + + $this->assertSame( + $expectedSyntax, + $syntax + ); + } + public function providerExemples() { $tests = array(); $tests['simple 1'] = array( - ' ' . "\n" . - ' X X ' . "\n" . - ' XXXX ' . "\n" . - ' XXXXXXXX ' . "\n" . - ' ' . "\n" , + ' . ' . "\n" . + ' X >X. ' . "\n" . + ' XXXX . ' . "\n" . + ' XXXXXXXX. ' . "\n" . + ' <. ' . "\n" , new NodeGrid( array( array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), @@ -53,15 +70,26 @@ public function providerExemples() array(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1), array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ) + ), + new NodePath( + array( + new Node(1, 8), + new Node(0, 9), + new Node(1, 10), + new Node(2, 11), + new Node(3, 12), + new Node(4, 11), + new Node(4, 10), + ) ) ); $tests['simple 2'] = array( 'XXXXXXXX ' . "\n" . - 'X ' . "\n" . - 'X ' . "\n" . - 'X ' . "\n" . - ' ' . "\n" , + 'X ...> ' . "\n" . + 'X . ' . "\n" . + 'X. ' . "\n" . + '< ' . "\n" , new NodeGrid( array( array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1), @@ -70,9 +98,29 @@ public function providerExemples() array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ) + ), + new NodePath( + array( + new Node(1, 6), + new Node(1, 5), + new Node(1, 4), + new Node(1, 3), + new Node(2, 2), + new Node(3, 1), + new Node(4, 0), + ) ) ); - + return $tests; } + + private function removePath($syntax) + { + return str_replace( + array(ASCIISyntax::IN, ASCIISyntax::STEP, ASCIISyntax::OUT), + ' ', + $syntax + ); + } }