Index: branches/reconfiguration/platforms/tsar_generic_iob/scripts/random_faulty_core_router.py
===================================================================
--- branches/reconfiguration/platforms/tsar_generic_iob/scripts/random_faulty_core_router.py	(revision 894)
+++ branches/reconfiguration/platforms/tsar_generic_iob/scripts/random_faulty_core_router.py	(revision 902)
@@ -1,3 +1,3 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 import onerun
@@ -81,76 +81,97 @@
         return self.get_totalclusters() * self.nprocs
 
-for xsize, ysize in ((3, 3), (4, 4), (4, 8), (8, 8), (8, 16), (16, 16)):
-    # --------------------------------------------------------------------
-    # simulation without faults
-    # --------------------------------------------------------------------
-    cfgname = 'output_{0}_{1}'.format(xsize, ysize)
-    args = RunArguments(cfgname, xsize, ysize)
-    onerun.run(args)
+# activate the different kinds of simulation
+SIM_FAULTFREE = False
+SIM_FAULTCORES = False
+SIM_FAULTROUTERS = False
+SIM_FAULTMIXED = True
 
-    for pct in (10, 20, 30, 40, 50, 60):
-        # --------------------------------------------------------------------
-        # simulation with random faulty cores
-        # --------------------------------------------------------------------
-        cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct)
+# probability of faulty router (for mixed simul)
+SIM_FAULTMIXED_PROBROUTER = 0.05 # 5%
+
+for xsize, ysize in [(4, 4), (4, 8), (8, 8), (8, 16), (16, 16)]:
+    if SIM_FAULTFREE:
+        # ---------------------------------------------------------------------
+        # simulation without faults
+        # ---------------------------------------------------------------------
+        cfgname = 'output_{0}_{1}'.format(xsize, ysize)
         args = RunArguments(cfgname, xsize, ysize)
-
-        faultycount = args.get_faultycorecount(pct)
-        print "{0}/{1} faulty cores\n".\
-            format(faultycount, args.get_totalcores())
-
-        n = 0
-        while n < faultycount:
-            cx = random.randint(0, args.xmax)
-            cy = random.randint(0, args.ymax)
-            cl = random.randint(0, args.pmax)
-            if args.add_faultycore((cx, cy, cl)): n += 1
-
         onerun.run(args)
 
-        # --------------------------------------------------------------------
-        # simulation with random faulty routers
-        # --------------------------------------------------------------------
-        cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct)
-        args = RunArguments(cfgname, xsize, ysize)
+    for pct in xrange(5, 60, 5): # 5, 10, ..., 55
+        if SIM_FAULTCORES:
+            # -----------------------------------------------------------------
+            # simulation with random faulty cores
+            # -----------------------------------------------------------------
+            cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct)
+            args = RunArguments(cfgname, xsize, ysize)
 
-        faultycount = args.get_faultyroutercount(pct)
-        print "{0}/{1} faulty routers\n".\
-            format(faultycount, args.get_totalclusters())
+            faultycount = args.get_faultycorecount(pct)
+            print "{0}/{1} faulty cores\n".\
+                  format(faultycount, args.get_totalcores())
 
-        n = 0
-        while n < faultycount:
-            cx = random.randint(0, args.xmax)
-            cy = random.randint(0, args.ymax)
-            if args.add_faultyrouter((cx, cy)): n += 1
+            n = 0
+            while n < faultycount:
+                cx = random.randint(0, args.xmax)
+                cy = random.randint(0, args.ymax)
+                cl = random.randint(0, args.pmax)
+                if args.add_faultycore((cx, cy, cl)): n += 1
 
-        onerun.run(args)
+            onerun.run(args)
 
-        # --------------------------------------------------------------------
-        # simulation with random faulty routers and cores
-        # --------------------------------------------------------------------
-        cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct)
-        args = RunArguments(cfgname, xsize, ysize)
+        if SIM_FAULTROUTERS:
+            # -----------------------------------------------------------------
+            # simulation with random faulty routers
+            # -----------------------------------------------------------------
+            cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct)
+            args = RunArguments(cfgname, xsize, ysize)
 
-        total = args.get_totalclusters() + args.get_totalcores()
-        faultycount = args.get_faultycount(total, pct)
-        print "{0}/{1} faulty routers/cores\n".\
-                format(faultycount, total)
+            faultycount = args.get_faultyroutercount(pct)
+            print "{0}/{1} faulty routers\n".\
+                  format(faultycount, args.get_totalclusters())
 
-        n = 0
-        while n < faultycount:
-            cx = random.randint(0, args.xmax)
-            cy = random.randint(0, args.ymax)
-            if (random.random() < 0.05):    # faulty router: 5% of probability
-                if not args.add_faultyrouter((cx, cy)):
-                    continue
+            n = 0
+            while n < faultycount:
+                cx = random.randint(0, args.xmax)
+                cy = random.randint(0, args.ymax)
+                if args.add_faultyrouter((cx, cy)): n += 1
 
-            else:                           # faulty core: 95% of probability
-                cl = random.randint(0, args.pmax)
-                if not args.add_faultycore((cx, cy, cl)):
-                    continue
+            onerun.run(args)
 
-            n += 1
+        if SIM_FAULTMIXED:
+            # -----------------------------------------------------------------
+            # simulation with random faulty routers and cores
+            # -----------------------------------------------------------------
+            cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct)
+            args = RunArguments(cfgname, xsize, ysize)
 
-        onerun.run(args)
+            total = args.get_totalclusters() + args.get_totalcores()
+            faultycount = args.get_faultycount(total, pct)
 
+            print "\nprobability of faulty routers: {0}".\
+                  format(SIM_FAULTMIXED_PROBROUTER)
+            fr = 0
+            fc = 0
+            while (fr + fc) < faultycount:
+                cx = random.randint(0, args.xmax)
+                cy = random.randint(0, args.ymax)
+                if (random.random() < SIM_FAULTMIXED_PROBROUTER):
+                    # add faulty router
+                    fr += 1
+                    while not args.add_faultyrouter((cx, cy)):
+                        cx = random.randint(0, args.xmax)
+                        cy = random.randint(0, args.ymax)
+
+                else:
+                    # add faulty core
+                    fc += 1
+                    cl = random.randint(0, args.pmax)
+                    while not args.add_faultycore((cx, cy, cl)):
+                        cx = random.randint(0, args.xmax)
+                        cy = random.randint(0, args.ymax)
+                        cl = random.randint(0, args.pmax)
+
+            print "faulty routers / faulty cores = {0} / {1}".format(fr, fc)
+            onerun.run(args)
+
+# vim: ts=4 : sts=4 : sw=4 : et
