[Avida-SVN] r1764 - development/source/main
goingssh at myxo.css.msu.edu
goingssh at myxo.css.msu.edu
Mon Jul 9 08:37:04 PDT 2007
Author: goingssh
Date: 2007-07-09 11:37:04 -0400 (Mon, 09 Jul 2007)
New Revision: 1764
Modified:
development/source/main/cEnvironment.cc
development/source/main/cPopulation.cc
development/source/main/cTaskLib.cc
Log:
added range resources
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2007-07-09 03:00:58 UTC (rev 1763)
+++ development/source/main/cEnvironment.cc 2007-07-09 15:37:04 UTC (rev 1764)
@@ -759,7 +759,7 @@
if (random) {
if (m_true_rand) {
for (int i = 0; i < m_input_size; i++) {
- input_array[i] = ctx.GetRandom().GetUInt(1 << 31);
+ input_array[i] = ctx.GetRandom().GetUInt((unsigned int) 1 << 31);
}
} else {
// Set the top 8 bits of the input buffer...
@@ -826,6 +826,7 @@
}
const double task_quality = m_tasklib.TestOutput(taskctx);
+ assert(task_quality >= 0.0);
// If this task wasn't performed, move on to the next one.
@@ -928,8 +929,11 @@
// Otherwise we're using a finite resource
const int res_id = in_resource->GetID();
+ assert(resource_count[res_id] >= 0);
+ assert(result.GetConsumed(res_id) >= 0);
consumed = resource_count[res_id] - result.GetConsumed(res_id);
consumed *= cur_process->GetMaxFraction();
+ assert(consumed >= 0.0);
// Make sure we're not above the maximum consumption.
if (consumed > max_consumed) consumed = max_consumed;
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-07-09 03:00:58 UTC (rev 1763)
+++ development/source/main/cPopulation.cc 2007-07-09 15:37:04 UTC (rev 1764)
@@ -1633,21 +1633,18 @@
{
assert(step_size > 0.0);
assert(cell_id < cell_array.GetSize());
-
// If cell_id is negative, no cell could be found -- stop here.
if (cell_id < 0) return;
-
cPopulationCell& cell = GetCell(cell_id);
assert(cell.IsOccupied()); // Unoccupied cell getting processor time!
-
cOrganism* cur_org = cell.GetOrganism();
cur_org->GetHardware().SingleProcess(ctx);
if (cur_org->GetPhenotype().GetToDelete() == true) {
delete cur_org;
}
- m_world->GetStats().IncExecuted();
- resource_count.Update(step_size);
-}
+ m_world->GetStats().IncExecuted();
+ resource_count.Update(step_size);
+ }
void cPopulation::UpdateOrganismStats()
Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc 2007-07-09 03:00:58 UTC (rev 1763)
+++ development/source/main/cTaskLib.cc 2007-07-09 15:37:04 UTC (rev 1764)
@@ -2127,8 +2127,9 @@
schema.AddEntry("basepow", 0, 2.0);
schema.AddEntry("maxFx", 1, 1.0);
schema.AddEntry("minFx", 2, 0.0);
+ schema.AddEntry("thresh", 3, -1.0);
+ schema.AddEntry("threshMax", 4, -1.0);
-
cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
if (args)
{
@@ -2181,9 +2182,17 @@
x = tempX / tot;
y = tempY / tot;
} else {
- x = abs(double(ctx.GetOutputBuffer()[0]) / 0xffffffff);
- y = abs(double(ctx.GetOutputBuffer()[1]) / 0xffffffff);
+ x = double(ctx.GetOutputBuffer()[0]) / 0xffffffff;
+ y = double(ctx.GetOutputBuffer()[1]) / 0xffffffff;
}
+ if (x < 0)
+ x = 0;
+ else if (x > 1)
+ x = 1;
+ if (y < 0)
+ y = 0;
+ else if (y > 1)
+ y = 1;
switch(function) {
case 1:
@@ -2226,8 +2235,35 @@
quality = .001;
}
ctx.SetTaskValue(Fx);
- quality = (args.GetDouble(1) - Fx+.001) / (args.GetDouble(1) - args.GetDouble(2)+.001);
-
+ if (args.GetDouble(3) < 0.0)
+ {
+ double q1 = (args.GetDouble(1) - Fx+.001);
+ double q2 = (args.GetDouble(1) - args.GetDouble(2)+.001);
+ assert(q1 > 0.0);
+ assert(q2 > 0.0);
+ quality = q1 / q2;
+ } else {
+ if (args.GetDouble(4) < 0.0)
+ {
+ if (Fx <= (args.GetDouble(1) - args.GetDouble(2))*args.GetDouble(3) + args.GetDouble(2))
+ {
+ quality = 1.0;
+ }
+ else
+ {
+ quality = 0.0;
+ }
+ }
+ else
+ {
+ if ( (Fx >= (args.GetDouble(1) - args.GetDouble(2))*args.GetDouble(3) + args.GetDouble(2))
+ && (Fx <= (args.GetDouble(1) - args.GetDouble(2))*args.GetDouble(4) + args.GetDouble(2)) )
+ quality = 1.0;
+ else
+ quality = 0.0;
+ }
+ }
+
// because want org to only have 1 shot to use outputs for all functions at once, even if they
// output numbers that give a quality of 0 on a function, still want to mark it as completed
// so give it a very low quality instead of 0 (if using limited resources they still will get
@@ -2235,14 +2271,11 @@
// possible fraction they'll be below minimum allowed consumed and will consume nothing
if (quality > 1)
- cout << "\n\nquality > 1!\n\n";
+ cout << "\n\nquality > 1! quality= " << quality << " Fx= " << Fx << endl;
- if (quality < .001)
- return .001;
- else
- return quality;
+ if (quality < 0.001) return .001;
- return 0;
+ return quality;
}
void cTaskLib::Load_Mult(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
More information about the Avida-cvs
mailing list