30 cerr <<
"usage: -P <wave pool> -S <seed> <ancestorlist>" << endl;
31 cerr <<
"[-F <number of fixed waves (first N waves in list)> default: 1 ]" << endl;
32 cerr <<
"[-E <number of waves to exchange> default: 5 ]" << endl;
33 cerr <<
"[-D <number of waves to drop> ]" << endl;
34 cerr <<
"[-A <number of waves to add> ]" << endl;
35 cerr <<
"[-V <range of number of waves to vay> ]" << endl;
36 cerr <<
"[-p 1 < selective pressure < 2, default: 1.5 ]" << endl;
37 cerr <<
"[-c 0 < crossover probability < 1 default> 0.75 ]" << endl;
38 cerr << progname << endl;
50 main(
int argc,
char** argv){
54 vector<TString> inputlistFiles;
55 vector<double> fitness;
70 unsigned int optcount=1;
71 while ((c = getopt(argc, argv,
"hE:A:V:D:P:F:S:c:p:")) != -1){
123 TString ancestorList(argv[optcount]);
124 ifstream ancfile(ancestorList.Data());
125 while(!ancfile.eof()){
128 ancfile >> ancestor >> fitn;
129 ancfile.ignore(200,
'\n');
130 if(ancestor.Length()<1 || fitn==0)
continue;
132 inputlistFiles.push_back(ancestor);
133 fitness.push_back(fitn);
137 if(inputlistFiles.size()<1){
138 cerr <<
"No ancestor wavelists given. Exiting." << endl;
142 cerr << inputlistFiles.size() <<
" ancestors." << endl;
145 TString inputlistFile=inputlistFiles[0];
149 cerr <<
"Seed =" << seed << endl;
150 gRandom->SetSeed(
time(NULL)+seed);
154 vector<set<wsetentry>*> ancestorlist;
155 unsigned int na=inputlistFiles.size();
156 unsigned int mingenes=1000;
158 for(
unsigned int ia=0;ia<na;++ia){
159 ancestorlist.push_back(
new set<wsetentry>());
161 unsigned int n=ancestorlist[ia]->size();
169 cerr <<
"Ancestor has not enough genes to fix "
170 <<Fix<<
". Fixing all" << endl;
182 TH1I hDist(
"hDist",
"hDist",na,0,na-1);
187 for(
unsigned int ia=0;ia<na;++ia){
189 double rank=(double)(na-ia)-1.;
190 double npop=(double)na;
192 double p=1./npop*(2.-sel+2.*(sel-1)*rank/npopa);
194 hDist.Fill(ia,p*npop);
198 unsigned int x1=(
unsigned int)hDist.GetRandom();
199 unsigned int x2=(
unsigned int)hDist.GetRandom();
201 assert(x1>=0 && x1<na);
202 assert(x2>=0 && x2<na);
204 cerr <<
"Selective Pressure: " << sel << endl;
205 cerr <<
"Choosing ancestors: " << x1 <<
" and " << x2 << endl;
207 set<wsetentry>* ancestor1=ancestorlist[x1];
208 set<wsetentry>* ancestor2=ancestorlist[x2];
217 cerr <<
"Crossover probability: "<< pc << endl;
220 set<wsetentry> motherlist;
221 copy(ancestor1->begin(),ancestor1->end(),inserter(motherlist,motherlist.begin()));
223 if(gRandom->Uniform()<pc){
225 cerr <<
" crossing over ... ";
227 set<wsetentry>* smallancestor=NULL;
230 if(ancestor1->size()<=ancestor2->size()){
231 smallancestor = ancestor1;
235 smallancestor = ancestor2;
241 unsigned int cp1=gRandom->Integer(smallancestor->size()-Fix)+Fix;
242 unsigned int cp2=gRandom->Integer(smallancestor->size()-Fix)+Fix;
244 unsigned int cpp1 = cp1;
245 unsigned int cpp2 = cp2;
251 cerr <<
" [" << cpp1 <<
"..." << cpp2 <<
"]" << endl;
253 set<wsetentry>::iterator ita1=motherlist.begin();
254 set<wsetentry>::iterator ita2=ancestor2->begin();
255 for(
unsigned int ip=0; ip<cpp1; ++ip){
260 for(
unsigned int ip=cpp1; ip<cpp2; ++ip){
262 if(
findByName(motherlist,gene)==motherlist.end()){
263 cerr <<
"crossing gene " << ip <<
": "
264 << gene.
name << endl;
265 motherlist.erase(*ita1);
266 motherlist.insert(gene);
267 ita1=find(motherlist.begin(),motherlist.end(),gene);
277 set<wsetentry> wavepool;
281 unsigned int nwaves=motherlist.size();
284 set<wsetentry> redpool;
286 set<wsetentry>::iterator it1=wavepool.begin();
287 while(it1!=wavepool.end()){
288 if(find(motherlist.begin(),motherlist.end(),*it1)==motherlist.end()){
289 redpool.insert(*it1);
295 unsigned int npool=redpool.size();
296 cerr << wavepool.size() <<
" waves in pool." << endl;
297 cerr << nwaves <<
" waves in ancestor." << endl;
298 cerr << npool <<
" waves in reduced pool." << endl;
300 set<wsetentry> mutantlist(motherlist);
302 cerr <<
"Add =" << Add << endl;
303 cerr <<
"Drop=" << Drop << endl;
304 cerr <<
"Exch=" << Exch << endl;
308 int v= gRandom->Integer(2*Vary)-Vary;
309 cerr <<
"Var ="<<v<< endl;
321 cerr <<
"Add =" << Add << endl;
322 cerr <<
"Drop=" << Drop << endl;
324 unsigned int exchangable=mutantlist.size()-Fix;
325 if(Exch+Drop>exchangable){
326 Drop=exchangable-Exch;
327 cerr <<
"Adjusting drop to maximal value "<<Drop<<endl;
331 for(
unsigned int ie=0;ie<Exch+Drop;++ie){
336 cerr <<
"removed " << Exch+Drop <<
" waves" << endl;
339 for(
unsigned int ie=0;ie<Exch+Add;++ie){
342 anentry.
index=nwaves+ie;
343 mutantlist.insert(anentry);
347 cerr <<
"added " << Exch+Add <<
" waves" << endl;
350 set<wsetentry>::iterator it=mutantlist.begin();
352 while(it!=mutantlist.end()){
354 set<wsetentry>::iterator it2=it;
356 if(find(it2,mutantlist.end(),*it)!=mutantlist.end()){
357 cerr <<
"Double entry " << it->name << endl;
362 if((it->threshold)!=0) cout <<
" " << it->threshold;
367 cerr << count <<
" waves in mutant." << endl;