DIJKSTRA YEAH BUDDY

This commit is contained in:
Alexandre 2024-06-04 20:59:15 +02:00
parent 5b24934b4f
commit 0f2e25bec9
4 changed files with 593 additions and 9 deletions

BIN
a.out

Binary file not shown.

Binary file not shown.

Binary file not shown.

602
graphs.ml
View File

@ -1,12 +1,12 @@
open Graphics ;;
(* SOMMAIRE
- misc functions : 20 ~ 65
- main function : 68 - 120
- type 2 printing: 122 - 270
- DFS : 275 - 530 (yes the function is that big)
- BFS : 532 - 727
- misc functions : 20
- main function : 68
- type 2 printing: 122
- DFS : 373
- BFS : 630
- Dijkstra :
@ -219,7 +219,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
done
done;
let roff = (6*r)/5 in
let roff = (9*r)/8 in
let roff2 = (7*r)/5 in
let rsize = (3*r)/4 in
let wcolor = rgb 255 255 255 in
@ -824,6 +824,589 @@ let another_type_of_bfs (gr : type2graph) r d =
with
| Stdlib.Queue.Empty -> ignore (Scanf.bscanf Scanf.Scanning.stdin "%d\n" identity) ;;
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
type 'a dynamic_array = { mutable arr : 'a array ; mutable len : int } ;;
let create () =
{ arr = [||] ; len = 0 } ;;
let init a =
{ arr = a ; len = Array.length a } ;;
let length a = a.len ;;
let get a i =
assert(0 <= i && i < a.len) ;
a.arr.(i) ;;
let set a i x =
assert(0 <= i && i < a.len) ;
a.arr.(i) <- x ;;
let resize a newlen e =
a.arr <- Array.init newlen (fun i -> if i < a.len then a.arr.(i) else e) ;;
let append a e =
if a.len = Array.length a.arr then
resize a (a.len * 2 + 1) e ;
a.arr.(a.len) <- e ;
a.len <- a.len + 1 ;;
let pop a =
assert(a.len > 0) ;
a.len <- a.len - 1 ;
let x = a.arr.(a.len) in
if a.len < (Array.length a.arr) / 4 then
resize a (a.len * 2) a.arr.(0) ;
x ;;
module H = Hashtbl ;;
(*
'a : type for elements
'b : type for priorities (hypothesis : totally ordered type).
*)
type ('a, 'b) priority_queue = { heap : ('a * 'b) dynamic_array ; locate : ('a, int) H.t } ;;
let pq_create () =
{ heap = create () ; locate = H.create 200 } ;;
let pq_is_empty pq =
length pq.heap = 0 ;;
let pq_mem pq elt =
H.mem pq.locate elt ;;
(* SWAPS indexes i and j in the heap AND the hash table : *)
let pq_swap pq i j =
let elt1 = fst (get pq.heap i)
and elt2 = fst (get pq.heap j) in
let tmp = (get pq.heap i) in
set pq.heap i (get pq.heap j) ;
set pq.heap j tmp ;
H.replace pq.locate elt1 j ;
H.replace pq.locate elt2 i ;;
(* PERCOLATE UP AND DOWN *)
let pq_get_priority pq i =
snd (get pq.heap i) ;;
let rec pq_percolate_up pq i =
let father = ((i-1)/2) in
if i > 0 && (pq_get_priority pq i) < (pq_get_priority pq father) then begin
pq_swap pq i father ;
pq_percolate_up pq father
end ;;
let rec pq_percolate_down pq i =
let n = length pq.heap in
let left_child = 2*i+1 and right_child = 2*i+2 in
let m = ref (pq_get_priority pq i) in
let max_node = ref i in
if left_child < n && pq_get_priority pq left_child < !m then begin
m := pq_get_priority pq left_child ;
max_node := left_child
end ;
if right_child < n && pq_get_priority pq right_child < !m then begin
m := pq_get_priority pq right_child ;
max_node := right_child
end ;
if !max_node <> i then
pq_swap pq i !max_node ;;
(* ACTUAL FUNCTIONS *)
exception BreakOfLoop ;;
let pq_add elt pq prio =
append pq.heap (elt, prio) ;
H.add pq.locate elt (length pq.heap - 1) ;
pq_percolate_up pq (length pq.heap - 1) ;;
let pq_min pq =
assert(length pq.heap > 0 ) ;
get pq.heap 0 ;;
let pq_extract_min pq =
let n = length pq.heap in
if n <= 0 then raise BreakOfLoop;
pq_swap pq 0 (n-1) ;
let (elt, prio) = pop pq.heap in
H.remove pq.locate elt ;
if n > 1 then
pq_percolate_down pq 0 ;
(elt, prio) ;;
let pq_priority pq elt =
pq_get_priority pq (H.find pq.locate elt) ;;
let pq_update_priority pq elt prio =
let index = H.find pq.locate elt in
let p = pq_get_priority pq index in
set pq.heap index (elt, prio) ;
if p > prio then
pq_percolate_up pq index
else
pq_percolate_down pq index ;;
let pq_init a default_priority =
let pq = pq_create () in
Array.iter (fun x -> pq_add x pq default_priority) a ;
pq ;;
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
let another_type_of_dijkstra (gr : type2graph) r d =
let colors = Array.make_matrix gr.width gr.height (rgb 0 0 0) in
for i = 0 to gr.width -1 do
for j = 0 to gr.height -1 do
if (i*gr.width + j) mod 7 = 0 then
colors.(i).(j) <- rgb 0 0 200
else if (i*gr.width + j) mod 7 = 1 then
colors.(i).(j) <- rgb 0 200 0
else if (i*gr.width + j) mod 7 = 2 then
colors.(i).(j) <- rgb 0 200 200
else if (i*gr.width + j) mod 7 = 3 then
colors.(i).(j) <- rgb 200 0 0
else if (i*gr.width + j) mod 7 = 4 then
colors.(i).(j) <- rgb 200 0 200
else if (i*gr.width + j) mod 7 = 5 then
colors.(i).(j) <- rgb 200 200 0
else
colors.(i).(j) <- rgb 200 200 200
done
done;
set_line_width 4;
set_color black ;
for i = 0 to gr.width -1 do
for j = 0 to gr.height -1 do
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) then begin (* SO *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*(j-1))|] ;
end;
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) then begin (* O *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*j)|] ;
end;
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) then begin (* NO *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*(j+1))|] ;
end;
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) then begin (* N *)
draw_poly_line [|node_xy; (r + (2*r + d)*i), (r + (2*r + d)*(j+1))|] ;
end;
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) then begin (* NE *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*(j+1))|] ;
end;
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) then begin (* E *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*j)|] ;
end;
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) then begin (* SE *)
draw_poly_line [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*(j-1))|] ;
end;
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) then begin (* S *)
draw_poly_line [|node_xy; (r + (2*r + d)*i), (r + (2*r + d)*(j-1))|] ;
end;
done
done;
let roff = (9*r)/8 in
let roff2 = (7*r)/5 in
let rsize = (3*r)/4 in
let wcolor = rgb 64 64 64 in
let bcolor = rgb 0 0 0 in
let is_weighted = true in
set_line_width 8;
for i = 0 to gr.width -1 do
for j = 0 to gr.height -1 do
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) then begin (* SO *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff) (snd node_xy - roff) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy - roff) gr.g.(i).(j).edges.(0) rsize;
end
end;
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) then begin (* O *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff2) (snd node_xy) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy - roff2) (snd node_xy) gr.g.(i).(j).edges.(1) rsize;
end
end;
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) then begin (* NO *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff) (snd node_xy + roff) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy + roff) gr.g.(i).(j).edges.(2) rsize;
end
end;
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) then begin (* N *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy) (snd node_xy + roff2) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy + roff2) gr.g.(i).(j).edges.(3) rsize;
end
end;
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) then begin (* NE *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff) (snd node_xy + roff) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy + roff) gr.g.(i).(j).edges.(4) rsize;
end
end;
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) then begin (* E *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff2) (snd node_xy) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy + roff2) (snd node_xy) gr.g.(i).(j).edges.(5) rsize;
end
end;
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) then begin (* SE *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff) (snd node_xy - roff) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy - roff) gr.g.(i).(j).edges.(6) rsize;
end
end;
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) then begin (* S *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy) (snd node_xy - roff2) (3*rsize/4) ;
set_color wcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy - roff2) gr.g.(i).(j).edges.(7) rsize;
end
end;
done
done;
set_line_width 5;
for i = 0 to gr.width -1 do
for j = 0 to gr.height -1 do
set_color (rgb 48 48 48) ;
fill_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color black ;
draw_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color (rgb 48 48 48) ;
draw_integer (r + (2*r + d)*i) (r + (2*r + d)*j) gr.g.(i).(j).tag r
done
done ;
let draw_tile i j =
set_line_width 5;
set_color (rgb 48 48 48) ;
fill_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color black;
draw_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color colors.(i).(j);
draw_integer (r + (2*r + d)*i) (r + (2*r + d)*j) gr.g.(i).(j).tag r ;
let fcolor = rgb 255 0 0 in
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) then begin (* SO *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff) (snd node_xy - roff) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy - roff) gr.g.(i).(j).edges.(0) rsize;
end
end;
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) then begin (* O *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff2) (snd node_xy) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy - roff2) (snd node_xy) gr.g.(i).(j).edges.(1) rsize;
end
end;
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) then begin (* NO *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy - roff) (snd node_xy + roff) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy + roff) gr.g.(i).(j).edges.(2) rsize;
end
end;
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) then begin (* N *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy) (snd node_xy + roff2) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy + roff2) gr.g.(i).(j).edges.(3) rsize;
end
end;
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) then begin (* NE *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff) (snd node_xy + roff) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy + roff) gr.g.(i).(j).edges.(4) rsize;
end
end;
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) then begin (* E *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff2) (snd node_xy) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy + roff2) (snd node_xy) gr.g.(i).(j).edges.(5) rsize;
end
end;
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) then begin (* SE *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy + roff) (snd node_xy - roff) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy - roff) gr.g.(i).(j).edges.(6) rsize;
end
end;
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) then begin (* S *)
if is_weighted then begin
set_color bcolor;
fill_circle (fst node_xy) (snd node_xy - roff2) (3*rsize/4) ;
set_color fcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy - roff2) gr.g.(i).(j).edges.(7) rsize;
end
end;
in
(* Actual BFS *)
let pq = pq_create () in
pq_add (gr.width/2, gr.height/2, gr.width/2, gr.height/2, [||], [||]) pq 0 ;
let drawn = Array.make_matrix gr.width gr.height false in
let loops = Array.make_matrix gr.width gr.height [||] in
for i = 0 to gr.width-1 do
for j = 0 to gr.height-1 do
loops.(i).(j) <- Array.make 8 false;
done
done;
let dcolor = rgb 0 255 0 in
let done_smth = ref true in
let mindists = Array.make_matrix gr.width gr.height 999 in
try
while true do
done_smth := false;
let ((i0, j0, i, j, path_arr, bigpath_arr), depth) = pq_extract_min pq in
if true then begin
if drawn.(i).(j) = false then begin
drawn.(i).(j) <- true;
draw_tile i j;
done_smth := true;
end;
if drawn.(i0).(j0) = false then begin
drawn.(i0).(j0) <- true;
draw_tile i0 j0;
done_smth := true;
end;
if mindists.(i).(j) > depth then begin
mindists.(i).(j) <- depth;
set_color (rgb 48 48 48) ;
fill_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color black ;
draw_circle (r + (2*r + d)*i) (r + (2*r + d)*j) r ;
set_color colors.(i).(j);
draw_integer (r + (2*r + d)*i) (r + (2*r + d)*j) depth r
end;
let node_xy = ((r + (2*r + d)*i0), (r + (2*r + d)*j0)) in
let dx = i - i0 and dy = j - j0 in
if (dx, dy) = (1, 1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy + roff) gr.g.(i0).(j0).edges.(4) rsize;
done_smth := true;
end
else if (dx, dy) = (1, 0) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy + roff2) (snd node_xy) gr.g.(i0).(j0).edges.(5) rsize;
done_smth := true;
end
else if (dx, dy) = (1, -1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy + roff) (snd node_xy - roff) gr.g.(i0).(j0).edges.(6) rsize;
done_smth := true;
end
else if (dx, dy) = (0, -1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy - roff2) gr.g.(i0).(j0).edges.(7) rsize;
done_smth := true;
end
else if (dx, dy) = (-1, -1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy - roff) gr.g.(i0).(j0).edges.(0) rsize;
done_smth := true;
end
else if (dx, dy) = (-1, 0) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy - roff2) (snd node_xy) gr.g.(i0).(j0).edges.(1) rsize;
done_smth := true;
end
else if (dx, dy) = (-1, 1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy - roff) (snd node_xy + roff) gr.g.(i0).(j0).edges.(2) rsize;
done_smth := true;
end
else if (dx, dy) = (0, 1) then begin
set_color dcolor;
set_line_width 3;
draw_integer (fst node_xy) (snd node_xy + roff2) gr.g.(i0).(j0).edges.(3) rsize;
done_smth := true;
end;
set_color white;
fill_circle (1200-r) (800-r) r;
set_color black;
draw_integer (1200-r) (800-r) depth r;
if !done_smth then
Unix.sleepf 0.05;
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(0) = false then begin (* SO *)
loops.(i).(j).(0) <- true;
pq_add (i, j, i-1, j-1, [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*(j-1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i-1))/3, (2 * (snd node_xy) + r + (2*r + d)*(j-1))/3|]) pq (depth+gr.g.(i).(j).edges.(0));
end;
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(1) = false then begin (* O *)
loops.(i).(j).(1) <- true;
pq_add (i, j, i-1, j, [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*j)|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i-1))/3, (2 * (snd node_xy) + r + (2*r + d)*j)/3|]) pq (depth+gr.g.(i).(j).edges.(1));
end;
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(2) = false then begin (* NO *)
loops.(i).(j).(2) <- true;
pq_add (i, j, i-1, j+1, [|node_xy; (r + (2*r + d)*(i-1)), (r + (2*r + d)*(j+1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i-1))/3, (2 * (snd node_xy) + r + (2*r + d)*(j+1))/3|]) pq (depth+gr.g.(i).(j).edges.(2));
end;
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(3) = false then begin (* N *)
loops.(i).(j).(3) <- true;
pq_add (i, j, i, j+1, [|node_xy; (r + (2*r + d)*i), (r + (2*r + d)*(j+1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*i)/3, (2 * (snd node_xy) + r + (2*r + d)*(j+1))/3|]) pq (depth+gr.g.(i).(j).edges.(3));
end;
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(4) = false then begin (* NE *)
loops.(i).(j).(4) <- true;
pq_add (i, j, i+1, j+1, [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*(j+1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i+1))/3, (2 * (snd node_xy) + r + (2*r + d)*(j+1))/3|]) pq (depth+gr.g.(i).(j).edges.(4));
end;
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(5) = false then begin (* E *)
loops.(i).(j).(5) <- true;
pq_add (i, j, i+1, j, [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*j)|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i+1))/3, (2 * (snd node_xy) + r + (2*r + d)*j)/3|]) pq (depth+gr.g.(i).(j).edges.(5));
end;
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(6) = false then begin (* SE *)
loops.(i).(j).(6) <- true;
pq_add (i, j, i+1, j-1, [|node_xy; (r + (2*r + d)*(i+1)), (r + (2*r + d)*(j-1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*(i+1))/3, (2 * (snd node_xy) + r + (2*r + d)*(j-1))/3|]) pq (depth+gr.g.(i).(j).edges.(6));
end;
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) && ((i >= 0) && (j >= 0) && (i < gr.width) && (j < gr.height)) && loops.(i).(j).(7) = false then begin (* S *)
loops.(i).(j).(7) <- true;
pq_add (i, j, i, j-1, [|node_xy; (r + (2*r + d)*i), (r + (2*r + d)*(j-1))|], [|node_xy; (2 * (fst node_xy) + r + (2*r + d)*i)/3, (2 * (snd node_xy) + r + (2*r + d)*(j-1))/3|]) pq (depth+gr.g.(i).(j).edges.(7));
end
end;
done;
()
with
| BreakOfLoop -> ignore (Scanf.bscanf Scanf.Scanning.stdin "%d\n" identity) ;;
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
(* ------------------------------------------------------------*)
@ -833,11 +1416,12 @@ let another_type_of_bfs (gr : type2graph) r d =
open_graph " 1200x800" ;;
set_window_title "Graphs" ;;
let type2 = generate_type2_graph 7 5 40 1 100 ;;
let type2 = generate_type2_graph 7 5 40 1 4 ;;
another_type_of_graph_printing type2 35 100 true ;;
(*another_type_of_graph_printing type2 35 100 true ;;*)
(*another_type_of_dfs type2 35 75 ;;*)
(*another_type_of_bfs type2 35 75 ;;*)
another_type_of_dijkstra type2 35 75 ;;
close_graph () ;;