Skip to content
Snippets Groups Projects
Commit 86adc124 authored by erwan's avatar erwan
Browse files

Fix: various issues in gg

- the mean degree was wrong
- the er generation was wrong
parent 1fd63e93
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 09/03/2020 (at 14:54) by Erwan Jahier> *)
(* Time-stamp: <modified the 10/03/2020 (at 17:00) by Erwan Jahier> *)
open Graph
open Graph.Dot_ast
......@@ -155,9 +155,12 @@ let (get_degree:t -> int*int) =
else
let node_deg n = List.length (t.succ (n.id)) in
let d_start = node_deg ((List.hd t.nodes)) in
List.fold_left (fun (d_min,d_max) n ->
(min (node_deg n) d_min, max (node_deg n) d_max)
) (d_start,d_start) (List.tl t.nodes)
List.fold_left
(fun (d_min,d_max) n ->
(min (node_deg n) d_min, max (node_deg n) d_max)
)
(d_start,d_start)
(List.tl t.nodes)
let (get_nb_link: t -> int) =
fun t ->
......@@ -165,10 +168,10 @@ let (get_nb_link: t -> int) =
(fun acc n -> ((List.length (t.succ n.id))) + acc) 0 t.nodes
in
if t.directed then res else res/2
let (get_mean_degree : t -> float) =
fun t ->
(float_of_int (get_nb_link t)) /. (float_of_int (List.length t.nodes))
2.0 *. (float_of_int (get_nb_link t)) /. (float_of_int (List.length t.nodes))
let bfs : (t -> string -> bool * string list) =
fun t n ->
......
......@@ -146,7 +146,8 @@ let to_dot_string : (Topology.t -> string -> (string * string) list -> string)
let attrs_to_string (an,av) = Printf.sprintf "%s=%s" an av in
let graph_attr =
if attrs = [] then "" else
Printf.sprintf "graph [%s]" (String.concat " " (List.map attrs_to_string attrs))
Printf.sprintf "graph [%s]"
(String.concat " " (List.map attrs_to_string attrs))
in
let node_to_node_string n =
Printf.sprintf " %s [algo=\"%s\"]\n" n.Topology.id n.Topology.file
......@@ -158,24 +159,31 @@ let to_dot_string : (Topology.t -> string -> (string * string) list -> string)
let links =
List.map
(fun (w,neighbour) ->
(match w with
| 1 ->
if n.Topology.id < neighbour then
(match w with
| 1 ->
assert (n.Topology.id <> neighbour);
if n.Topology.id < neighbour then
Printf.sprintf (" %s -- %s") n.Topology.id neighbour
else
Printf.sprintf (" %s -- %s") neighbour n.Topology.id
| x ->
if n.Topology.id < neighbour then
Printf.sprintf (" %s -- %s [weight=%d]") n.Topology.id neighbour x
else
Printf.sprintf (" %s -- %s") neighbour n.Topology.id
| x ->
Printf.sprintf (" %s -- %s [weight=%d]") n.Topology.id neighbour x
)
Printf.sprintf (" %s -- %s [weight=%d]") neighbour n.Topology.id x
)
)
succ
in
links
in
let links = List.map node_to_link_string g.nodes in
let links = List.sort_uniq compare (List.flatten links) in
let links = List.flatten links in
let links = List.sort_uniq compare links in
let links = String.concat "\n" links in
Printf.sprintf "graph %s {\n%s\n%s\n%s\n}\n" name graph_attr nodes links
Printf.sprintf "%s %s {\n%s\n%s\n\n%s\n}\n"
(if g.directed then "digraph" else "graph")
name graph_attr nodes links
let make_dot : (Topology.t -> string -> (string * string) list -> unit) =
......
......@@ -274,7 +274,7 @@ let (mkoptab : string array -> t -> unit) =
mkopt args ["--directed";"-dir"]
(Arg.Unit (fun () -> args.directed <- true))
[(["Generate a directed graph."],"void")];
[(["NOT WORKING! Generate a directed graph."],"void")];
mkopt args ["--help";"-h"]
(Arg.Unit (fun () -> help args ((argv.(0))^(if args.action = "void" then ""
......
......@@ -11,19 +11,18 @@ let gen_ER : (bool -> int -> probability -> Topology.t) =
let (node_succ:node_succ_t) = Hashtbl.create nb
and nodes = create_nodes "p" (0,nb)
in
let succ n = try Hashtbl.find node_succ n with Not_found -> [] in
let add_succ n m = Hashtbl.replace node_succ n ((1,m)::(succ n)) in
iteri (fun i n ->
iteri (fun j m ->
if not directed then (
if i < j && (Random.float 1.) < p then (
(Hashtbl.replace node_succ n
((1,m)::(try Hashtbl.find node_succ n with Not_found -> [])));
(Hashtbl.replace node_succ m
((1,n)::(try Hashtbl.find node_succ m with Not_found -> [])));
add_succ n m;
add_succ m n
);
) else (
if i <> j && (Random.float 1.) < p then
(Hashtbl.replace node_succ n
((1,m)::(try Hashtbl.find node_succ n with Not_found -> [])));
)
add_succ n m;
)
)
nodes
......@@ -32,7 +31,7 @@ let gen_ER : (bool -> int -> probability -> Topology.t) =
let nl = id_to_empty_nodes nodes in
{
nodes = nl;
succ = (fun n -> try Hashtbl.find node_succ n with Not_found -> []);
succ = succ;
of_id = get_of_id nl;
directed = directed
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment