[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[freehaven-cvs] fancier distributions to try to simulate mixes and s...
Update of /home/freehaven/cvsroot/doc/e2e-traffic/src
In directory moria.mit.edu:/tmp/cvs-serv25178
Modified Files:
Makefile rng.cpp rng.h sim.cpp sim.h test.cpp
Log Message:
fancier distributions to try to simulate mixes and scale-free networks
Index: Makefile
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile 9 Aug 2003 02:35:13 -0000 1.1
+++ Makefile 21 Aug 2003 21:05:57 -0000 1.2
@@ -35,8 +35,11 @@
simmain.o: simmain.cpp vec.h comb.h
$(CXX) $(CFLAGS) -c simmain.cpp
-sim: sim.o vec.o rng.o simmain.o
- $(CXX) $(CFLAGS) -o sim sim.o vec.o rng.o simmain.o
+netparams.o: netparams.cpp rng.h netparams.h
+ $(CXX) $(CFLAGS) -c netparams.cpp
+
+sim: sim.o vec.o rng.o simmain.o netparams.o
+ $(CXX) $(CFLAGS) -o sim sim.o vec.o rng.o simmain.o netparams.o
test: test.o vec.o sim.o rng.o
$(CXX) $(CFLAGS) -o test test.o vec.o sim.o rng.o
Index: rng.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/rng.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rng.cpp 9 Aug 2003 02:35:13 -0000 1.1
+++ rng.cpp 21 Aug 2003 21:05:57 -0000 1.2
@@ -36,6 +36,19 @@
return state.norm();
}
+CumulativeDist
+CumulativeDist::fromDist(Dist<int> &d, int max)
+{
+ std::vector<double> probabilities(max);
+ double total = 0.0;
+ for (int i = 0; i < max; ++i) {
+ total += (probabilities[i] = d.getP(i));
+ }
+ probabilities[max-1] += (1.0-total);
+ return CumulativeDist(probabilities, false);
+}
+
+
CumulativeDist::CumulativeDist(const std::vector<double> &dist,
bool isCumulative)
: prob(dist.size()), cumDist(dist.size())
Index: rng.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/rng.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rng.h 9 Aug 2003 02:35:13 -0000 1.1
+++ rng.h 21 Aug 2003 21:05:57 -0000 1.2
@@ -3,6 +3,11 @@
#define _RNG_H
#include <vector>
+#include <cmath>
+#include "comb.h"
+
+double rng();
+double normal_rng();
template <class C>
class Dist
@@ -25,24 +30,56 @@
~ConstDist() {}
};
+class ExponentialDist : public Dist<int>
+{
+ private:
+ double p;
+ public:
+ ExponentialDist(double param) : p(param) {}
+ int get() const { int v = 0; while (rng() > p) ++v; return v; }
+ double getP(const int &val) const {
+ return p * std::pow(1-p, (int)val);
+ }
+ ~ExponentialDist() {}
+};
+
+class GeometricDist : public Dist<int>
+{
+ private:
+ double p;
+ int n;
+ public:
+ GeometricDist(double prob, int maximum) : p(prob), n(maximum) {}
+ int get() const {
+ int v = 0;
+ for (int i = 0; i < n; ++i) {
+ if (rng() < p) ++v;
+ }
+ return v;
+ }
+ double getP(int &v) const {
+ return comb(n, v)*std::pow(p,v)*std::pow(1-p,n-v);
+ }
+ ~GeometricDist() {}
+};
+
class CumulativeDist : public Dist<int>
{
private:
std::vector<double> prob;
std::vector<double> cumDist;
public:
+ static CumulativeDist fromDist(Dist<int> &d, int max);
CumulativeDist(const std::vector<double> &dist, bool isCumulative=0);
CumulativeDist(const CumulativeDist &d) : cumDist(d.cumDist) {}
CumulativeDist & operator=(const CumulativeDist &d)
- { cumDist = d.cumDist; return *this; }
+ { prob=d.prob; cumDist = d.cumDist; return *this; }
int get() const;
double getP(const int &v) const
{ return (0 <= v && v <= (int)prob.size()) ? prob[v] : 0.0; }
~CumulativeDist() {}
};
-double rng();
-double normal_rng();
inline int rng(int m) { return static_cast<int>(rng()*m); }
Index: sim.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/sim.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sim.cpp 9 Aug 2003 02:35:13 -0000 1.1
+++ sim.cpp 21 Aug 2003 21:05:57 -0000 1.2
@@ -173,7 +173,7 @@
DistBackground::getNTraffic(vec<int> &v_out, int nMessages)
{
while (nMessages-- > 0) {
- ++ v_out[ cdist.get() ];
+ ++ v_out[ dist.get() ];
}
}
@@ -319,7 +319,7 @@
nOtherHist[nAliceIdx] = nOther;
double exAlice = expectedAliceMsgs();
- double exOther = expectedAliceMsgs();
+ double exOther = expectedOtherMsgs();
if (exAlice < BG_THRESHOLD) {
for (int i = 0; i < nRecips; ++i)
background[i] += r[i]*exOther;
Index: sim.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/sim.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sim.h 9 Aug 2003 02:35:13 -0000 1.1
+++ sim.h 21 Aug 2003 21:05:57 -0000 1.2
@@ -131,12 +131,11 @@
class DistBackground : public Background {
private:
- std::vector<double> dist;
- CumulativeDist cdist;
+ CumulativeDist dist;
Dist<int> *nMessages;
public:
- DistBackground(const std::vector<double> &dist, Dist<int> *nMsgs)
- : dist(dist), cdist(dist), nMessages(nMsgs) {}
+ DistBackground(const CumulativeDist &d, Dist<int> *nMsgs)
+ : dist(d), nMessages(nMsgs) {}
void getNTraffic(vec<int> &v_out, int nMessages);
void getTraffic(vec<int> &v_out);
~DistBackground() {}
Index: test.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/test.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test.cpp 9 Aug 2003 02:35:13 -0000 1.1
+++ test.cpp 21 Aug 2003 21:05:57 -0000 1.2
@@ -2,6 +2,8 @@
#include <iostream>
#include "vec.h"
#include "comb.h"
+#include "rng.h"
+#include "netparams.h"
using namespace std;
***********************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe freehaven-cvs in the body. http://freehaven.net/