[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Refactor the "binomial" part of "BinomialCottrellMixQue...



Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv24160/src/minion/lib/mixminion/server

Modified Files:
	ServerQueue.py 
Log Message:
Refactor the "binomial" part of "BinomialCottrellMixQueue" to be a mixin class.

Index: ServerQueue.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerQueue.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ServerQueue.py	20 Feb 2003 16:57:40 -0000	1.9
+++ ServerQueue.py	26 Mar 2003 16:32:02 -0000	1.10
@@ -565,14 +565,22 @@
         else:
             return []
 
-class BinomialCottrellMixQueue(CottrellMixQueue):
-    """Same algorithm as CottrellMixQueue, but instead of sending N messages
-       from the pool of size P, sends each message with probability N/P."""
+class _BinomialMixin:
+    """Mixin class.  Given a MixQueue that defines a _getBatchSize function,
+       replaces the getBatch function with one that -- instead of sending N
+       messages from a pool of size P, sends each message with probability
+       N/P."""
     def getBatch(self):
         n = self._getBatchSize()
-        if n == 0:
+        count = self.count()
+        if n == 0 or count == 0:
             return []
-        msgProbability = n / float(self.count())
+        msgProbability = n / float(count)
         rng = getCommonPRNG()
         return rng.shuffle([ h for h in self.getAllMessages()
                              if rng.getFloat() < msgProbability ])
+
+class BinomialCottrellMixQueue(_BinomialMixin,CottrellMixQueue):
+    """Same algorithm as CottrellMixQueue, but instead of sending N messages
+       from the pool of size P, sends each message with probability N/P."""
+