1 /*
2  *  cBirthEntry.cc
3  *  Avida
4  *
5  *  Copyright 1999-2011 Michigan State University. All rights reserved.
6  *  Copyright 1993-2003 California Institute of Technology.
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 "cBirthEntry.h"
23 #include "cString.h"
24 #include "cStringUtil.h"
25 #include "cOrganism.h"
26 #include "cPhenotype.h"
27 
cBirthEntry()28 cBirthEntry::cBirthEntry()
29 : m_mating_type(MATING_TYPE_JUVENILE)
30 , m_mating_display_a(0)
31 , m_mating_display_b(0)
32 , m_mate_preference(MATE_PREFERENCE_RANDOM)
33 , m_group_id(-1)
34 , timestamp(-1)
35 {
36 }
37 
38 //This instructor is intended to be use to create a temporary birth entry from a parent that is
39 // about to divide sexually, just for record-keeping purposes; the birth entry should then be
40 // immediately destroyed
cBirthEntry(const Genome & _offspring,cOrganism * _parent,int _timestamp)41 cBirthEntry::cBirthEntry(const Genome& _offspring, cOrganism* _parent, int _timestamp)
42 : m_mating_type(_parent->GetPhenotype().GetMatingType())
43 , m_mating_display_a(_parent->GetPhenotype().GetLastMatingDisplayA())
44 , m_mating_display_b(_parent->GetPhenotype().GetLastMatingDisplayB())
45 , m_mate_preference(_parent->GetPhenotype().GetMatePreference())
46 , m_group_id(-1)
47 , genome(_offspring)
48 , merit(_parent->GetPhenotype().GetMerit())
49 , timestamp(_timestamp)
50 {
51   // Note: Not checking for energy because we don't want to clear out the parent's energy
52   // for a temporary birth entry, otherwise things may get screwed up when the REAL offspring
53   // is created
54 
55   // Similarly, I'm not setting the biogroups here because I don't want to add references to them,
56   // since this birth entry is going to be destroyed anyway
57   if (_parent->HasOpinion()) {
58     m_group_id = _parent->GetOpinion().first;
59   }
60 }
61 
62 //Returns a string representation of a birth entry's information (primarily used for print actions
63 // that output information about the offspring in the birth chamber)
GetPhenotypeString()64 cString cBirthEntry::GetPhenotypeString()
65 {
66   //genome
67   //timestamp
68   //merit
69   //mating_type
70   //mate_preference
71   //mating_display_a
72   //mating_display_b
73   //group
74   cString result;
75 
76   result = genome.GetSequence().AsString();
77   result += " "; result += cStringUtil::Convert(timestamp);
78   result += " "; result += cStringUtil::Convert(merit.GetDouble());
79   result += " "; result += cStringUtil::Convert(m_mating_type);
80   result += " "; result += cStringUtil::Convert(m_mate_preference);
81   result += " "; result += cStringUtil::Convert(m_mating_display_a);
82   result += " "; result += cStringUtil::Convert(m_mating_display_b);
83   result += " "; result += cStringUtil::Convert(m_group_id);
84 
85   return result;
86 }
87 
88 //Companion function for GetPhenotypeString() that tells what information is contained in each field
GetPhenotypeStringFormat()89 cString cBirthEntry::GetPhenotypeStringFormat()
90 {
91   return "genome timestamp merit mating_type mate_preference mating_display_a mating_display_b group";
92 }
93 
operator =(const cBirthEntry & _birth_entry)94 cBirthEntry& cBirthEntry::operator=(const cBirthEntry& _birth_entry)
95 {
96   m_mating_type = _birth_entry.m_mating_type;
97   m_mating_display_a = _birth_entry.m_mating_display_a;
98   m_mating_display_b = _birth_entry.m_mating_display_b;
99   m_parent_task_count = _birth_entry.m_parent_task_count;
100   m_mate_preference = _birth_entry.m_mate_preference;
101   m_group_id = _birth_entry.m_group_id;
102 
103   genome = _birth_entry.genome;
104   energy4Offspring = _birth_entry.energy4Offspring;
105   merit = _birth_entry.merit;
106   timestamp = _birth_entry.timestamp;
107   groups = _birth_entry.groups;
108 
109   return *this;
110 }
111