Changes between Version 10 and Version 11 of Parcours source RHT


Ignore:
Timestamp:
Oct 26, 2011 10:55:02 PM (14 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Parcours source RHT

    v10 v11  
    2020-- La distance source est la distance mer maximale de tous les chemins possibles en ne prenant que le dernier tronçon du chemin. 
    2121Select max(dmer) from rht.rht_topology where id_drain in ( 
    22 Select cast(ltree2text(subpath(chemin, -1, 1))as integer) as chenin_id_drain from rht.rht_topology where chemin <@ '212340'); 
     22Select cast(ltree2text(subpath(chemin, -1, 1))as integer) as chenin_id_drain from rht.rht_topology where chemin ~ '*.212340.*'); 
     23--  travail sur les noeuds source et le recalcul des distances mer et source (voir fichier doc joint) 
     24-- en pratique les distances sont calculées a partir du milieu de chaque tronçon, elles prennent par contre toute la distance des tronçons autre que le tronçon considéré. 
    2325 
    24 --  fonction pour renvoyer les distances source 
     26alter table rht.rht_topology add column noeudsource boolean default FALSE; 
     27-- identification des noeuds source 
     28update rht.rht_topology set noeudsource=TRUE where id_drain in ( 
     29select id_drain from rht.rht_topology except ( 
     30select rt2.id_drain from rht.rht_topology rt1 join rht.rht_topology rt2 on rt1.nextdownid=rt2.id_drain) 
     31);-- 57533 
     32update rht.rht_topology set dmer=dmer+length/2;-- 114600 
     33alter table rht.rht_topology add column dsource numeric; 
     34update rht.rht_topology set dsource=length/2 where noeudsource;-- 57533 
     35-- voir schéma pour explications 
     36 
     37 
    2538DROP FUNCTION IF EXISTS rht.distance_source(); 
    26 CREATE OR REPLACE FUNCTION rht.distance_source() RETURNS integer AS $$ 
     39 
     40CREATE OR REPLACE FUNCTION rht.distance_source(min integer, max integer) RETURNS integer AS $$ 
    2741DECLARE 
    28     id_drains RECORD; 
    29     nbligne integer; 
     42    ligne integer; 
     43    nbligne integer;  
     44    id_drains record; 
    3045BEGIN 
    31           nbligne:=1; 
    32           DROP TABLE IF EXISTS rht.distance_mer; 
    33           CREATE TABLE rht.distance_mer (id_drain integer,distance_mer  numeric); 
    34           FOR id_drains IN SELECT id_drain FROM rht.rht_topology ORDER BY id_drain LOOP 
    35                   -- pour vérification décommenter ensuite 
    36                   RAISE NOTICE 'distance_source for %', quote_ident(CAST(id_drains.id_drain as text)); 
    37                   EXECUTE 'INSERT INTO rht.distance_mer SELECT MAX(dmer) FROM rht.rht_topology WHERE id_drain IN ( 
    38                         SELECT CAST(ltree2text(subpath(chemin, -1, 1))as integer) FROM rht.rht_topology where chemin <@  text2ltree(cast ('|| 
    39                         id_drains.id_drain 
    40                         || 'as text)) )';   
    41                 nbligne=nbligne+1;       
    42         END LOOP; 
    43     RETURN nbligne; 
     46        ligne:=1; 
     47        DROP TABLE IF EXISTS sousselection; 
     48        DROP sequence IF EXISTS  seq; 
     49        CREATE sequence seq; 
     50        EXECUTE 'create temporary table sousselection as SELECT id_drain, nextval(''seq'') as num FROM (SELECT * FROM rht.rht_topology WHERE noeudsource=FALSE ORDER BY id_drain) as sub WHERE id_drain >='|| min || ' AND id_drain<='||max ; 
     51        SELECT COUNT(*) FROM sousselection INTO nbligne; 
     52        WHILE ligne <=nbligne LOOP 
     53                  -- pour vérification décommenter ensuite 
     54                  SELECT * from sousselection where num=ligne INTO id_drains; 
     55                  RAISE NOTICE 'distance_source for %', quote_ident(CAST(id_drains.id_drain as text)); 
     56                  EXECUTE 'INSERT INTO rht.distance_source SELECT '||id_drains.id_drain||', MAX(dmer+length/2) as dmer FROM rht.rht_topology WHERE id_drain IN ( 
     57                        SELECT CAST(ltree2text(subpath(chemin, -1, 1))as integer) FROM rht.rht_topology where chemin ~  ''*.'|| 
     58                        id_drains.id_drain 
     59                        || '.*'' )';   
     60                ligne=ligne+1;       
     61        END LOOP; 
     62    RETURN ligne; 
    4463END; 
    4564$$ LANGUAGE plpgsql; 
     65-- lancement de la requête 
     66DROP TABLE IF EXISTS rht.distance_source; 
     67CREATE TABLE rht.distance_source (id_drain integer,distance  numeric); 
     68select rht.distance_source(1,50000); 
    4669 
    47 select rht.distance_source(); 
     70-- pour essai pour voir ce qui se passe dans la requête 
     71 
     72SELECT 212340,  MAX(dmer+length/2) as dmer FROM rht.rht_topology WHERE id_drain IN ( 
     73                        SELECT CAST(ltree2text(subpath(chemin, -1, 1))as integer) FROM rht.rht_topology where chemin ~  '*.212340.*' ) 
     74-- il faudra enlever la dmer de 212340 
     75 
     76-- requête finale pour calculer les distances source (à lancer) 
     77alter table rht.distance_source d add column distance source numeric; 
     78update rht.distance_source set distance source = sub.distance_source from ( 
     79select id_drain, distance-dmer as distance_source from rht.distance_source s joint rht.rht_topology t on s.id_drain=t.id_drain) as source 
     80where sub.id_drain=d.id_drain; 
    4881}}} 
    4982== utilisation des donnees de parcours == 
     
    5184Ci dessous la fonction utilise les expressions régulières ltree => vecteur => table 
    5285{{{ 
    53  
     86#!sql 
    5487/* 
    5588regexp_split_to_array(string text, pattern text [, flags text ])        regexp_split_to_array('hello world', E'\\s+')   {hello,world}