1 /*
2 * cGenomeTestMetrics.cc
3 * Avida
4 *
5 * Created by David Bryson on 8/13/10.
6 * Copyright 2010-2011 Michigan State University. All rights reserved.
7 *
8 *
9 * This file is part of Avida.
10 *
11 * Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
13 *
14 * Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License along with Avida.
18 * If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 #include "cGenomeTestMetrics.h"
23
24 #include "avida/core/Genome.h"
25
26 #include "cAvidaContext.h"
27 #include "cBioGroup.h"
28 #include "cHardwareManager.h"
29 #include "cPhenotype.h"
30 #include "cTestCPU.h"
31 #include "cWorld.h"
32 #include "tAutoRelease.h"
33
34 using namespace Avida;
35
36
cGenomeTestMetrics(cAvidaContext & ctx,cBioGroup * bg)37 cGenomeTestMetrics::cGenomeTestMetrics(cAvidaContext& ctx, cBioGroup* bg)
38 {
39 tAutoRelease<cTestCPU> testcpu(ctx.GetWorld()->GetHardwareManager().CreateTestCPU(ctx));
40
41 cCPUTestInfo test_info;
42 testcpu->TestGenome(ctx, test_info, Genome(bg->GetProperty("genome").AsString()));
43
44 m_is_viable = test_info.IsViable();
45
46 cPhenotype& phenotype = test_info.GetTestPhenotype();
47 m_fitness = test_info.GetGenotypeFitness();
48 m_colony_fitness = test_info.GetColonyFitness();
49 m_merit = phenotype.GetMerit().GetDouble();
50 m_executed_size = phenotype.GetExecutedSize();
51 m_copied_size = phenotype.GetCopiedSize();
52 m_gestation_time = phenotype.GetGestationTime();
53 }
54
55
56
GetMetrics(cAvidaContext & ctx,cBioGroup * bg)57 cGenomeTestMetrics* cGenomeTestMetrics::GetMetrics(cAvidaContext& ctx, cBioGroup* bg)
58 {
59 cGenomeTestMetrics* metrics = bg->GetData<cGenomeTestMetrics>();
60 if (!metrics && bg->HasProperty("genome")) {
61 metrics = new cGenomeTestMetrics(ctx, bg);
62 assert(metrics);
63 bg->AttachData(metrics);
64 }
65
66 return metrics;
67 }
68