Skip to content

Commit

Permalink
Merge pull request #2 from letournel/add-php-7-support
Browse files Browse the repository at this point in the history
fix: minor fixes, tu and php 7.0 support
  • Loading branch information
letournel authored Jul 23, 2017
2 parents afb840a + d57d364 commit 9397f88
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

before_script:
- composer install --dev

script:
- phpunit
- phpunit
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithms/ShortestDistance/FloydWarshall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Algorithms/TravelingSalesman/Christofides.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public function setGraph(NodeGraph $graph)

public function computeRoute()
{
throw new \RuntimeException('Not implemented');
}
}
1 change: 1 addition & 0 deletions src/Algorithms/TravelingSalesman/LinKernighan.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public function setGraph(NodeGraph $graph)

public function computeRoute()
{
throw new \RuntimeException('Not implemented');
}
}
12 changes: 2 additions & 10 deletions src/Algorithms/TravelingSalesman/kOpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Letournel\PathFinder\AlgorithmTravelingSalesman;
use Letournel\PathFinder\Core\NodeGraph;
use Letournel\PathFinder\Core\NodePath;

class kOpt implements AlgorithmTravelingSalesman
{
Expand All @@ -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');
}
}
70 changes: 59 additions & 11 deletions tests/Converters/Grid/ASCIISyntaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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
);
}
}

0 comments on commit 9397f88

Please sign in to comment.