Skip to content

Commit 8177c5c

Browse files
committed
2016/03/03 do dijkstra
1 parent 409124c commit 8177c5c

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Graphic/.Edge.php.swp

-12 KB
Binary file not shown.

Graphic/.GraALG.php.swo

-12 KB
Binary file not shown.

Graphic/.GraALG.php.swp

-12 KB
Binary file not shown.

Graphic/GraALG.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
namespace Graphic;
44

55
class GraALG {
6+
67
const INFINITY = 65535;
78
const CONNECT = 1;
9+
810
public $verex;
911
public $edges;
12+
//邻接表
1013
public $graphic;
14+
1115
//dijkstr用来记录最短路径和前置节点
1216
public $dijkstra;
17+
//邻接矩阵表示
1318
public $adjMatrix;
19+
1420
public function __construct($verex, $edges, $graphic) {
1521
$this->verex = $verex;
1622
$this->edges = $edges;
@@ -78,8 +84,22 @@ public function toAdjMatrix() {
7884
$this->adjMatrix [] = $arr;
7985
}
8086
}
81-
//最短路径的问题
87+
88+
//最短路径的问题,$dijkstra,邻接矩阵表示$adjMatrix;
8289
public function shortestPathDijkstrai() {
83-
90+
$pre = 0;
91+
$shortest = 1;
92+
$this->dijkstra = array();
93+
//第一个数值表示本节点的前置节点为0,
94+
//第二个数值表示本节点到源点的最短距离
95+
$row = array(0, 0);
96+
$this->dijkstra [0] = $row;
97+
$this->verex[0]->visited = 1;
98+
99+
foreach ($this->verex as $vex) {
100+
if ($vex->visited == 0) {
101+
102+
}
103+
}
84104
}
85105
}

0 commit comments

Comments
 (0)