~ubuntu-branches/ubuntu/breezy/ocamlgraph/breezy

« back to all changes in this revision

Viewing changes to demo_planar.ml

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Le Gall
  • Date: 2005-03-23 23:17:46 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050323231746-8rmzgp3zyslg4me5
Tags: 0.90-2
* Transition to ocaml 3.08.3 : depends on ocaml-nox-3.08.3
* Patch 03_META use graph.cma and graph.cmxa ( Closes: #294806 )
* Correct the patch 01_makefile to install graph.a ( Closes: #289138 )

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
open Printf
3
3
open Graph
4
4
 
 
5
module U = Unix
 
6
  
 
7
let utime f x =                                                   
 
8
  let u = (U.times()).U.tms_utime in                                  
 
9
  let y = f x in
 
10
  let ut = (U.times()).U.tms_utime -. u in
 
11
  (y,ut)
 
12
 
 
13
let print_utime f x = 
 
14
  let (y,ut) = utime f x in
 
15
  Printf.printf "user time: %2.2f\n" ut; flush Pervasives.stdout;
 
16
  y
 
17
 
5
18
let () = 
6
19
  printf "planar graphs demo
7
20
  use mouse to select two vertices (blue = source, green = destination)
105
118
let new_graph () = R.graph ~xrange:(20,780) ~yrange:(20,580) ~prob n
106
119
let g = ref (new_graph ())
107
120
 
 
121
let () = printf "nb edges : %d\n" (G.nb_edges !g); flush stdout
 
122
 
108
123
(* let () = g := read_graph "tmp/carron.txt" *)
109
124
 
110
125
open Graphics
201
216
let dijkstra () = match !selection with
202
217
  | Two (v1, v2) ->
203
218
      printf "running Dijkstra... "; flush stdout;
 
219
      let t_ = ref 0.0 in
204
220
      begin try
205
 
        let p,l = Dij.shortest_path !g v1 v2 in
206
 
        printf "path of length %d\n" l; flush stdout;
 
221
        let (p,l),t = utime (Dij.shortest_path !g v1) v2 in
 
222
        t_ := t;
 
223
        printf "path of length %d (%d nodes) (%2.2f s)\n" l (List.length p) t;
 
224
        flush stdout; 
207
225
        List.iter 
208
226
          (fun e -> 
209
227
             let v1 = G.E.src e in
213
231
        ignore (Graphics.wait_next_event [ Key_pressed; Button_down ]);
214
232
        draw_graph ()
215
233
      with Not_found -> 
216
 
        printf "no path\n"; flush stdout
 
234
        printf "no path (%2.2f s)\n" !t_; flush stdout
217
235
      end
218
236
  | _ -> 
219
237
      ()