Start of Wright-Fisher dynamics using STL. Mutations stored as std::set, species...
authorDariusz Murakowski <murakdar@mit.edu>
Fri, 5 Apr 2013 03:28:36 +0000 (23:28 -0400)
committerDariusz Murakowski <murakdar@mit.edu>
Fri, 5 Apr 2013 03:28:55 +0000 (23:28 -0400)
Makefile [new file with mode: 0644]
wf.cpp [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..3b3fcc4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,35 @@
+
+SRCS = wf.cpp
+EXECNAME = $(SRCS:.cpp=)
+OBJS = $(SRCS:.cpp=.o)
+
+CXX = c++
+CFLAGS = $(DBGFLAG) -Wall -Wextra
+INCLUDES =
+LFLAGS = $(DBGFLAG)
+LIBS = -lm
+
+ifeq ($(dbg),1)
+       DBGFLAG = -g
+else
+       DBGFLAG = -O3
+endif
+
+# now the actual build rules, pretty general
+
+.PHONY: clean
+
+all: $(EXECNAME)
+#      @echo done making $(EXECNAME)
+
+$(EXECNAME): $(OBJS)
+       $(CXX) -o $(EXECNAME) $(OBJS) $(LFLAGS) $(LIBS)
+#      $(CXX) $(CFLAGS) $(INCLUDES) -o $(EXECNAME) $(OBJS) $(LFLAGS) $(LIBS)
+
+# equivalent way using 'old-fashioned suffix rules' would be .c.o:
+%.o: %.cpp
+       $(CXX) -c $(CFLAGS) $(INCLUDES) $< -o $@
+
+clean:
+       $(RM) *.o $(EXECNAME)
+
diff --git a/wf.cpp b/wf.cpp
new file mode 100644 (file)
index 0000000..75caa50
--- /dev/null
+++ b/wf.cpp
@@ -0,0 +1,33 @@
+
+#include <iostream>
+
+#include <set>
+#include <map>
+
+typedef unsigned int spin_t;
+typedef std::set<spin_t> mutset_t;  // virus is defined by set of mutations
+typedef std::map<mutset_t,int> pop_t;   // number of each virus species
+
+
+int main(int argc, char **argv)
+{
+    argc++; argv++; // avoid "warning: unused parameter"
+
+    pop_t Pop;
+
+    spin_t muts[] = {3,0,5};
+    mutset_t s(muts,muts+3);
+    /*
+    mutset_t s;
+    for (int i = 0; i < 3; ++i)
+        s.insert(muts[i]);
+    */
+
+    Pop[s] = 100;
+    Pop[s] += 50;
+
+    std::cout << *Pop.begin()->first.begin() << ' ' << Pop.begin()->second << std::endl;
+
+    return 0;
+}
+