Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set random seed action #92

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions avida-core/source/actions/DriverActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,36 @@ class cActionExitDemeResources : public cAction {
};


class cActionSetRandomSeed : public cAction {
public:
/*! Constructor; parse out the number of replications.
*/
cActionSetRandomSeed(cWorld* world, const cString& args, Feedback&) : cAction(world, args) {
cString largs(args);
if (largs.GetSize()) {
m_random_seed = largs.PopWord().AsInt();
} else {
m_world->GetDriver().Feedback().Error("SetRandomSeed event requires an integer seed.");
m_world->GetDriver().Abort(Avida::INVALID_CONFIG);
}
}

static const cString GetDescription() { return "Arguments: <int rng seed>"; }

void Process(cAvidaContext& ctx) {
// copied from void Avida::Viewer::Driver::SetRandomSeed
m_world->GetConfig().RANDOM_SEED.Set(m_random_seed);
m_world->GetRandom().ResetSeed(m_random_seed);

// When resetting the random seed, the timeslicer also needs to be rebuilt, since it may use the RNG
// Resizing the cell grid triggers the reconstruction of the timeslicer, so...
m_world->GetPopulation().ResizeCellGrid(m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get());
}

protected:
int m_random_seed; //!< Number of deme resources after which Avida should exit.
};


void RegisterDriverActions(cActionLibrary* action_lib)
{
Expand All @@ -261,4 +291,5 @@ void RegisterDriverActions(cActionLibrary* action_lib)
action_lib->Register<cActionExitDemeReplications>("ExitDemeReplications");
action_lib->Register<cActionExitDemeResources>("ExitDemeResources");
action_lib->Register<cActionPause>("Pause");
action_lib->Register<cActionSetRandomSeed>("SetRandomSeed");
}
688 changes: 688 additions & 0 deletions avida-core/tests/set_random_seed/config/avida.cfg

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions avida-core/tests/set_random_seed/config/environment.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#for analyze mode, uncomment this line
#RESOURCE resECHO:initial=10000000:inflow=40:outflow=0.10
RESOURCE resECHO:inflow=40:outflow=0.10

#REACTION ECHO echo process:resource=resECHO:value=0.0:type=pow:frac=0.5:min=1:max=1: requisite:noreaction=ECHO

REACTION NOT
REACTION NAND
REACTION AND
REACTION ORN
REACTION OR
REACTION ANDN
REACTION NOR
REACTION XOR
REACTION EQU

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
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
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
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
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
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
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
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
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
39 changes: 39 additions & 0 deletions avida-core/tests/set_random_seed/config/events.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##############################################################################
#
# This is the setup file for the events system. From here, you can
# configure any actions that you want to have happen during the course of
# an experiment, including setting the times for data collection.
#
# basic syntax: [trigger] [start:interval:stop] [action/event] [arguments...]
#
# This file is currently setup to record key information every 100 updates.
#
# For information on how to use this file, see: doc/events.html
# For other sample event configurations, see: support/config/
#
##############################################################################

# Seed the population with a single organism
u begin SetRandomSeed 42
u begin Inject evolved-not.org

u 800 PrintParasiteData parasites1a.dat
u 800 InjectParasite parasite-smt.org ABB 0 400

u 1000 PrintParasiteData parasites1b.dat
u 1000 DumpParasiteGenotypeGrid parasites1.grid

u 1000 KillProb 1.0

u 1000 SetRandomSeed 42
u 1000 Inject evolved-not.org

u 1800 PrintParasiteData parasites2a.dat
u 1800 InjectParasite parasite-smt.org ABB 0 400

u 2000 PrintParasiteData parasites2b.dat
u 2000 DumpParasiteGenotypeGrid parasites2.grid

u 2000 SetRandomSeed 52
u 2001 PrintParasiteData parasites3.dat
u 2002 Exit
Loading
Loading