diff --git a/tools/graphgen/randomGraph.ml b/tools/graphgen/randomGraph.ml index df1c7600cc004e5a5215d88602efe9ab30e2a7b6..9b6b6d971876e4d0623af17b06af4476b3c54e91 100644 --- a/tools/graphgen/randomGraph.ml +++ b/tools/graphgen/randomGraph.ml @@ -8,23 +8,34 @@ type probability = float (*between 0 and 1*) let gen_ER : (bool -> int -> probability -> Topology.t) = fun directed nb p -> - let (node_succ:node_succ_t) = Hashtbl.create nb and nodes = create_nodes "p" (0,nb) in - iteri (fun i n -> + let (node_succ:node_succ_t) = Hashtbl.create nb + and nodes = create_nodes "p" (0,nb) + in + iteri (fun i n -> iteri (fun j m -> - 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 -> []))) - ) nodes - ) nodes; - let nl = id_to_empty_nodes nodes in - { - nodes = nl; - succ = (fun n -> try Hashtbl.find node_succ n with Not_found -> []); - of_id = get_of_id nl; - directed = directed - } + 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 -> []))); + ) 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 -> []))); + ) + ) + ) + nodes + ) + nodes; + let nl = id_to_empty_nodes nodes in + { + nodes = nl; + succ = (fun n -> try Hashtbl.find node_succ n with Not_found -> []); + of_id = get_of_id nl; + directed = directed + } let rec init_m_nodes : (int -> node_succ_t -> node_id list -> node_id list) =