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

Method Divide_MainRS

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

Almost the same as Divide_Main, but resamples reverted offspring. RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTATIONS OCCUR ON DIVIDE!! AWC - 06/29/06 */

Source from the content-addressed store, hash-verified

1850 AWC - 06/29/06
1851 */
1852bool cHardwareCPU::Divide_MainRS(cAvidaContext& ctx, const int div_point,
1853 const int extra_lines, double mut_multiplier)
1854{
1855
1856 //cStats stats = m_world->GetStats();
1857 const int child_size = m_memory.GetSize() - div_point - extra_lines;
1858
1859 // Make sure this divide will produce a viable offspring.
1860 const bool viable = Divide_CheckViable(ctx, div_point, child_size);
1861 if (viable == false) return false;
1862
1863 // Since the divide will now succeed, set up the information to be sent
1864 // to the new organism
1865 InstructionSequencePtr offspring_seq(new InstructionSequence(m_memory.Crop(div_point, div_point + child_size)));
1866 HashPropertyMap props;
1867 cHardwareManager::SetupPropertyMap(props, (const char*)m_inst_set->GetInstSetName());
1868 Genome offspring(GetType(), props, offspring_seq);
1869
1870 m_organism->OffspringGenome() = offspring;
1871
1872 // Cut off everything in this memory past the divide point.
1873 m_memory.Resize(div_point);
1874
1875 unsigned
1876 totalMutations = 0,
1877 mutations = 0;
1878 //RScount = 0;
1879
1880
1881 bool
1882 fitTest = false;
1883
1884 // Handle Divide Mutations...
1885 /*
1886 Do mutations until one of these conditions are satisified:
1887 we have resampled X times
1888 we have an offspring with the same number of muations as the first offspring
1889 that is not reverted
1890 the parent is steralized (usually means an implicit mutation)
1891 */
1892 for (unsigned i = 0; i <= 100; i++) {
1893 if (i == 0) {
1894 mutations = totalMutations = Divide_DoMutations(ctx, mut_multiplier);
1895 }
1896 else{
1897 mutations = Divide_DoMutations(ctx, mut_multiplier);
1898 m_world->GetStats().IncResamplings();
1899 }
1900
1901 fitTest = Divide_TestFitnessMeasures1(ctx);
1902
1903 if (!fitTest && mutations >= totalMutations) break;
1904
1905 }
1906 // think about making this mutations == totalMuations - though this may be too hard...
1907 /*
1908 if (RScount > 2)
1909 cerr << "Resampled " << RScount << endl;

Callers

nothing calls this directly

Calls 14

CropMethod · 0.80
OffspringGenomeMethod · 0.80
IncResamplingsMethod · 0.80
ChildFertileMethod · 0.80
IncFailedResamplingsMethod · 0.80
GetConfigMethod · 0.80
GetFTCostMethod · 0.80
ActivateDivideMethod · 0.80
ClearFlagsMethod · 0.80
InstructionClass · 0.50
GetSizeMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected