[avida-cvs] avida CVS commits: /current/source/main analyze.cc analyze.hh environment.cc environment.hh reaction.cc reaction.hh
mercere99
avida-cvs at alife.org
Wed Oct 15 20:57:25 PDT 2003
mercere99 Wed Oct 15 12:57:25 2003 EDT
Modified files:
/avida/current/source/main analyze.cc analyze.hh environment.cc
environment.hh reaction.cc reaction.hh
Log:
Setup environment file with an extra command
SET_ACTIVE <type> <name> <active=true>
Type can currently only be "reaction" (but soon I'll also get resources
working, and eventually mutations). Name is the name of the resource,
and fitnally a true or false if you want that reaction turned on.
THEN I also added a command to the analyze mode called "ENVIRONMENT"
which will allow you to add extra commands to define the environment
file on the fly. For example, the analyze command:
ENVIRONMENT SET_ACTIVE reaction NOT false
Will turn off rewards for not. They can be turned back on again
trivially with:
ENVIRONMENT SET_ACTIVE reaction NOT true
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.79 avida/current/source/main/analyze.cc:1.80
--- avida/current/source/main/analyze.cc:1.79 Tue Oct 14 15:35:00 2003
+++ avida/current/source/main/analyze.cc Wed Oct 15 12:57:24 2003
@@ -3436,6 +3436,16 @@
return;
}
+
+void cAnalyze::EnvironmentSetup(cString cur_string)
+{
+ cout << "Running environment command: " << endl
+ << " " << cur_string << endl;
+
+ cTestCPU::GetEnvironment()->LoadLine(cur_string);
+}
+
+
void cAnalyze::CommandHelpfile(cString cur_string)
{
cout << "Printing helpfiles in: " << cur_string << endl;
@@ -4403,6 +4413,9 @@
AddLibraryDef("ANALYZE_BRANCHING", &cAnalyze::AnalyzeBranching);
AddLibraryDef("ANALYZE_MUTATION_TRACEBACK",
&cAnalyze::AnalyzeMutationTraceback);
+
+ // Environment manipulation
+ AddLibraryDef("ENVIRONMENT", &cAnalyze::EnvironmentSetup);
// Documantation...
AddLibraryDef("HELPFILE", &cAnalyze::CommandHelpfile);
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.46 avida/current/source/main/analyze.hh:1.47
--- avida/current/source/main/analyze.hh:1.46 Mon Oct 13 10:34:26 2003
+++ avida/current/source/main/analyze.hh Wed Oct 15 12:57:25 2003
@@ -471,6 +471,9 @@
void AnalyzeComplexity(cString cur_string);
void AnalyzePopComplexity(cString cur_string);
+ // Environment Manipulation
+ void EnvironmentSetup(cString cur_string);
+
// Documentation...
void CommandHelpfile(cString cur_string);
void CommandDocfile(cString cur_string);
Index: avida/current/source/main/environment.cc
diff -u avida/current/source/main/environment.cc:1.16 avida/current/source/main/environment.cc:1.17
--- avida/current/source/main/environment.cc:1.16 Tue Jul 15 09:40:48 2003
+++ avida/current/source/main/environment.cc Wed Oct 15 12:57:25 2003
@@ -551,6 +551,60 @@
return true;
}
+bool cEnvironment::LoadSetActive(cString desc)
+{
+ cString item_type = desc.PopWord();
+ item_type.ToUpper();
+
+ cString item_name = desc.PopWord();
+
+ cString item_active = desc.PopWord();
+ item_active.ToUpper();
+
+ bool new_active = true;
+ if (item_active == "0" || item_active == "FALSE") new_active = false;
+
+ if (item_type == "REACTION") {
+ cReaction * cur_reaction = reaction_lib.GetReaction(item_name);
+ if (cur_reaction == NULL) {
+ cerr << "Unknown REACTION: '" << item_name << "'" << endl;
+ return false;
+ }
+ cur_reaction->SetActive(new_active);
+ } else if (item_type == "") {
+ cerr << "Format: SET_ACTIVE <type> <name> <new_status=true>" << endl;
+ } else {
+ cerr << "Error: Cannot deactivate items of type "
+ << item_type << endl;
+ return false;
+ }
+
+ return true;
+}
+
+bool cEnvironment::LoadLine(cString line)
+{
+ cString type = line.PopWord(); // Determine type of this entry.
+ type.ToUpper(); // Make type case insensitive.
+
+ bool load_ok = true;
+ if (type == "RESOURCE") load_ok = LoadResource(line);
+ else if (type == "REACTION") load_ok = LoadReaction(line);
+ else if (type == "MUTATION") load_ok = LoadMutation(line);
+ else if (type == "SET_ACTIVE") load_ok = LoadSetActive(line);
+ else {
+ cerr << "Error: Unknown environment keyword '" << type << "." << endl;
+ return false;
+ }
+
+ if (load_ok == false) {
+ cerr << "...failed in loading '" << type << "'..." << endl;
+ return false;
+ }
+
+ return true;
+}
+
bool cEnvironment::Load(const cString & filename)
{
cerr << "ENV: Loading file '" << filename << "'." << endl;
@@ -568,23 +622,9 @@
// cerr << "ENV: found " << infile.GetNumLines() << " commands." << endl;
for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
- cString line = infile.GetLine(line_id); // Load next line from file.
- cString type = line.PopWord(); // Determine type of this entry.
- type.ToUpper(); // Make type case insensitive.
-
- bool load_ok = true;
- if (type == "RESOURCE") load_ok = LoadResource(line);
- else if (type == "REACTION") load_ok = LoadReaction(line);
- else if (type == "MUTATION") load_ok = LoadMutation(line);
- else {
- cerr << "Error: Unknown environment keyword '" << type << "." << endl;
- return false;
- }
-
- if (load_ok == false) {
- cerr << "...failed in loading '" << type << "'..." << endl;
- return false;
- }
+ // Load the next line from the file.
+ bool load_ok = LoadLine(infile.GetLine(line_id));
+ if (load_ok == false) return false;
}
// Make sure that all pre-declared reactions have been loaded correctly.
@@ -642,6 +682,9 @@
for (int i = 0; i < num_reactions; i++) {
cReaction * cur_reaction = reaction_lib.GetReaction(i);
assert(cur_reaction != NULL);
+
+ // Only use active reactions...
+ if (cur_reaction->GetActive() == false) continue;
// Examine the task trigger associated with this reaction
cTaskEntry * cur_task = cur_reaction->GetTask();
Index: avida/current/source/main/environment.hh
diff -u avida/current/source/main/environment.hh:1.10 avida/current/source/main/environment.hh:1.11
--- avida/current/source/main/environment.hh:1.10 Wed Jun 18 17:41:59 2003
+++ avida/current/source/main/environment.hh Wed Oct 15 12:57:25 2003
@@ -46,6 +46,8 @@
bool LoadReaction(cString desc);
bool LoadMutation(cString desc);
+ bool LoadSetActive(cString desc);
+
bool TestRequisites(const tList<cReactionRequisite> & req_list,
int task_count,
const tArray<int> & reaction_count) const;
@@ -62,6 +64,11 @@
* Reads the environment from disk.
**/
bool Load(const cString & filename);
+
+ /**
+ * Reads in a single environment configuration line
+ **/
+ bool LoadLine(cString line);
// Interaction with the organisms
void SetupInputs( tArray<int> & input_array ) const;
Index: avida/current/source/main/reaction.cc
diff -u avida/current/source/main/reaction.cc:1.6 avida/current/source/main/reaction.cc:1.7
--- avida/current/source/main/reaction.cc:1.6 Wed Jun 18 17:41:59 2003
+++ avida/current/source/main/reaction.cc Wed Oct 15 12:57:25 2003
@@ -62,6 +62,7 @@
: name(_name)
, id(_id)
, task(NULL)
+ , active(true)
{
}
Index: avida/current/source/main/reaction.hh
diff -u avida/current/source/main/reaction.hh:1.5 avida/current/source/main/reaction.hh:1.6
--- avida/current/source/main/reaction.hh:1.5 Tue Jun 24 14:55:49 2003
+++ avida/current/source/main/reaction.hh Wed Oct 15 12:57:25 2003
@@ -100,6 +100,7 @@
cTaskEntry * task;
tList<cReactionProcess> process_list;
tList<cReactionRequisite> requisite_list;
+ bool active;
public:
cReaction(const cString & _name, int _id);
~cReaction();
@@ -110,10 +111,12 @@
const tList<cReactionProcess> & GetProcesses() { return process_list; }
const tList<cReactionRequisite> & GetRequisites()
{ return requisite_list; }
+ bool GetActive() const { return active; }
void SetTask(cTaskEntry * _task) { task = _task; }
cReactionProcess * AddProcess();
cReactionRequisite * AddRequisite();
+ void SetActive(bool in_active=true) { active = in_active; }
};
class cReactionLib {
More information about the Avida-cvs
mailing list