1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GGGGino\WarehousePath\Tools\Console\Command; |
4
|
|
|
|
5
|
|
|
use GGGGino\WarehousePath\Calculator\FastCalculator; |
6
|
|
|
use GGGGino\WarehousePath\Entity\Place; |
7
|
|
|
use GGGGino\WarehousePath\Warehouse; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Helper\Table; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
class MultiplePathGraphicalTestCommand extends Command |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
$this |
21
|
|
|
->setName('ggggino:warehouse:mpg-print-matrix') |
22
|
|
|
->setDescription('Print a beautiful matrix with the lenght of every path') |
23
|
|
|
->setHelp(<<<EOT |
24
|
|
|
Print a beautiful matrix. |
25
|
|
|
EOT |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
/** @var Warehouse $warehouse */ |
35
|
|
|
$warehouse = Warehouse::createFromJson(getcwd() . "/../resources/biggerWarehouse.json"); |
36
|
|
|
$calculatedArray = $warehouse->getPlacesCollector()->getPlaces(); |
37
|
|
|
|
38
|
|
|
$warehouse->setPathCalculator(new FastCalculator()); |
39
|
|
|
|
40
|
|
|
/** @var Place[] $arrayNodes */ |
41
|
|
|
$arrayNodes = $this->chooseSearchablePlaces($calculatedArray); |
42
|
|
|
|
43
|
|
|
$matrix = $warehouse->getMultiplePath($arrayNodes); |
44
|
|
|
|
45
|
|
|
$this->printTable($output, $arrayNodes, $matrix); |
46
|
|
|
|
47
|
|
|
$warehouse->calculate($arrayNodes, $matrix); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Output the table for debug purpose |
52
|
|
|
* |
53
|
|
|
* @param OutputInterface $output |
54
|
|
|
* @param array $arrayNodes |
55
|
|
|
* @param array $matrix |
56
|
|
|
*/ |
57
|
|
|
private function printTable(OutputInterface $output, array $arrayNodes, array $matrix) |
58
|
|
|
{ |
59
|
|
|
$table = new Table($output); |
60
|
|
|
$table |
61
|
|
|
->setHeaders($arrayNodes) |
62
|
|
|
->setRows($matrix) |
63
|
|
|
; |
64
|
|
|
$table->render(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Select the Places for find the path |
69
|
|
|
* |
70
|
|
|
* @param Place[] $calculatedArray |
71
|
|
|
* @return Place[] |
72
|
|
|
*/ |
73
|
|
|
private function chooseSearchablePlaces($calculatedArray) |
74
|
|
|
{ |
75
|
|
|
return array( |
76
|
|
|
$calculatedArray[103], |
77
|
|
|
$calculatedArray[30], |
78
|
|
|
$calculatedArray[23], |
79
|
|
|
$calculatedArray[57], |
80
|
|
|
$calculatedArray[135], |
81
|
|
|
$calculatedArray[120], |
82
|
|
|
$calculatedArray[115], |
83
|
|
|
$calculatedArray[79], |
84
|
|
|
$calculatedArray[601], |
85
|
|
|
$calculatedArray[650] |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|