fork download
  1. <?php
  2.  
  3. /* http://d...content-available-to-author-only...2.net/ */
  4.  
  5. define('SUBWAY', 'sub');
  6. define('FOOT', 'foot');
  7. define('BUS', 'bus');
  8.  
  9. $transportName = array(
  10. SUBWAY => 'едешь на метро',
  11. FOOT => 'идешь пешком',
  12. BUS => 'едешь на автобусе'
  13. );
  14.  
  15. $startPoint = 'pet'; // Петроградская
  16. $endPoint = 'nov'; // Новая Голландия
  17.  
  18. $pointNames = array(
  19. 'pet' => 'ст. м. Петроградская',
  20. 'chk' => 'ст. м. Чкаловская',
  21. 'gor' => 'ст. м. Горьковская',
  22. 'spo' => 'ст. м. Спортивная',
  23. 'vas' => 'ст. м. Василеостровская',
  24. 'kre' => 'Петропавловская крепость',
  25. 'let' => 'Летний сад',
  26. 'dvo' => 'Дворцовая площадь',
  27. 'isa' => 'Исакиевский собор',
  28. 'nov' => 'Новая Голландия',
  29. 'ras' => 'Дом Раскольникова',
  30. 'gos' => 'Гостиный Двор',
  31. 'sen' => 'Сенная Площадь',
  32. 'vla' => 'ст. м. Владимирская',
  33. 'vit' => 'Витебский вокзал',
  34. 'teh' => 'Технологический Институт'
  35. );
  36.  
  37. $paths = array(
  38. 'pet' => array(
  39. 'chk' => canGet(10, BUS),
  40. 'gor' => canGet(3, SUBWAY)
  41. ),
  42.  
  43. 'chk' => array(
  44. 'pet' => canGet(10, BUS),
  45. 'spo' => canGet(3, SUBWAY)
  46. ),
  47.  
  48. 'gor' => array(
  49. 'pet' => canGet(3, BUS),
  50. 'kre' => canGet(5, FOOT),
  51. 'gos' => canGet(6, SUBWAY)
  52. ),
  53.  
  54. 'spo' => array(
  55. 'chk' => canGet(3, SUBWAY),
  56. 'vas' => canGet(10, BUS),
  57. 'sen' => canGet(7, SUBWAY)
  58. ),
  59.  
  60. 'vas' => array(
  61. 'spo' => canGet(10, BUS),
  62. 'gos' => canGet(7, SUBWAY),
  63. 'nov' => canGet(11, FOOT)
  64. ),
  65.  
  66. 'kre' => array(
  67. 'gor' => canGet(5, FOOT)
  68. ),
  69.  
  70. 'let' => array(
  71. 'dvo' => canGet(6, FOOT),
  72. 'gos' => canGet(7, FOOT)
  73. ),
  74.  
  75. 'dvo' => array(
  76. 'isa' => canGet(6, FOOT),
  77. 'gos' => canGet(6, FOOT),
  78. 'let' => canGet(6, FOOT)
  79. ),
  80.  
  81. 'isa' => array(
  82. 'dvo' => canGet(6, FOOT),
  83. 'nov' => canGet(5, FOOT)
  84. ),
  85.  
  86. 'nov' => array(
  87. 'vas' => canGet(11, FOOT),
  88. 'isa' => canGet(5, FOOT),
  89. 'ras' => canGet(7, BUS)
  90. ),
  91.  
  92. 'ras' => array(
  93. 'nov' => canGet(7, BUS),
  94. 'sen' => canGet(3, FOOT)
  95. ),
  96.  
  97. 'gos' => array(
  98. 'vas' => canGet(7, SUBWAY),
  99. 'sen' => canGet(3, SUBWAY),
  100. 'dvo' => canGet(6, FOOT),
  101. 'gor' => canGet(6, SUBWAY),
  102. 'let' => canGet(7, FOOT),
  103. 'vla' => canGet(7, FOOT)
  104. ),
  105.  
  106. 'sen' => array(
  107. 'ras' => canGet(3, FOOT),
  108. 'spo' => canGet(7, SUBWAY),
  109. 'gos' => canGet(3, SUBWAY),
  110. 'vla' => canGet(4, SUBWAY),
  111. 'vit' => canGet(2, SUBWAY),
  112. 'teh' => canGet(3, SUBWAY)
  113. ),
  114.  
  115. 'vla' => array(
  116. 'sen' => canGet(4, SUBWAY),
  117. 'gos' => canGet(7, FOOT),
  118. 'vit' => canGet(3, SUBWAY)
  119. ),
  120.  
  121. 'vit' => array(
  122. 'sen' => canGet(2, SUBWAY),
  123. 'teh' => canGet(2, SUBWAY),
  124. 'vla' => canGet(3, SUBWAY)
  125. ),
  126.  
  127. 'teh' => array(
  128. 'sen' => canGet(3, SUBWAY),
  129. 'vit' => canGet(2, SUBWAY)
  130. )
  131. );
  132.  
  133. /* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
  134.   «canGet» переводится как «можно попасть» */
  135. function canGet($time, $byWhat) {
  136. return array('time' => $time, 'by' => $byWhat);
  137. }
  138.  
  139. function oneStep($paths, $pathDone, $time, $point, $target){
  140. $result=array();
  141.  
  142. if(!$paths[$point][$target]){
  143. foreach($paths[$point] as $key=>$val){
  144. if (in_array($key, $pathDone)){
  145. continue;
  146. }
  147.  
  148. $pathDone[]=$key;
  149. $time=$time+$paths[$point][$key]['time'];
  150. $container=oneStep($paths, $pathDone, $time, $key, $target);
  151.  
  152. if($time>$container['time']){
  153. continue;
  154. }
  155.  
  156.  
  157.  
  158. }
  159.  
  160. unset($paths[$point]);
  161.  
  162.  
  163.  
  164. }
  165.  
  166. else{
  167.  
  168.  
  169. $result['path'] = $pathDone;
  170. $result['time'] = $paths[$point][$target]['time']+$time;
  171. $pathDone=array();
  172. $time=0;
  173. return $result;
  174.  
  175. }
  176. if(!$paths){
  177. return $container;
  178. }
  179. }
  180. $testar=array();
  181. $testvar=oneStep($paths, $testar, 0, 'vas' , 'teh');
  182. var_dump($testvar);
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
NULL
stderr
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143
PHP Notice:  Undefined index: teh in /home/gWBmFA/prog.php on line 143