JEB: Creates specified number of offspring by running each organism in the test CPU with mutations on.
| 1602 | // JEB: Creates specified number of offspring by running |
| 1603 | // each organism in the test CPU with mutations on. |
| 1604 | void cAnalyze::SampleOffspring(cString cur_string) |
| 1605 | { |
| 1606 | int number_to_sample = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : 1000; |
| 1607 | |
| 1608 | // These parameters copied from BatchRecalculate, they could change what kinds of offspring are produced!! |
| 1609 | Apto::Array<int> manual_inputs; // Used only if manual inputs are specified |
| 1610 | cString msg; // Holds any information we may want to send the driver to display |
| 1611 | int use_resources = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : 0; |
| 1612 | int update = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : -1; |
| 1613 | bool use_random_inputs = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() == 1: false; |
| 1614 | bool use_manual_inputs = false; |
| 1615 | |
| 1616 | //Manual inputs will override random input request and must be the last arguments. |
| 1617 | if (cur_string.CountNumWords() > 0){ |
| 1618 | if (cur_string.CountNumWords() == m_world->GetEnvironment().GetInputSize()){ |
| 1619 | manual_inputs.Resize(m_world->GetEnvironment().GetInputSize()); |
| 1620 | use_random_inputs = false; |
| 1621 | use_manual_inputs = true; |
| 1622 | for (int k = 0; cur_string.GetSize(); k++) |
| 1623 | manual_inputs[k] = cur_string.PopWord().AsInt(); |
| 1624 | } else if (m_world->GetVerbosity() >= VERBOSE_ON) { |
| 1625 | cerr << "warning: Invalid number of environment inputs requested for recalculation: " << cur_string.CountNumWords() |
| 1626 | << " specified, " << m_world->GetEnvironment().GetInputSize() << " required." << endl; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | cCPUTestInfo test_info(1); //we only allow one generation of testing! v. important to get proper offspring |
| 1631 | if (use_manual_inputs) |
| 1632 | test_info.UseManualInputs(manual_inputs); |
| 1633 | else |
| 1634 | test_info.UseRandomInputs(use_random_inputs); |
| 1635 | test_info.SetResourceOptions(use_resources, m_resources, update, m_resource_time_spent_offset); |
| 1636 | |
| 1637 | if (m_world->GetVerbosity() >= VERBOSE_ON) { |
| 1638 | msg.Set("Sampling %d offspring from each of the %d organisms in batch %d...", number_to_sample, batch[cur_batch].GetSize(), cur_batch); |
| 1639 | cout << msg << endl; |
| 1640 | } else{ |
| 1641 | msg.Set("Sampling offspring..."); |
| 1642 | cout << msg << endl; |
| 1643 | } |
| 1644 | |
| 1645 | // Load the mutation rates from the environment. |
| 1646 | test_info.MutationRates().Copy(m_world->GetEnvironment().GetMutRates()); |
| 1647 | // Copy them into the organism |
| 1648 | tListPlus<cAnalyzeGenotype> offspring_list; |
| 1649 | tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List()); |
| 1650 | cAnalyzeGenotype* parent_genotype = NULL; |
| 1651 | |
| 1652 | cTestCPU * test_cpu = m_world->GetHardwareManager().CreateTestCPU(m_ctx); |
| 1653 | while ((parent_genotype = batch_it.Next())) { |
| 1654 | |
| 1655 | // We keep a hash with genome strings as keys |
| 1656 | // to save duplication of the same offspring genotype. |
| 1657 | // NumCPUs is incremented whenever an offspring is |
| 1658 | // created more than once from the same parent. |
| 1659 | Apto::Map<Apto::String, cAnalyzeGenotype*> genome_hash; |
| 1660 | |
| 1661 | for (int i=0; i<number_to_sample; i++) { |
nothing calls this directly
no test coverage detected