Tree DFS implem
This commit is contained in:
parent
2cd51bdd98
commit
0420af289e
Binary file not shown.
Binary file not shown.
|
@ -448,39 +448,35 @@ let connect l0 =
|
||||||
end
|
end
|
||||||
in aux l0 ;;
|
in aux l0 ;;
|
||||||
|
|
||||||
let even_more_pretty_printing t r ystep =
|
let even_more_pretty_printing t r ystep skip =
|
||||||
open_graph " 1800x800" ;
|
|
||||||
set_window_title "Trees" ;
|
|
||||||
|
|
||||||
let sx = Graphics.size_x () in
|
let sx = Graphics.size_x () in
|
||||||
let sy = Graphics.size_y () in
|
let sy = Graphics.size_y () in
|
||||||
|
|
||||||
let graphdata = fill_data t ystep sx sy (3*r/4) in
|
let graphdata = fill_data t ystep sx sy (6*r/10) in
|
||||||
(* graphdata is a ((int * (int * int)) * (int * int)) list array *)
|
(* graphdata is a ((int * (int * int)) * (int * int)) list array *)
|
||||||
|
(* <==> ((value, (parent_x, parent_y)), (this_x, this_y)) *)
|
||||||
|
if skip = false then begin
|
||||||
|
set_color (rgb 192 192 192);
|
||||||
|
set_line_width 15 ;
|
||||||
|
for dpth = 1 to (Array.length graphdata -1) do
|
||||||
|
connect graphdata.(dpth-1);
|
||||||
|
done;
|
||||||
|
|
||||||
set_color (rgb 192 192 192);
|
set_line_width 5 ;
|
||||||
set_line_width 15 ;
|
for dpth = 0 to (Array.length graphdata -1) do
|
||||||
for dpth = 1 to (Array.length graphdata -1) do
|
draw_list graphdata.(dpth) dpth r
|
||||||
connect graphdata.(dpth-1);
|
done;
|
||||||
done;
|
|
||||||
|
|
||||||
set_line_width 5 ;
|
let halt = ref false in
|
||||||
for dpth = 0 to (Array.length graphdata -1) do
|
while !halt = false do
|
||||||
draw_list graphdata.(dpth) dpth r
|
Unix.sleepf 0.1 ;
|
||||||
done;
|
Unix.sleepf 2.0 ;
|
||||||
|
halt := true;
|
||||||
|
done;
|
||||||
|
end;
|
||||||
|
graphdata ;;
|
||||||
|
|
||||||
let halt = ref false in
|
|
||||||
while !halt = false do
|
|
||||||
Unix.sleepf 0.1 ;
|
|
||||||
Unix.sleepf 2.0 ;
|
|
||||||
halt := true;
|
|
||||||
done;
|
|
||||||
|
|
||||||
close_graph () ;
|
|
||||||
() ;;
|
|
||||||
|
|
||||||
(* --------------------------------------| TESTS |-------------------------------------- *)
|
|
||||||
Random.self_init ;;
|
|
||||||
|
|
||||||
let generate_full_graph d =
|
let generate_full_graph d =
|
||||||
let rec aux n = match n with
|
let rec aux n = match n with
|
||||||
|
@ -490,7 +486,99 @@ let generate_full_graph d =
|
||||||
end
|
end
|
||||||
in aux d ;;
|
in aux d ;;
|
||||||
|
|
||||||
even_more_pretty_printing (generate_full_graph 3) 40 100 ;
|
let rec nth l n = match l with
|
||||||
|
| [] -> failwith "Out of range"
|
||||||
|
| h::t when n = 0 -> h
|
||||||
|
| h::t -> nth t (n-1) ;;
|
||||||
|
|
||||||
|
let even_more_fancy_dfs_prefixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
||||||
|
let rec aux tr dpth os =
|
||||||
|
match tr with
|
||||||
|
| Empty -> ()
|
||||||
|
| Leaf _ -> begin
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
end
|
||||||
|
| Node (_, g, d) -> begin
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
|
||||||
|
aux g (dpth+1) (2*os);
|
||||||
|
aux g (dpth+1) (2*os + 1);
|
||||||
|
end
|
||||||
|
in aux t 0 0 ;;
|
||||||
|
|
||||||
|
|
||||||
|
let even_more_fancy_dfs_infixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
||||||
|
let rec aux tr dpth os =
|
||||||
|
match tr with
|
||||||
|
| Empty -> ()
|
||||||
|
| Leaf _ -> begin
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
end
|
||||||
|
| Node (_, g, d) -> begin
|
||||||
|
aux g (dpth+1) (2*os);
|
||||||
|
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
aux g (dpth+1) (2*os + 1);
|
||||||
|
end
|
||||||
|
in aux t 0 0 ;;
|
||||||
|
|
||||||
|
|
||||||
|
let even_more_fancy_dfs_postfixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
||||||
|
let rec aux tr dpth os =
|
||||||
|
match tr with
|
||||||
|
| Empty -> ()
|
||||||
|
| Leaf _ -> begin
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
end
|
||||||
|
| Node (_, g, d) -> begin
|
||||||
|
aux g (dpth+1) (2*os);
|
||||||
|
aux g (dpth+1) (2*os + 1);
|
||||||
|
|
||||||
|
let data = nth graphdata.(dpth) os in
|
||||||
|
set_color (rgb rfound gfound bfound);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
Unix.sleepf tts;
|
||||||
|
set_color (rgb rmark gmark bmark);
|
||||||
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
end
|
||||||
|
in aux t 0 0 ;;
|
||||||
|
|
||||||
|
(* --------------------------------------| TESTS |-------------------------------------- *)
|
||||||
|
Random.self_init ;;
|
||||||
|
|
||||||
|
open_graph " 1800x800" ;;
|
||||||
|
set_window_title "Trees" ;;
|
||||||
|
|
||||||
|
let gdata = even_more_pretty_printing (generate_full_graph 4) 40 150 false ;;
|
||||||
|
|
||||||
|
even_more_fancy_dfs_prefixe (generate_full_graph 4) gdata 40 0.2 255 255 32 32 32 255 ;;
|
||||||
|
|
||||||
|
close_graph () ;;
|
||||||
|
|
||||||
(* compilation command : ocamlfind ocamlc -linkpkg -package unix -linkpkg -package graphics pretty_printing.ml *)
|
(* compilation command : ocamlfind ocamlc -linkpkg -package unix -linkpkg -package graphics pretty_printing.ml *)
|
||||||
print_int 0 ;;
|
print_int 0 ;;
|
||||||
|
|
Loading…
Reference in New Issue