-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolving_network_navigation_best_first.php
More file actions
63 lines (55 loc) · 1.66 KB
/
Solving_network_navigation_best_first.php
File metadata and controls
63 lines (55 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php declare(strict_types=1);
namespace Stratadox\PuzzleSolver\Test;
use PHPUnit\Framework\TestCase;
use Stratadox\PuzzleSolver\Find;
use Stratadox\PuzzleSolver\Puzzle\NetworkNavigation\NetworkPuzzleFactory;
use Stratadox\PuzzleSolver\PuzzleCreationFailure;
use Stratadox\PuzzleSolver\UniversalSolver;
/**
* @testdox Solving network navigation, best first
*/
class Solving_network_navigation_best_first extends TestCase
{
/** @test */
function finding_the_shortest_path_in_the_example_graph()
{
$solver = UniversalSolver::aimingTo(Find::aBestSolution())
->withWeightedMoves()
->select();
$puzzle = NetworkPuzzleFactory::make()->fromString('
{
"edges": [
{
"from": "A",
"to": "B",
"cost": 1.4
},
{
"from": "B",
"to": "C",
"cost": 1.34
},
{
"from": "A",
"to": "C",
"cost": 2.76
}
],
"start": "A",
"goal": "C"
}
');
$solution = $solver->solve($puzzle)[0];
self::assertEquals(2.74, $solution->cost());
self::assertCount(2, $solution->moves());
self::assertEquals('Go to B', $solution->moves()[0]);
self::assertEquals('Go to C', $solution->moves()[1]);
}
/** @test */
function not_loading_invalid_json_input()
{
$factory = NetworkPuzzleFactory::make();
$this->expectException(PuzzleCreationFailure::class);
$factory->fromString('{ "edges": [{');
}
}