From 73f42287b8f1aa2f1e19a7fdbbb3b3b5c099c48b Mon Sep 17 00:00:00 2001
From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr>
Date: Mon, 9 Mar 2020 16:48:40 +0100
Subject: [PATCH] Fix: a bug in gg. The ER graph generation was wrong (missing
 parenthesis in if/then).

Moreover, it was not taking into account whether the graph was directed or not.
---
 tools/graphgen/randomGraph.ml | 43 ++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/tools/graphgen/randomGraph.ml b/tools/graphgen/randomGraph.ml
index df1c7600..9b6b6d97 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) =
-- 
GitLab