CREATE OR REPLACE PACKAGE shortest_path_pkg
成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括浉河網(wǎng)站建設(shè)、浉河網(wǎng)站制作、浉河網(wǎng)頁(yè)制作以及浉河網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,浉河網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到?jīng)负邮》莸牟糠殖鞘?,未?lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
AS
TYPE node_dist_rt IS RECORD(fpoint INT, dvalue INT);
TYPE node_dist_tt IS TABLE OF node_dist_rt INDEX BY PLS_INTEGER;
TYPE graph_node_rt IS RECORD(NAME VARCHAR2(100), isvisited BOOLEAN);
TYPE graph_node_tt IS TABLE OF graph_node_rt INDEX BY PLS_INTEGER;
TYPE graph_dist_tt IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
TYPE graph_dist_nt IS TABLE OF graph_dist_tt INDEX BY PLS_INTEGER;
PROCEDURE add_node(graph_nodes IN OUT graph_node_tt,NAME VARCHAR2);
FUNCTION get_minnode(graph_nodes IN graph_node_tt, graph_dists IN graph_dist_nt, dnode INT) RETURN PLS_INTEGER;
PROCEDURE add_node_dist(graph_dist_inst IN OUT graph_dist_nt, snode INT, enode INT, dvalue INT);
PROCEDURE cals_min_gdist(graph_nodes IN OUT graph_node_tt, graph_dist_inst IN graph_dist_nt, snode IN OUT INT);
PROCEDURE INIT_dist_inst(graph_dist IN OUT graph_dist_nt, nodes_cnt INT);
END;
CREATE OR REPLACE PACKAGE BODY shortest_path_pkg
AS
PROCEDURE add_node(graph_nodes IN OUT graph_node_tt, NAME VARCHAR2)
AS
tmp_node graph_node_rt;
BEGIN
tmp_node.name := NAME;
tmp_node.isvisited := FALSE;
graph_nodes(graph_nodes.count + 1) := tmp_node;
END add_node;
FUNCTION get_minnode(graph_nodes IN graph_node_tt, graph_dists IN graph_dist_nt, dnode INT) RETURN PLS_INTEGER
AS
dest_node PLS_INTEGER := -1;
minval PLS_INTEGER := 999999999;
BEGIN
FOR tlvl IN 1..graph_dists(dnode).count LOOP
IF NOT graph_nodes(tlvl).isvisited AND graph_dists(dnode)(tlvl) < minval THEN
minval := graph_dists(dnode)(tlvl);
dest_node := tlvl;
END IF;
END LOOP;
RETURN dest_node;
END get_minnode;
PROCEDURE add_node_dist(graph_dist_inst IN OUT graph_dist_nt, snode INT, enode INT, dvalue INT)
AS
BEGIN
graph_dist_inst(snode)(enode) := dvalue;
graph_dist_inst(enode)(snode) := dvalue;
END add_node_dist;
PROCEDURE INIT_dist_inst(graph_dist IN OUT graph_dist_nt, nodes_cnt INT)
AS
BEGIN
FOR i IN 1..nodes_cnt LOOP
FOR j IN 1..nodes_cnt LOOP
graph_dist(i)(j) := 999999999;
END LOOP;
END LOOP;
END init_dist_inst;
PROCEDURE cals_min_gdist(graph_nodes IN OUT graph_node_tt, graph_dist_inst IN graph_dist_nt, snode IN OUT INT)
AS
tmp_cnt INT := 0;
dest_node INT;
node_dist_nt node_dist_tt;
node_dist_rec node_dist_rt;
tmp_dist INT;
BEGIN
FOR i IN 1..graph_nodes.count LOOP
node_dist_rec.fpoint := snode;
node_dist_rec.dvalue := graph_dist_inst(snode)(i);
node_dist_nt(i) := node_dist_rec;
END LOOP;
WHILE (tmp_cnt < graph_nodes.count) LOOP
dest_node := get_minnode(graph_nodes,graph_dist_inst, snode);
IF(dest_node = -1) THEN
raise_application_error(-20001, 'there exists a gap');
END IF;
graph_nodes(dest_node).isvisited := TRUE;
tmp_dist := graph_dist_inst(snode)(dest_node);
FOR i IN 1..graph_nodes.count LOOP
IF(node_dist_nt(i).dvalue>(tmp_dist+graph_dist_inst(dest_node)(i))) THEN
node_dist_nt(i).dvalue := tmp_dist + graph_dist_inst(dest_node)(i);
node_dist_nt(i).fpoint := dest_node;
END IF;
END LOOP;
snode := dest_node;
tmp_cnt := tmp_cnt + 1;
END LOOP;
FOR i IN 1..node_dist_nt.count LOOP
dbms_output.put_line('節(jié)點(diǎn)'||graph_nodes(i).name||', 父節(jié)點(diǎn): '||node_dist_nt(i).fpoint||' 距離:'||node_dist_nt(i).dvalue);
END LOOP;
END cals_min_gdist;
END;
當(dāng)前標(biāo)題:oracleshortest_path
分享鏈接:http://m.rwnh.cn/article0/igpcoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、靜態(tài)網(wǎng)站、定制開(kāi)發(fā)、小程序開(kāi)發(fā)、面包屑導(dǎo)航、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)