[Avida-SVN] r3313 - development/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Wed Jun 10 20:29:58 PDT 2009
Author: hjg
Date: 2009-06-10 23:29:57 -0400 (Wed, 10 Jun 2009)
New Revision: 3313
Modified:
development/source/main/cTaskLib.cc
development/source/main/cTaskLib.h
Log:
Added an additional task to enable the formation of dynamic groups with a designated id.
Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc 2009-06-10 21:31:36 UTC (rev 3312)
+++ development/source/main/cTaskLib.cc 2009-06-11 03:29:57 UTC (rev 3313)
@@ -440,6 +440,9 @@
if (name == "form-group")
Load_FormSpatialGroup(name, info, envreqs, errors);
+
+ if (name == "form-group-id")
+ Load_FormSpatialGroupWithID(name, info, envreqs, errors);
// Make sure we have actually found a task
if (task_array.GetSize() == start_size) {
@@ -3421,3 +3424,50 @@
return reward;
}
+
+/* Reward organisms for having a given group-id, provided the group is under the
+ max number of members.*/
+void cTaskLib::Load_FormSpatialGroupWithID(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
+{
+ cArgSchema schema;
+
+ // Integer Arguments
+ schema.AddEntry("group_size", 0, 1);
+ schema.AddEntry("group_id", 1, 1);
+
+ cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
+ if (args) NewTask(name, "FormSpatialGroupWithID", &cTaskLib::Task_FormSpatialGroupWithID, 0, args);
+}
+
+double cTaskLib::Task_FormSpatialGroupWithID(cTaskContext& ctx) const
+{
+ double t = (double) ctx.GetTaskEntry()->GetArguments().GetInt(0);
+ int des_group_id = (double) ctx.GetTaskEntry()->GetArguments().GetInt(1);
+
+ double reward = 0.0;
+ int group_id = -1;
+ if (ctx.GetOrganism()->HasOpinion()) {
+ group_id = ctx.GetOrganism()->GetOpinion().first;
+ }
+
+ // If the organism is in the group...
+ if (group_id == des_group_id) {
+ double g = (double) m_world->GetPopulation().NumberOfOrganismsInGroup(group_id);
+ // If the population size is less than the max size
+ if (g < t) {
+ reward = 1;
+ } else {
+
+ double num = (t-g) * (t-g);
+ double denom = (t*t);
+
+ reward = 1 - (num/denom);
+ if (reward < 0) reward = 0;
+
+ }
+
+ }
+
+ return reward;
+}
+
Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h 2009-06-10 21:31:36 UTC (rev 3312)
+++ development/source/main/cTaskLib.h 2009-06-11 03:29:57 UTC (rev 3313)
@@ -321,6 +321,8 @@
// group formation
void Load_FormSpatialGroup(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
double Task_FormSpatialGroup(cTaskContext& ctx) const;
+ void Load_FormSpatialGroupWithID(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
+ double Task_FormSpatialGroupWithID(cTaskContext& ctx) const;
};
More information about the Avida-cvs
mailing list