Graphes
Graphes
begin
s := s.alt ;
end loop ;
exit when estvide ( f ) ;
del_min ( ax, x, f ) ;
end loop ;
x := z ;
loop
exit when x = a ;
da_x := adr ( x, da ) ;
--ins1 ( ( da_x.attr.dist, da_x.attr.prec ), y ) ;
ins1 ( da_x.attr.prec, y ) ;
x := da_x.attr.prec ;
end loop ;
end if ;
return y ;
end pcm ;
--------------------------------------------------------------
--------------------------------------------------------------
--type id_id is record
-- id1, id2 : item_id ; end record ;
procedure put ( x : id_id ) is begin
put ( x.id1 ) ; text_io.put ( "--" ) ;
put ( x.id2 ) ; end put ;
-----------------------------------------------------------------------------
procedure read ( fs : access Ada.Streams.Root_Stream_Type'Class ; x : out
id_id ) is begin
id_id'read ( fs, x ) ; end read ;
-----------------------------------------------------------------------------
procedure write ( fs : access Ada.Streams.Root_Stream_Type'Class ; x : id_id )
is begin
id_id'write ( fs, x ) ; end write ;
-----------------------------------------------------------------------------
function "<" ( x1 : id_id ; x2 : id_id ) return boolean is begin
if x1.id1 < x2.id1 then
return true ;
elsif x1.id1 = x2.id1 then
if x1.id2 < x2.id2 then
return true ;
elsif x1.id2 = x2.id2 then
return false ;
else
return false ;
end if ;
else
return false ;
end if ;
end "<" ;
-----------------------------------------------------------------------------
function "=" ( x1 : id_id ; x2 : id_id ) return boolean is begin
return x1.id1 = x2.id1 and x1.id2 = x2.id2 ; end "=" ;
-----------------------------------------------------------------------------
function ">=" ( x1 : id_id ; x2 : id_id ) return boolean is begin
return not ( x1 < x2 ) ; end ">=" ;
-----------------------------------------------------------------------------
function ">" ( x1 : id_id ; x2 : id_id ) return boolean is begin
if x1.id1 < x2.id1 then
return false ;
elsif x1.id1 = x2.id1 then
if x1.id2 < x2.id2 then
return false ;
elsif x1.id2 = x2.id2 then
return false ;
else
return true ;
end if ;
else
return true ;
end if ; end ">" ;
-----------------------------------------------------------------------------
function "<=" ( x1 : id_id ; x2 : id_id ) return boolean is begin
return not ( x1 > x2 ) ; end "<=" ;
--package id_id_caps is new tables ( id_id, item_arc ) ;
use id_id_caps ;
----------------------------------------------------------------
package arc2s is new
temp_liste_triees ( item_arc, entier ) ; use arc2s ;
type noeud_cell2 is record
cap_noeud : item_arc ;
recu : item_arc ;
flux_noeud : item_arc ;
suiv_trie : arc2s.table ;
prec_trie : arc2s.table ; end record ;
--procedure put ( x : noeud_cell2 ) is
--begin
-- text_io.put ( "cap : " ) ; put ( x.cap_noeud ) ; text_io.put ( ", " ) ;
-- text_io.put ( "re�u : " ) ; put ( x.recu ) ; text_io.put ( ", " ) ;
-- text_io.put ( "flux : " ) ; put ( x.flux_noeud ) ; text_io.put ( ", " ) ;
--text_io.new_line ;
--text_io.put ( "suiv : " ) ; put ( x.suiv_trie ) ; text_io.new_line ;
--text_io.put ( "prec : " ) ; put ( x.prec_trie ) ;
--end put ;
-------------------------------------------------------------------
-------------------------------------------------------------------
function flot_max ( g : graphe ) return id_id_liste is
flux : id_id_liste ;
n : entier := card ( g ) ;
package noeud_cell2s is new
temp_tab_tries ( n, item_id, noeud_cell2 ) ;
use noeud_cell2s ;
h : noeud_cell2s.table ;
package cap_ids is new temp_liste_triees ( item_arc, entier );
use cap_ids ;
f : cap_ids.table ;
--------------------------------------------------------------
procedure init
( g : graphe ; h : in out noeud_cell2s.table ;
f : in out cap_ids.table ; flux : in out id_id_liste ) is
i : entier ;
procedure init1( g:graphe ; h:in out noeud_cell2s.table ) is
begin
if not estvide(g) then
init1 ( s1(g), h ) ;
i := i + 1 ;
h(i).cle := g.cle ;
h(i).attr.cap_noeud := zero ;
h(i).attr.recu := zero ;
h(i).attr.flux_noeud := zero ;
init ( h(i).attr.suiv_trie ) ;
init ( h(i).attr.prec_trie ) ;
init1 ( s2(g), h ) ;
end if ;
end init1 ;
--------------------------------------------------------------
procedure init2
( g : graphe ; h : in out noeud_cell2s.table ;
flux : in out id_id_liste) is
s : arcs.table ;
x, ns : entier ;
i_i : id_id ;
begin
if not estvide(g) then
init2 ( s1(g), h, flux ) ;
i := i + 1 ; x := adr ( g.cle, h ) ;
s := g.attr ; while not ( estvide ( s ) ) loop
ns := adr ( s.cle, h ) ;
ins ( -s.attr, x, h(ns).attr.prec_trie ) ;
ins ( s.attr, ns, h(x).attr.suiv_trie ) ;
i_i := ( g.cle, s.cle ) ;
ins ( i_i, zero, flux ) ;
s := s.alt ;
end loop ;
init2 ( s2(g), h, flux ) ;
end if ;
end init2 ;
-----------------------------------------------------------
procedure init_cap
( h : in out noeud_cell2s.table ;
f : out cap_ids.table ) is
s_s, s_p : item_arc ;
s : arc2s.table ;
begin
for x in 1..n loop
s_s := zero ;
s := h(x).attr.suiv_trie ;
while not ( estvide ( s ) ) loop
s_s := s_s + s.cle ;
s := s.alt ;
end loop ;
if estvide ( h(x).attr.suiv_trie ) then
s_s := infini ; end if ;
s_p := zero ;
s := h(x).attr.prec_trie ;
while not ( estvide ( s ) ) loop
s_p := s_p + abs ( s.cle ) ;
s := s.alt ;
end loop ;
if estvide ( h(x).attr.prec_trie ) then
h(x).attr.recu := s_s ;
h(x).attr.cap_noeud := s_s ;
ins ( s_s, x, f ) ;
else
h(x).attr.cap_noeud := min ( s_s, s_p ) ;
end if ;
end loop ;
end init_cap ;
begin
i := 0 ; init1 ( g, h ) ;
i := 0 ; init2 ( g, h, flux ) ;
init_cap ( h, f ) ;
end init ;
--------------------------------------------------------------
cx, m, anc : item_arc ;
x, ns : entier ;
x_ns, ns_x : id_id_liste ; s : arc2s.table ;
cont : string :="o" ;
i_i : id_id ;
begin
init ( flux ) ; init ( f ) ;
init ( g, h, f, flux ) ;
loop
exit when estvide ( f ) ;
del_min ( cx, x, f ) ; --h_x := adr ( x, h ) ;
s := h(x).attr.suiv_trie ;
while not ( estvide ( s ) ) loop
ns := s.attr ;
i_i := (h(x).cle,h(ns).cle) ;
x_ns := adr( i_i, flux) ;
m := min ( s.cle - x_ns.attr,
min ( h(ns).attr.cap_noeud -
h(ns).attr.flux_noeud,
h(x).attr.recu )) ;
if m > zero then
x_ns.attr := x_ns.attr + m ;
anc := h(ns).attr.flux_noeud ;
h(ns).attr.flux_noeud :=
h(ns).attr.flux_noeud + m ;
del ( anc, ns, f ) ;
ins ( h(ns).attr.flux_noeud, ns, f ) ;
h(ns).attr.recu := h(ns).attr.recu + m ;
h(x).attr.recu := h(x).attr.recu - m ;
exit when h(x).attr.recu = zero ;
end if ;
exit when h(x).attr.recu = zero ;
s := s.alt ;
end loop ;
----------------------------------------------------------------------------
-----------------------------------------------------------------
function coloriage ( g : graphe ) return coul_tab is
n : entier := card ( g ) ;
--package temp_ent8s is new temp_avls ( entier ) ; use temp_ent8s ;
package indexs is new temp_listes ( entier ) ; use indexs ;
type quat_bool is array ( ent8 range 1..4 ) of boolean ;
type quat_b is record
couleur : ent8 ;
nblibre : ent8 ;
libre : quat_bool ;
suiv : indexs.liste ; end record ;
package quat_b_tab is new
temp_tab_tries ( n, item_id, quat_b ) ; use quat_b_tab ;
h : quat_b_tab.table ;
package temp_nb is new temp_avls ( entier ) ; use temp_nb ;
type quat_temp_nb_table is
array ( ent8 range 1..4 ) of temp_nb.table ;
f : quat_temp_nb_table ;
i : entier ;
--------------------------------------------------------
procedure init1 ( g : graphe ; h : in out quat_b_tab.table ) is
--s : arcs.table ;
begin
if not estvide ( g ) then
init1 ( s1 ( g ), h ) ;
i := i + 1 ;
h(i).cle := g.cle ;
init ( h(i).attr.suiv ) ;
h(i).attr.couleur := 0 ;
init1 ( s2 ( g ), h ) ;
end if ;
end ;
------------------------------------------------------------------
procedure init2 ( g : graphe ; h : in out quat_b_tab.table ; f : in out
quat_temp_nb_table ) is
x, ns : entier ;
s : arcs.table ;
begin
if not estvide(g) then
init2 ( s1(g), h, f ) ;
i := i + 1 ; x := adr ( g.cle, h ) ;
s := g.attr ;
loop exit when estvide ( s ) ;
ns := adr ( s.cle, h ) ;
ins1 ( ns, h(x).attr.suiv ) ;
s := s.alt ;
end loop ;
ins ( x, f(4) ) ;
init2 ( s2(g), h, f ) ;
end if ;
end ;
-----------------------------------------------------------
y : coul_tab ;
x : entier ;
s : indexs.liste ;
cx, nbl : ent8 ;
ns : entier ;
fi : ent8 ;
-------------------------------------------------------
begin
init ( y ) ; --init ( h ) ;
for j in 1..4 loop
init ( f ( ent8(j) ) ) ;
end loop ;
i := 0 ; init1 ( g, h ) ;
i := 0 ; init2 ( g, h, f ) ;
for j in 1..n loop
for k in 1..4 loop
h(j).attr.libre(ent8(k)) := true ;
end loop ;
h(j).attr.nblibre := 4 ;
end loop ;
loop
fi := 1 ; while fi <= 4 loop
exit when not estvide ( f(fi) ) ;
fi := fi+1 ;
end loop ;
exit when fi > 4 ;
del_min ( x, f(fi) ) ;
cx := 1 ;
while cx <= 4 loop
exit when h(x).attr.libre(cx) ;
cx := cx + 1 ;
end loop ;
h(x).attr.couleur := cx ;
s := h(x).attr.suiv ;
while not estvide ( s ) loop
ns := s.info ;
if h(ns).attr.libre(cx) and h(ns).attr.couleur = 0 then
h(ns).attr.libre(cx) := false ;
nbl := h(ns).attr.nblibre ;
h(ns).attr.nblibre := nbl - 1 ;
del ( ns, f(nbl)) ;
ins ( ns, f(nbl-1)) ;
end if ;
s := s.alt ;
end loop ;
end loop ;
for j in 1..n loop
ins ( h(j).cle, h(j).attr.couleur, y ) ;
end loop ;
return y ;
end ;
--------------------------------------------------------------
--------------------------------------------------------------
end graphes ;