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

Method Divide_Main

avida-core/source/cpu/cHardwareExperimental.cc:1547–1597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1545}
1546
1547bool cHardwareExperimental::Divide_Main(cAvidaContext& ctx, const int div_point, const int extra_lines, double mut_multiplier)
1548{
1549 const int child_size = m_memory.GetSize() - div_point - extra_lines;
1550
1551 // Make sure this divide will produce a viable offspring.
1552 const bool viable = Divide_CheckViable(ctx, div_point, child_size);
1553 if (viable == false) return false;
1554
1555 // Since the divide will now succeed, set up the information to be sent
1556 // to the new organism
1557 InstructionSequencePtr offspring_seq(new InstructionSequence(m_memory.Crop(div_point, div_point + child_size)));
1558 HashPropertyMap props;
1559 cHardwareManager::SetupPropertyMap(props, (const char*)m_inst_set->GetInstSetName());
1560 Genome offspring(GetType(), props, offspring_seq);
1561
1562 m_organism->OffspringGenome() = offspring;
1563
1564 // Cut off everything in this memory past the divide point.
1565 m_memory.Resize(div_point);
1566
1567 // Handle Divide Mutations...
1568 Divide_DoMutations(ctx, mut_multiplier);
1569
1570 // Many tests will require us to run the offspring through a test CPU;
1571 // this is, for example, to see if mutations need to be reverted or if
1572 // lineages need to be updated.
1573 Divide_TestFitnessMeasures(ctx);
1574
1575 // reset first time instruction costs
1576 for (int i = 0; i < m_inst_ft_cost.GetSize(); i++) {
1577 m_inst_ft_cost[i] = m_inst_set->GetFTCost(Instruction(i));
1578 }
1579
1580 m_mal_active = false;
1581 if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
1582 m_advance_ip = false;
1583 }
1584
1585 // Activate the child
1586 bool parent_alive = m_organism->ActivateDivide(ctx);
1587
1588 // Do more work if the parent lives through the birth of the offspring
1589 if (parent_alive) {
1590 if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
1591
1592 // Clear instruction flags on successful divide
1593 m_memory.ClearFlags();
1594 }
1595
1596 return true;
1597}
1598
1599void cHardwareExperimental::checkWaitingThreads(int cur_thread, int reg_num)
1600{

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected