甲骨文shortest_path

创建或替换包shortest_path_pkg

,类型node_dist_rt记录(dvalue fpoint INT, INT);

,类型node_dist_tt PLS_INTEGER node_dist_rt索引表;

,类型graph_node_rt记录(名字VARCHAR2 (100), isvisited布尔),

,类型graph_node_tt PLS_INTEGER graph_node_rt索引表;

,类型graph_dist_tt PLS_INTEGER PLS_INTEGER索引表;

,类型graph_dist_nt PLS_INTEGER graph_dist_tt索引表;

,过程add_node (graph_nodes graph_node_tt,名字VARCHAR2);

,函数,get_minnode (graph_nodes graph_node_tt, graph_dists graph_dist_nt, dnode INT返回PLS_INTEGER;

,过程add_node_dist (graph_dist_inst graph_dist_nt,综述INT, INT enode, dvalue INT);

,过程cals_min_gdist (graph_nodes graph_node_tt, graph_dist_inst graph_dist_nt,综述在INT);

,过程INIT_dist_inst (graph_dist graph_dist_nt, nodes_cnt INT);

,


创建或替换包身体shortest_path_pkg

,过程add_node (graph_nodes graph_node_tt,名字VARCHAR2)

,和

,,tmp_node graph_node_rt;

,

开始,,,tmp_node.name:=名字;

,,tmp_node。isvisited:=FALSE;

,,graph_nodes (graph_nodes。数+ 1):=tmp_node;

,结束add_node;


,函数get_minnode (graph_nodes graph_node_tt, graph_dists graph_dist_nt, dnode INT返回PLS_INTEGER

,和

,,,dest_node PLS_INTEGER:=1;

,,minval大敌;,PLS_INTEGER:=999999999;

,

开始,,,在1 . . tlvl graph_dists (dnode)。计数循环

,,,,如果不是graph_nodes (tlvl)。isvisited和graph_dists (dnode) (tlvl) & lt;minval然后

,,,,,,minval:=graph_dists (dnode) (tlvl);

,,,,,,dest_node:=tlvl;

,,,,如果结束,

,,,结束循环;

,,,返回dest_node;

,结束get_minnode;



,过程add_node_dist (graph_dist_inst在graph_dist_nt,综述INT, INT enode, dvalue INT)

,和

,

开始,,graph_dist_inst(综述)(enode):=dvalue;

,,graph_dist_inst (enode)(综述):=dvalue;

,结束add_node_dist;


,过程INIT_dist_inst (graph_dist在graph_dist_nt, nodes_cnt INT)

,和

,

开始,,因为我在1 . .nodes_cnt循环

,,,j在1 . .nodes_cnt循环

,,,,graph_dist (i) (j):=999999999;

,,,结束循环;

,,结束循环;

,结束init_dist_inst;

,

,过程cals_min_gdist (graph_nodes在graph_node_tt, graph_dist_inst graph_dist_nt,综述在INT)

,如

,,tmp_cnt INT:=0;

,,dest_node INT;

,,node_dist_nt node_dist_tt;

,,node_dist_rec node_dist_rt;

,,tmp_dist INT;

,

开始,1 . . graph_nodes的我。计数循环

,,,node_dist_rec。fpoint:=综述;

,,,node_dist_rec。dvalue:=graph_dist_inst(综述)(i);

,,,,node_dist_nt(我):=node_dist_rec;

,,结束循环;


,,而(tmp_cnt & lt;graph_nodes.count)循环

,,,,dest_node:=get_minnode (graph_nodes graph_dist_inst,综述);

,,,,如果(dest_node=1),那么

,,,,,,raise_application_error(-20001年,“存在一个差距”);

,,,,如果结束,

,,,,graph_nodes (dest_node)。isvisited:=TRUE;

,,,,tmp_dist:=graph_dist_inst(综述)(dest_node);

,,,,1 . . graph_nodes的我。计数循环

,,,,,如果(node_dist_nt .dvalue> (tmp_dist + graph_dist_inst (dest_node) (i)))然后

,,,,,,,node_dist_nt(我)。dvalue:=tmp_dist + graph_dist_inst (dest_node) (i);

,,,,,,,node_dist_nt(我)。fpoint:=dest_node;

,,,,,如果结束,

,,,,结束循环;

,,,,综述:=dest_node;

,,,,tmp_cnt:=tmp_cnt + 1,

,,结束循环;


,1 . . node_dist_nt的我。计数循环

,,null

甲骨文shortest_path