资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

oracleshortest_path-创新互联

CREATE OR REPLACE PACKAGE shortest_path_pkg

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、虚拟空间、营销软件、网站建设、崇明网站维护、网站推广。

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('节点'||graph_nodes(i).name||',  父节点:  '||node_dist_nt(i).fpoint||' 距离:'||node_dist_nt(i).dvalue);

  END LOOP;

 END cals_min_gdist;

END;

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前题目:oracleshortest_path-创新互联
网站URL:http://cdkjz.cn/article/ddggdd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220