MCPcopy Create free account
hub / github.com/devosoft/avida / Divide_Main

Method Divide_Main

avida-core/source/cpu/cHardwareCPU.cc:1775–1843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1773
1774
1775bool cHardwareCPU::Divide_Main(cAvidaContext& ctx, const int div_point,
1776 const int extra_lines, double mut_multiplier)
1777{
1778 const int child_size = m_memory.GetSize() - div_point - extra_lines;
1779
1780 // Make sure this divide will produce a viable offspring.
1781 const bool viable = Divide_CheckViable(ctx, div_point, child_size);
1782 if (viable == false) return false;
1783
1784 // Since the divide will now succeed, set up the information to be sent
1785 // to the new organism
1786 InstructionSequencePtr offspring_seq(new InstructionSequence(m_memory.Crop(div_point, div_point + child_size)));
1787 HashPropertyMap props;
1788 cHardwareManager::SetupPropertyMap(props, (const char*)m_inst_set->GetInstSetName());
1789 Genome offspring(GetType(), props, offspring_seq);
1790
1791 // Make sure it is an exact copy at this point (before divide mutations) if required
1792 const Genome& base_genome = m_organism->GetGenome();
1793 ConstInstructionSequencePtr seq_p;
1794 seq_p.DynamicCastFrom(base_genome.Representation());
1795 const InstructionSequence& seq = *seq_p;
1796 if (m_world->GetConfig().REQUIRE_EXACT_COPY.Get() && (seq != *offspring_seq) ) {
1797 return false;
1798 }
1799
1800 m_organism->OffspringGenome() = offspring;
1801
1802 // Cut off everything in this memory past the divide point.
1803 m_memory.Resize(div_point);
1804
1805 // Handle Divide Mutations...
1806 Divide_DoMutations(ctx, mut_multiplier);
1807
1808 // Many tests will require us to run the offspring through a test CPU;
1809 // this is, for example, to see if mutations need to be reverted or if
1810 // lineages need to be updated.
1811 Divide_TestFitnessMeasures1(ctx);
1812
1813 if (m_world->GetConfig().DIVIDE_METHOD.Get() != DIVIDE_METHOD_OFFSPRING) {
1814 // reset first time instruction costs
1815 for (int i = 0; i < m_inst_ft_cost.GetSize(); i++) {
1816 m_inst_ft_cost[i] = m_inst_set->GetFTCost(Instruction(i));
1817 }
1818 }
1819
1820 m_mal_active = false;
1821 if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
1822 m_advance_ip = false;
1823 }
1824
1825 // Activate the child
1826 bool parent_alive = m_organism->ActivateDivide(ctx);
1827
1828 // Do more work if the parent lives through the birth of the offspring
1829 if (parent_alive) {
1830
1831 if ( (m_world->GetConfig().EPIGENETIC_METHOD.Get() == EPIGENETIC_METHOD_PARENT)
1832 || (m_world->GetConfig().EPIGENETIC_METHOD.Get() == EPIGENETIC_METHOD_BOTH) ) {

Callers

nothing calls this directly

Calls 11

CropMethod · 0.80
RepresentationMethod · 0.80
GetConfigMethod · 0.80
OffspringGenomeMethod · 0.80
GetFTCostMethod · 0.80
ActivateDivideMethod · 0.80
ClearFlagsMethod · 0.80
InstructionClass · 0.50
GetSizeMethod · 0.45
GetMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected