Skip to content

Commit e28e4dc

Browse files
committed
Add set random seed action
1 parent 3a38d1a commit e28e4dc

File tree

16 files changed

+1388
-0
lines changed

16 files changed

+1388
-0
lines changed

avida-core/source/actions/DriverActions.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,36 @@ class cActionExitDemeResources : public cAction {
250250
};
251251

252252

253+
class cActionSetRandomSeed : public cAction {
254+
public:
255+
/*! Constructor; parse out the number of replications.
256+
*/
257+
cActionSetRandomSeed(cWorld* world, const cString& args, Feedback&) : cAction(world, args) {
258+
cString largs(args);
259+
if (largs.GetSize()) {
260+
m_random_seed = largs.PopWord().AsInt();
261+
} else {
262+
m_world->GetDriver().Feedback().Error("SetRandomSeed event requires an integer seed.");
263+
m_world->GetDriver().Abort(Avida::INVALID_CONFIG);
264+
}
265+
}
266+
267+
static const cString GetDescription() { return "Arguments: <int rng seed>"; }
268+
269+
void Process(cAvidaContext& ctx) {
270+
// copied from void Avida::Viewer::Driver::SetRandomSeed
271+
m_world->GetConfig().RANDOM_SEED.Set(m_random_seed);
272+
m_world->GetRandom().ResetSeed(m_random_seed);
273+
274+
// When resetting the random seed, the timeslicer also needs to be rebuilt, since it may use the RNG
275+
// Resizing the cell grid triggers the reconstruction of the timeslicer, so...
276+
m_world->GetPopulation().ResizeCellGrid(m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get());
277+
}
278+
279+
protected:
280+
int m_random_seed; //!< Number of deme resources after which Avida should exit.
281+
};
282+
253283

254284
void RegisterDriverActions(cActionLibrary* action_lib)
255285
{
@@ -261,4 +291,5 @@ void RegisterDriverActions(cActionLibrary* action_lib)
261291
action_lib->Register<cActionExitDemeReplications>("ExitDemeReplications");
262292
action_lib->Register<cActionExitDemeResources>("ExitDemeResources");
263293
action_lib->Register<cActionPause>("Pause");
294+
action_lib->Register<cActionSetRandomSeed>("SetRandomSeed");
264295
}

avida-core/tests/set_random_seed/config/avida.cfg

Lines changed: 688 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#for analyze mode, uncomment this line
2+
#RESOURCE resECHO:initial=10000000:inflow=40:outflow=0.10
3+
RESOURCE resECHO:inflow=40:outflow=0.10
4+
5+
#REACTION ECHO echo process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=ECHO
6+
7+
REACTION NOT
8+
REACTION NAND
9+
REACTION AND
10+
REACTION ORN
11+
REACTION OR
12+
REACTION ANDN
13+
REACTION NOR
14+
REACTION XOR
15+
REACTION EQU
16+
17+
REACTION NOT not process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
18+
REACTION NAND nand process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
19+
REACTION AND and process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
20+
REACTION ORN orn process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
21+
REACTION OR or process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
22+
REACTION ANDN andn process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
23+
REACTION NOR nor process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
24+
REACTION XOR xor process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
25+
REACTION EQU equ process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=EQU:noreaction=XOR:noreaction=NOR:noreaction=ANDN:noreaction=OR:noreaction=ORN:noreaction=AND:noreaction=NAND:noreaction=NOT
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
##############################################################################
2+
#
3+
# This is the setup file for the events system. From here, you can
4+
# configure any actions that you want to have happen during the course of
5+
# an experiment, including setting the times for data collection.
6+
#
7+
# basic syntax: [trigger] [start:interval:stop] [action/event] [arguments...]
8+
#
9+
# This file is currently setup to record key information every 100 updates.
10+
#
11+
# For information on how to use this file, see: doc/events.html
12+
# For other sample event configurations, see: support/config/
13+
#
14+
##############################################################################
15+
16+
# Seed the population with a single organism
17+
u begin SetRandomSeed 42
18+
u begin Inject evolved-not.org
19+
20+
u 800 PrintParasiteData parasites1a.dat
21+
u 800 InjectParasite parasite-smt.org ABB 0 400
22+
23+
u 1000 PrintParasiteData parasites1b.dat
24+
u 1000 DumpParasiteGenotypeGrid parasites1.grid
25+
26+
u 1000 KillProb 1.0
27+
28+
u 1000 SetRandomSeed 42
29+
u 1000 Inject evolved-not.org
30+
31+
u 1800 PrintParasiteData parasites2a.dat
32+
u 1800 InjectParasite parasite-smt.org ABB 0 400
33+
34+
u 2000 PrintParasiteData parasites2b.dat
35+
u 2000 DumpParasiteGenotypeGrid parasites2.grid
36+
37+
u 2000 SetRandomSeed 52
38+
u 2001 PrintParasiteData parasites3.dat
39+
u 2002 Exit

0 commit comments

Comments
 (0)