[Avida-cvs] [Avida2-svn] r358 - in branches/brysonda/source: cpu event main tools
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sat Oct 22 21:09:39 PDT 2005
Author: brysonda
Date: 2005-10-23 00:09:39 -0400 (Sun, 23 Oct 2005)
New Revision: 358
Modified:
branches/brysonda/source/cpu/cHardware4Stack.cc
branches/brysonda/source/cpu/cHardwareCPU.cc
branches/brysonda/source/cpu/cHardwareManager.cc
branches/brysonda/source/cpu/cHardwareManager.h
branches/brysonda/source/cpu/cHardwareSMT.cc
branches/brysonda/source/event/cEventManager.cc
branches/brysonda/source/main/cAnalyze.cc
branches/brysonda/source/main/cAnalyzeUtil.cc
branches/brysonda/source/main/cBirthChamber.cc
branches/brysonda/source/main/cEnvironment.cc
branches/brysonda/source/main/cEnvironment.h
branches/brysonda/source/main/cGenotype.cc
branches/brysonda/source/main/cInjectGenotype.cc
branches/brysonda/source/main/cInstSet.cc
branches/brysonda/source/main/cInstSet.h
branches/brysonda/source/main/cLandscape.cc
branches/brysonda/source/main/cMutationRates.cc
branches/brysonda/source/main/cMutationRates.h
branches/brysonda/source/main/cMxCodeArray.cc
branches/brysonda/source/main/cOrganism.cc
branches/brysonda/source/main/cPhenotype.cc
branches/brysonda/source/main/cPopulation.cc
branches/brysonda/source/main/cPopulationCell.cc
branches/brysonda/source/main/cPopulationCell.h
branches/brysonda/source/main/cWorld.cc
branches/brysonda/source/tools/cProbSchedule.cc
branches/brysonda/source/tools/cProbSchedule.h
branches/brysonda/source/tools/cTools.cc
branches/brysonda/source/tools/cTools.h
Log:
Remove the global random number generator. cWorld now holds the RNG accessed by most things.
Modified: branches/brysonda/source/cpu/cHardware4Stack.cc
===================================================================
--- branches/brysonda/source/cpu/cHardware4Stack.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/cpu/cHardware4Stack.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -403,7 +403,7 @@
// Prob of exec
if ( GetInstSet().GetProbFail(cur_inst) > 0.0 ){
- return !( g_random.P(GetInstSet().GetProbFail(cur_inst)) );
+ return !( m_world->GetRandom().P(GetInstSet().GetProbFail(cur_inst)) );
}
#endif
return true;
@@ -888,7 +888,7 @@
//************* CALL GOES HERE ******************//
// spin around randomly (caution: possible organism dizziness)
//const int num_neighbors = organism->GetNeighborhoodSize();
- //for(unsigned int i=0; i<g_random.GetUInt(num_neighbors); i++)
+ //for(unsigned int i=0; i<m_world->GetRandom().GetUInt(num_neighbors); i++)
// organism->Rotate(1);
// If we don't have a host, stop here.
@@ -998,10 +998,10 @@
int cHardware4Stack::PointMutate(const double mut_rate)
{
const int num_muts =
- g_random.GetRandBinomial(GetMemory(0).GetSize(), mut_rate);
+ m_world->GetRandom().GetRandBinomial(GetMemory(0).GetSize(), mut_rate);
for (int i = 0; i < num_muts; i++) {
- const int pos = g_random.GetUInt(GetMemory(0).GetSize());
+ const int pos = m_world->GetRandom().GetUInt(GetMemory(0).GetSize());
Mutate(pos);
}
@@ -1081,11 +1081,11 @@
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
cHeadMultiMem tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
}
@@ -1098,7 +1098,7 @@
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
TriggerMutations_Body(cur_mut->GetType(), target_memory, cur_head);
return true;
}
@@ -1113,12 +1113,12 @@
// that should occur.
const int num_mut =
- g_random.GetRandBinomial(target_memory.GetSize(), rate);
+ m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
cHeadMultiMem tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
}
@@ -1405,21 +1405,21 @@
// Divide Mutations
if (organism->TestDivideMut()) {
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[mut_line] = GetRandomInst();
cpu_stats.mut_stats.divide_mut_count++;
}
// Divide Insertions
if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize() + 1);
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
child_genome.Insert(mut_line, GetRandomInst());
cpu_stats.mut_stats.divide_insert_mut_count++;
}
// Divide Deletions
if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if( child_genome.FlagCopied(mut_line) == true) copied_size_change--;
child_genome.Remove(mut_line);
cpu_stats.mut_stats.divide_delete_mut_count++;
@@ -1427,12 +1427,12 @@
// Divide Mutations (per site)
if(organism->GetDivMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDivMutProb() / mut_multiplier);
// If we have lines to mutate...
if( num_mut > 0 ){
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[site]=GetRandomInst();
cpu_stats.mut_stats.div_mut_count++;
}
@@ -1442,7 +1442,7 @@
// Insert Mutations (per site)
if(organism->GetInsMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetInsMutProb());
// If would make creature to big, insert up to MAX_CREATURE_SIZE
if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1453,7 +1453,7 @@
// Build a list of the sites where mutations occured
static int mut_sites[MAX_CREATURE_SIZE];
for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = g_random.GetUInt(child_genome.GetSize() + 1);
+ mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
}
// Sort the list
qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1468,7 +1468,7 @@
// Delete Mutations (per site)
if( organism->GetDelMutProb() > 0 ){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDelMutProb());
// If would make creature too small, delete down to MIN_CREATURE_SIZE
if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1477,7 +1477,7 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if (child_genome.FlagCopied(site) == true) copied_size_change--;
child_genome.Remove(site);
cpu_stats.mut_stats.delete_mut_count++;
@@ -1517,21 +1517,21 @@
// Divide Mutations
if (organism->TestDivideMut()) {
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code[mut_line] = GetRandomInst();
//cpu_stats.mut_stats.divide_mut_count++;
}
// Divide Insertions
if (organism->TestDivideIns() && injected_code.GetSize() < MAX_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize() + 1);
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
injected_code.Insert(mut_line, GetRandomInst());
//cpu_stats.mut_stats.divide_insert_mut_count++;
}
// Divide Deletions
if (organism->TestDivideDel() && injected_code.GetSize() > MIN_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
// if( injected_code.FlagCopied(mut_line) == true) copied_size_change--;
injected_code.Remove(mut_line);
//cpu_stats.mut_stats.divide_delete_mut_count++;
@@ -1539,12 +1539,12 @@
// Divide Mutations (per site)
if(organism->GetDivMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetDivMutProb() / mut_multiplier);
// If we have lines to mutate...
if( num_mut > 0 ){
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(injected_code.GetSize());
+ int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code[site]=GetRandomInst();
//cpu_stats.mut_stats.div_mut_count++;
}
@@ -1554,7 +1554,7 @@
// Insert Mutations (per site)
if(organism->GetInsMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetInsMutProb());
// If would make creature to big, insert up to MAX_CREATURE_SIZE
if( num_mut + injected_code.GetSize() > MAX_CREATURE_SIZE ){
@@ -1565,7 +1565,7 @@
// Build a list of the sites where mutations occured
static int mut_sites[MAX_CREATURE_SIZE];
for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = g_random.GetUInt(injected_code.GetSize() + 1);
+ mut_sites[i] = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
}
// Sort the list
qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1580,7 +1580,7 @@
// Delete Mutations (per site)
if( organism->GetDelMutProb() > 0 ){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetDelMutProb());
// If would make creature too small, delete down to MIN_CREATURE_SIZE
if (injected_code.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1589,7 +1589,7 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(injected_code.GetSize());
+ int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
// if (injected_code.FlagCopied(site) == true) copied_size_change--;
injected_code.Remove(site);
//cpu_stats.mut_stats.delete_mut_count++;
@@ -1656,17 +1656,17 @@
if (child_fitness == 0.0) {
// Fatal mutation... test for reversion.
- if (g_random.P(organism->GetRevertFatal())) revert = true;
- if (g_random.P(organism->GetSterilizeFatal())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
} else if (child_fitness < neut_min) {
- if (g_random.P(organism->GetRevertNeg())) revert = true;
- if (g_random.P(organism->GetSterilizeNeg())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
} else if (child_fitness <= neut_max) {
- if (g_random.P(organism->GetRevertNeut())) revert = true;
- if (g_random.P(organism->GetSterilizeNeut())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
} else {
- if (g_random.P(organism->GetRevertPos())) revert = true;
- if (g_random.P(organism->GetSterilizePos())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
}
// Ideally, we won't have reversions and sterilizations turned on at the
@@ -2266,7 +2266,7 @@
{
// Rotate to a random facing and then run the normal inject instruction
const int num_neighbors = organism->GetNeighborhoodSize();
- organism->Rotate(g_random.GetUInt(num_neighbors));
+ organism->Rotate(m_world->GetRandom().GetUInt(num_neighbors));
Inst_Inject();
return true;
}
Modified: branches/brysonda/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/brysonda/source/cpu/cHardwareCPU.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/cpu/cHardwareCPU.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -519,7 +519,7 @@
// Prob of exec
if ( GetInstSet().GetProbFail(cur_inst) > 0.0 ){
- return !( g_random.P(GetInstSet().GetProbFail(cur_inst)) );
+ return !( m_world->GetRandom().P(GetInstSet().GetProbFail(cur_inst)) );
}
#endif
return true;
@@ -1070,10 +1070,10 @@
int cHardwareCPU::PointMutate(const double mut_rate)
{
const int num_muts =
- g_random.GetRandBinomial(GetMemory().GetSize(), mut_rate);
+ m_world->GetRandom().GetRandBinomial(GetMemory().GetSize(), mut_rate);
for (int i = 0; i < num_muts; i++) {
- const int pos = g_random.GetUInt(GetMemory().GetSize());
+ const int pos = m_world->GetRandom().GetUInt(GetMemory().GetSize());
Mutate(pos);
}
@@ -1153,11 +1153,11 @@
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
cHeadCPU tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
}
@@ -1170,7 +1170,7 @@
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
TriggerMutations_Body(cur_mut->GetType(), target_memory, cur_head);
return true;
}
@@ -1185,12 +1185,12 @@
// that should occur.
const int num_mut =
- g_random.GetRandBinomial(target_memory.GetSize(), rate);
+ m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
cHeadCPU tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
}
@@ -1575,11 +1575,11 @@
bool sterilize = false;
if (fitness_ratio < nHardware::FITNESS_NEUTRAL_MIN) {
- if (g_random.P(organism->GetSterilizeNeg())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
} else if (fitness_ratio <= nHardware::FITNESS_NEUTRAL_MAX) {
- if (g_random.P(organism->GetSterilizeNeut())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
} else {
- if (g_random.P(organism->GetSterilizePos())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
}
// cout << "[ min(" << genome_size
@@ -1610,21 +1610,21 @@
// Divide Mutations
if (organism->TestDivideMut()) {
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[mut_line] = GetRandomInst();
cpu_stats.mut_stats.divide_mut_count++;
}
// Divide Insertions
if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize() + 1);
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
child_genome.Insert(mut_line, GetRandomInst());
cpu_stats.mut_stats.divide_insert_mut_count++;
}
// Divide Deletions
if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if( child_genome.FlagCopied(mut_line) == true) copied_size_change--;
child_genome.Remove(mut_line);
cpu_stats.mut_stats.divide_delete_mut_count++;
@@ -1632,12 +1632,12 @@
// Divide Mutations (per site)
if(organism->GetDivMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDivMutProb() / mut_multiplier);
// If we have lines to mutate...
if( num_mut > 0 ){
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[site]=GetRandomInst();
cpu_stats.mut_stats.div_mut_count++;
}
@@ -1647,7 +1647,7 @@
// Insert Mutations (per site)
if(organism->GetInsMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetInsMutProb());
// If would make creature to big, insert up to MAX_CREATURE_SIZE
if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1658,7 +1658,7 @@
// Build a list of the sites where mutations occured
static int mut_sites[MAX_CREATURE_SIZE];
for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = g_random.GetUInt(child_genome.GetSize() + 1);
+ mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
}
// Sort the list
qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1673,7 +1673,7 @@
// Delete Mutations (per site)
if( organism->GetDelMutProb() > 0 ){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDelMutProb());
// If would make creature too small, delete down to MIN_CREATURE_SIZE
if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1682,7 +1682,7 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if (child_genome.FlagCopied(site) == true) copied_size_change--;
child_genome.Remove(site);
cpu_stats.mut_stats.delete_mut_count++;
@@ -1749,17 +1749,17 @@
if (child_fitness == 0.0) {
// Fatal mutation... test for reversion.
- if (g_random.P(organism->GetRevertFatal())) revert = true;
- if (g_random.P(organism->GetSterilizeFatal())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
} else if (child_fitness < neut_min) {
- if (g_random.P(organism->GetRevertNeg())) revert = true;
- if (g_random.P(organism->GetSterilizeNeg())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
} else if (child_fitness <= neut_max) {
- if (g_random.P(organism->GetRevertNeut())) revert = true;
- if (g_random.P(organism->GetSterilizeNeut())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
} else {
- if (g_random.P(organism->GetRevertPos())) revert = true;
- if (g_random.P(organism->GetSterilizePos())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
}
// Ideally, we won't have reversions and sterilizations turned on at the
@@ -2635,7 +2635,7 @@
bool cHardwareCPU::Inst_Die()
{
const double die_prob = m_world->GetConfig().DIE_PROB.Get();
- if(g_random.GetDouble() < die_prob) { organism->Die(); }
+ if(m_world->GetRandom().GetDouble() < die_prob) { organism->Die(); }
return true;
}
@@ -2701,7 +2701,7 @@
{
// Rotate to a random facing and then run the normal inject instruction
const int num_neighbors = organism->GetNeighborhoodSize();
- organism->Rotate(g_random.GetUInt(num_neighbors));
+ organism->Rotate(m_world->GetRandom().GetUInt(num_neighbors));
Inst_Inject();
return true;
}
@@ -2876,7 +2876,7 @@
}
// Turn to a random neighbor, get it, and turn back...
- int neighbor_id = g_random.GetInt(organism->GetNeighborhoodSize());
+ int neighbor_id = m_world->GetRandom().GetInt(organism->GetNeighborhoodSize());
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
@@ -2899,7 +2899,7 @@
const int num_neighbors = organism->GetNeighborhoodSize();
// Turn to face a random neighbor
- int neighbor_id = g_random.GetInt(num_neighbors);
+ int neighbor_id = m_world->GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
@@ -2942,7 +2942,7 @@
const int num_neighbors = organism->GetNeighborhoodSize();
// Turn to face a random neighbor
- int neighbor_id = g_random.GetInt(num_neighbors);
+ int neighbor_id = m_world->GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
@@ -3368,7 +3368,7 @@
// Do mutations.
cInstruction read_inst = read_head.GetInst();
ReadInst(read_inst.GetOp());
- if ( g_random.P(organism->GetCopyMutProb() / reduction) ) {
+ if ( m_world->GetRandom().P(organism->GetCopyMutProb() / reduction) ) {
read_inst = GetRandomInst();
cpu_stats.mut_stats.copy_mut_count++;
write_head.FlagMutated() = true;
Modified: branches/brysonda/source/cpu/cHardwareManager.cc
===================================================================
--- branches/brysonda/source/cpu/cHardwareManager.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/cpu/cHardwareManager.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -18,7 +18,7 @@
#include "cWorld.h"
#include "tDictionary.h"
-cHardwareManager::cHardwareManager(cWorld* world) : m_world(world), m_type(world->GetConfig().HARDWARE_TYPE.Get())
+cHardwareManager::cHardwareManager(cWorld* world) : m_world(world), m_inst_set(world), m_type(world->GetConfig().HARDWARE_TYPE.Get())
{
LoadInstSet(world->GetConfig().INST_SET.Get());
}
Modified: branches/brysonda/source/cpu/cHardwareManager.h
===================================================================
--- branches/brysonda/source/cpu/cHardwareManager.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/cpu/cHardwareManager.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -21,9 +21,6 @@
class cHardwareManager
{
private:
- cHardwareManager() { ; }
-
-protected:
cWorld* m_world;
cInstSet m_inst_set;
int m_type;
Modified: branches/brysonda/source/cpu/cHardwareSMT.cc
===================================================================
--- branches/brysonda/source/cpu/cHardwareSMT.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/cpu/cHardwareSMT.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -247,7 +247,7 @@
// Prob of exec
if ( GetInstSet().GetProbFail(cur_inst) > 0.0 ){
- return !( g_random.P(GetInstSet().GetProbFail(cur_inst)) );
+ return !( m_world->GetRandom().P(GetInstSet().GetProbFail(cur_inst)) );
}
#endif
return true;
@@ -712,7 +712,7 @@
//************* CALL GOES HERE ******************//
// spin around randomly (caution: possible organism dizziness)
//const int num_neighbors = organism->GetNeighborhoodSize();
- //for(unsigned int i=0; i<g_random.GetUInt(num_neighbors); i++)
+ //for(unsigned int i=0; i<m_world->GetRandom().GetUInt(num_neighbors); i++)
// organism->Rotate(1);
// If we don't have a host, stop here.
@@ -819,10 +819,10 @@
int cHardwareSMT::PointMutate(const double mut_rate)
{
- const int num_muts = g_random.GetRandBinomial(m_mem_array[0].GetSize(), mut_rate);
+ const int num_muts = m_world->GetRandom().GetRandBinomial(m_mem_array[0].GetSize(), mut_rate);
for (int i = 0; i < num_muts; i++) {
- const int pos = g_random.GetUInt(m_mem_array[0].GetSize());
+ const int pos = m_world->GetRandom().GetUInt(m_mem_array[0].GetSize());
Mutate(pos);
}
@@ -902,11 +902,11 @@
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
cHeadMultiMem tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
}
@@ -919,7 +919,7 @@
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
- if (g_random.P(rate) == true) {
+ if (m_world->GetRandom().P(rate) == true) {
TriggerMutations_Body(cur_mut->GetType(), target_memory, cur_head);
return true;
}
@@ -934,12 +934,12 @@
// that should occur.
const int num_mut =
- g_random.GetRandBinomial(target_memory.GetSize(), rate);
+ m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
cHeadMultiMem tmp_head(cur_head);
- tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
+ tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
}
@@ -1277,21 +1277,21 @@
// Divide Mutations
if (organism->TestDivideMut()) {
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[mut_line] = GetRandomInst();
cpu_stats.mut_stats.divide_mut_count++;
}
// Divide Insertions
if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize() + 1);
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
child_genome.Insert(mut_line, GetRandomInst());
cpu_stats.mut_stats.divide_insert_mut_count++;
}
// Divide Deletions
if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(child_genome.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if( child_genome.FlagCopied(mut_line) == true) copied_size_change--;
child_genome.Remove(mut_line);
cpu_stats.mut_stats.divide_delete_mut_count++;
@@ -1299,12 +1299,12 @@
// Divide Mutations (per site)
if(organism->GetDivMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDivMutProb() / mut_multiplier);
// If we have lines to mutate...
if( num_mut > 0 ){
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
child_genome[site]=GetRandomInst();
cpu_stats.mut_stats.div_mut_count++;
}
@@ -1314,7 +1314,7 @@
// Insert Mutations (per site)
if(organism->GetInsMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetInsMutProb());
// If would make creature to big, insert up to MAX_CREATURE_SIZE
if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1325,7 +1325,7 @@
// Build a list of the sites where mutations occured
static int mut_sites[MAX_CREATURE_SIZE];
for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = g_random.GetUInt(child_genome.GetSize() + 1);
+ mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
}
// Sort the list
qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1340,7 +1340,7 @@
// Delete Mutations (per site)
if( organism->GetDelMutProb() > 0 ){
- int num_mut = g_random.GetRandBinomial(child_genome.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
organism->GetDelMutProb());
// If would make creature too small, delete down to MIN_CREATURE_SIZE
if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1349,7 +1349,7 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(child_genome.GetSize());
+ int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
// if (child_genome.FlagCopied(site) == true) copied_size_change--;
child_genome.Remove(site);
cpu_stats.mut_stats.delete_mut_count++;
@@ -1386,30 +1386,30 @@
// Divide Mutations
if (organism->TestDivideMut()) {
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code[mut_line] = GetRandomInst();
}
// Divide Insertions
if (organism->TestDivideIns() && injected_code.GetSize() < MAX_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize() + 1);
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
injected_code.Insert(mut_line, GetRandomInst());
}
// Divide Deletions
if (organism->TestDivideDel() && injected_code.GetSize() > MIN_CREATURE_SIZE){
- const UINT mut_line = g_random.GetUInt(injected_code.GetSize());
+ const UINT mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code.Remove(mut_line);
}
// Divide Mutations (per site)
if(organism->GetDivMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetDivMutProb() / mut_multiplier);
// If we have lines to mutate...
if( num_mut > 0 ){
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(injected_code.GetSize());
+ int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code[site]=GetRandomInst();
}
}
@@ -1418,7 +1418,7 @@
// Insert Mutations (per site)
if(organism->GetInsMutProb() > 0){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetInsMutProb());
// If would make creature to big, insert up to MAX_CREATURE_SIZE
if( num_mut + injected_code.GetSize() > MAX_CREATURE_SIZE ){
@@ -1429,7 +1429,7 @@
// Build a list of the sites where mutations occured
static int mut_sites[MAX_CREATURE_SIZE];
for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = g_random.GetUInt(injected_code.GetSize() + 1);
+ mut_sites[i] = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
}
// Sort the list
qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1443,7 +1443,7 @@
// Delete Mutations (per site)
if( organism->GetDelMutProb() > 0 ){
- int num_mut = g_random.GetRandBinomial(injected_code.GetSize(),
+ int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
organism->GetDelMutProb());
// If would make creature too small, delete down to MIN_CREATURE_SIZE
if (injected_code.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1452,7 +1452,7 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- int site = g_random.GetUInt(injected_code.GetSize());
+ int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
injected_code.Remove(site);
}
}
@@ -1504,17 +1504,17 @@
if (child_fitness == 0.0) {
// Fatal mutation... test for reversion.
- if (g_random.P(organism->GetRevertFatal())) revert = true;
- if (g_random.P(organism->GetSterilizeFatal())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
} else if (child_fitness < neut_min) {
- if (g_random.P(organism->GetRevertNeg())) revert = true;
- if (g_random.P(organism->GetSterilizeNeg())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
} else if (child_fitness <= neut_max) {
- if (g_random.P(organism->GetRevertNeut())) revert = true;
- if (g_random.P(organism->GetSterilizeNeut())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
} else {
- if (g_random.P(organism->GetRevertPos())) revert = true;
- if (g_random.P(organism->GetSterilizePos())) sterilize = true;
+ if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
+ if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
}
// Ideally, we won't have reversions and sterilizations turned on at the
Modified: branches/brysonda/source/event/cEventManager.cc
===================================================================
--- branches/brysonda/source/event/cEventManager.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/event/cEventManager.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -1866,7 +1866,7 @@
}
///// inject_random /////
void Process(){
- if (cell_id == -1) cell_id = g_random.GetUInt(m_world->GetPopulation().GetSize());
+ if (cell_id == -1) cell_id = m_world->GetRandom().GetUInt(m_world->GetPopulation().GetSize());
cGenome genome =
cInstUtil::RandomGenome(length, m_world->GetHardwareManager().GetInstSet());
m_world->GetPopulation().Inject(genome, cell_id, merit, lineage_label, neutral_metric);
@@ -2719,7 +2719,7 @@
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(i);
if (cell.IsOccupied() == false) continue;
- if (g_random.P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
+ if (m_world->GetRandom().P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
}
}
};
@@ -2841,7 +2841,7 @@
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(i);
if (cell.IsOccupied() == false) continue;
- if (g_random.P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
+ if (m_world->GetRandom().P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
}
}
};
Modified: branches/brysonda/source/main/cAnalyze.cc
===================================================================
--- branches/brysonda/source/main/cAnalyze.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cAnalyze.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -3372,8 +3372,8 @@
// performing a random cross test.
cAnalyzeGenotype * genotype2 = NULL;
for (int test_id = 0; test_id < sample_size; test_id++) {
- genotype = genotype_array[ g_random.GetUInt(org_count) ];
- genotype2 = genotype_array[ g_random.GetUInt(org_count) ];
+ genotype = genotype_array[ m_world->GetRandom().GetUInt(org_count) ];
+ genotype2 = genotype_array[ m_world->GetRandom().GetUInt(org_count) ];
// Stop immediately if we're comparing a genotype to itself.
if (genotype == genotype2) {
@@ -3389,8 +3389,8 @@
double end_frac = -1.0;
double swap_frac = -1.0;
while (swap_frac < min_swap_frac || swap_frac > max_swap_frac) {
- start_frac = g_random.GetDouble();
- end_frac = g_random.GetDouble();
+ start_frac = m_world->GetRandom().GetDouble();
+ end_frac = m_world->GetRandom().GetDouble();
if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
swap_frac = end_frac - start_frac;
}
@@ -4677,8 +4677,8 @@
cCPUMemory test_genome0 = genotype1->GetGenome();
cCPUMemory test_genome1 = genotype2->GetGenome();
- double start_frac = g_random.GetDouble();
- double end_frac = g_random.GetDouble();
+ double start_frac = m_world->GetRandom().GetDouble();
+ double end_frac = m_world->GetRandom().GetDouble();
if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
int start0 = (int) (start_frac * (double) test_genome0.GetSize());
@@ -4782,8 +4782,8 @@
cCPUMemory test_genome0 = genotype1->GetGenome();
cCPUMemory test_genome1 = genotype2->GetGenome();
- double start_frac = g_random.GetDouble();
- double end_frac = g_random.GetDouble();
+ double start_frac = m_world->GetRandom().GetDouble();
+ double end_frac = m_world->GetRandom().GetDouble();
if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
int start0 = (int) (start_frac * (double) test_genome0.GetSize());
Modified: branches/brysonda/source/main/cAnalyzeUtil.cc
===================================================================
--- branches/brysonda/source/main/cAnalyzeUtil.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cAnalyzeUtil.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -70,12 +70,12 @@
// Should check to only insert infront of an instruction (not a Nop)
int ins_pos = -1;
while (ins_pos < 0) {
- ins_pos = g_random.GetUInt(genome.GetSize());
+ ins_pos = world->GetRandom().GetUInt(genome.GetSize());
if( inst_set.IsNop(genome[ins_pos]) ) ins_pos = -1;
}
// Insert some "instruction_none" into the genome
- const int num_nops = g_random.GetUInt(5) + 5;
+ const int num_nops = world->GetRandom().GetUInt(5) + 5;
for (int j = 0; j < num_nops; j++) genome.Insert(ins_pos, inst_none);
// Test the genome and output stats
@@ -385,7 +385,7 @@
const double skip_prob = 1.0 - sample_prob;
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue; // No organism...
- if (g_random.P(skip_prob)) continue; // Not sampled...
+ if (world->GetRandom().P(skip_prob)) continue; // Not sampled...
cOrganism * organism = pop->GetCell(i).GetOrganism();
cGenotype * genotype = organism->GetGenotype();
Modified: branches/brysonda/source/main/cBirthChamber.cc
===================================================================
--- branches/brysonda/source/main/cBirthChamber.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cBirthChamber.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -59,7 +59,7 @@
{
bool done = false;
while (done ==false) {
- int test_neighbor = (int) g_random.GetUInt(9);
+ int test_neighbor = (int) m_world->GetRandom().GetUInt(9);
int i = test_neighbor / 3 - 1;
int j = test_neighbor % 3 - 1;
int test_loc = GridNeighbor(parent_id,world_x, world_y, i, j);
@@ -324,8 +324,8 @@
cCPUMemory & genome1,
double & merit0, double & merit1)
{
- double start_frac = g_random.GetDouble();
- double end_frac = g_random.GetDouble();
+ double start_frac = m_world->GetRandom().GetDouble();
+ double end_frac = m_world->GetRandom().GetDouble();
if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
// calculate the proportion of the genome that will be swapped
@@ -357,8 +357,8 @@
{
const int num_modules = m_world->GetConfig().MODULE_NUM.Get();
- int start_module = (int) (g_random.GetDouble() * num_modules);
- int end_module = (int) (g_random.GetDouble() * num_modules);
+ int start_module = (int) (m_world->GetRandom().GetDouble() * num_modules);
+ int end_module = (int) (m_world->GetRandom().GetDouble() * num_modules);
double start_frac = ((double) start_module) / (double) num_modules;
double end_frac = ((double) end_module) / (double) num_modules;
@@ -396,7 +396,7 @@
int swap_count = 0;
for (int i = 0; i < num_modules; i++) {
- if (g_random.GetDouble() < 0.5) {
+ if (m_world->GetRandom().GetDouble() < 0.5) {
swap_count++;
double start_frac = ((double) i) / (double) num_modules;
double end_frac = ((double) i+1) / (double) num_modules;
@@ -434,7 +434,7 @@
int swap_count = 0;
for (int mod0 = 0; mod0 < num_modules; mod0++) {
- if (g_random.GetDouble() < 0.5) {
+ if (m_world->GetRandom().GetDouble() < 0.5) {
swap_count++;
// Collect start and end info for current module
@@ -444,9 +444,9 @@
int end0 = (int) (end0_frac * (double) genome0.GetSize());
// Pick module from other genome...
- int mod1 = g_random.GetUInt(num_modules);
+ int mod1 = m_world->GetRandom().GetUInt(num_modules);
while (swapped_region[mod1] == true) {
- mod1 = g_random.GetUInt(num_modules);
+ mod1 = m_world->GetRandom().GetUInt(num_modules);
}
swapped_region[mod1] = true;
@@ -550,7 +550,7 @@
// If we are NOT recombining, handle that here.
if (parent_phenotype.CrossNum() == 0 ||
- g_random.GetDouble() > m_world->GetConfig().RECOMBINATION_PROB.Get()) {
+ m_world->GetRandom().GetDouble() > m_world->GetConfig().RECOMBINATION_PROB.Get()) {
return DoPairAsexBirth(*old_entry, child_genome, parent,
child_array, merit_array);
}
@@ -616,7 +616,7 @@
child_array.Resize(1);
merit_array.Resize(1);
- if (g_random.GetDouble() < 0.5) {
+ if (m_world->GetRandom().GetDouble() < 0.5) {
child_array[0] = new cOrganism(m_world, genome0);
merit_array[0] = merit0;
Modified: branches/brysonda/source/main/cEnvironment.cc
===================================================================
--- branches/brysonda/source/main/cEnvironment.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cEnvironment.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -639,7 +639,7 @@
// And randomize the rest...
for (int i = 0; i < 3; i++) {
- input_array[i] += g_random.GetUInt(1 << 24);
+ input_array[i] += m_world->GetRandom().GetUInt(1 << 24);
}
}
@@ -851,7 +851,7 @@
const int detected_id = detected->GetID();
const double real_amount = resource_count[detected_id];
double estimated_amount =
- g_random.GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
+ m_world->GetRandom().GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
if (estimated_amount < cur_process->GetDetectionThreshold()) {
result.Detect(detected_id, 0.0);
} else {
Modified: branches/brysonda/source/main/cEnvironment.h
===================================================================
--- branches/brysonda/source/main/cEnvironment.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cEnvironment.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -91,7 +91,7 @@
// disabled copy constructor.
cEnvironment(const cEnvironment &);
public:
- cEnvironment(cWorld* world) : m_world(world) { ; }
+ cEnvironment(cWorld* world) : m_world(world), inst_set(world), mut_rates(world) { ; }
~cEnvironment() { ; }
/**
Modified: branches/brysonda/source/main/cGenotype.cc
===================================================================
--- branches/brysonda/source/main/cGenotype.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cGenotype.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -156,8 +156,8 @@
int i;
for (i = 0; i < genome.GetSize(); i++) {
- if (true) { // g_random.GetUInt()) { //@CAO always true!
- genome[i].SetOp(g_random.GetUInt(m_world->GetNumInstructions()));
+ if (true) { // m_world->GetRandom().GetUInt()) { //@CAO always true!
+ genome[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
// Flag command as having been mutated? @CAO
}
}
Modified: branches/brysonda/source/main/cInjectGenotype.cc
===================================================================
--- branches/brysonda/source/main/cInjectGenotype.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cInjectGenotype.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -112,7 +112,7 @@
int i;
for (i = 0; i < genome.GetSize(); i++) {
- genome[i].SetOp(g_random.GetUInt(m_world->GetNumInstructions()));
+ genome[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
}
}
Modified: branches/brysonda/source/main/cInstSet.cc
===================================================================
--- branches/brysonda/source/main/cInstSet.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cInstSet.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -5,34 +5,26 @@
// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
//////////////////////////////////////////////////////////////////////////////
-#ifndef cInstSet_h
#include "cInstSet.h"
-#endif
-#ifndef STRING_UTIL_HH
#include "cStringUtil.h"
-#endif
-#ifndef TOOLS_HH
-#include "cTools.h"
-#endif
+#include "cWorld.h"
using namespace std;
-//////////////////////
-// cInstSet
-//////////////////////
// Initialize static variables
const cInstruction cInstSet::inst_default( 0 );
cInstruction cInstSet::inst_default2( 0 );
cInstruction cInstSet::inst_error2 ( 255 );
-cInstSet::cInstSet()
+cInstSet::cInstSet(cWorld* world) : m_world(world)
{
}
cInstSet::cInstSet(const cInstSet & in_inst_set)
- : m_inst_lib(in_inst_set.m_inst_lib)
+ : m_world(in_inst_set.m_world)
+ , m_inst_lib(in_inst_set.m_inst_lib)
, m_lib_name_map(in_inst_set.m_lib_name_map)
, m_lib_nopmod_map(in_inst_set.m_lib_nopmod_map)
, mutation_chart2(in_inst_set.mutation_chart2)
@@ -74,7 +66,7 @@
cInstruction cInstSet::GetRandomInst() const
{
- int inst_op = mutation_chart2[g_random.GetUInt(mutation_chart2.GetSize())];
+ int inst_op = mutation_chart2[m_world->GetRandom().GetUInt(mutation_chart2.GetSize())];
return cInstruction(inst_op);
}
Modified: branches/brysonda/source/main/cInstSet.h
===================================================================
--- branches/brysonda/source/main/cInstSet.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cInstSet.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -25,15 +25,6 @@
using namespace std;
-// A typdef to simplify having an instruction point to methods in the
-// cHardwareBase object and its dirivitives...
-class cHardwareBase;
-
-// moved to cpu/hardware_method.hh for porting to gcc 3.1 -- k
-//typedef bool (cHardwareBase::*tHardwareMethod)();
-
-class cInstLibBase;
-
/**
* This class is used to create a mapping from the command strings in
* an organism's genome into real methods in one of the hardware objects. This
@@ -42,13 +33,11 @@
* attach different cInstSet objects to different hardware.
**/
-class cInstLibBase; // access
-template <class T> class tArray; // aggregate
-class cInstruction; // access
-class cString; // access
+class cWorld;
class cInstSet {
public:
+ cWorld* m_world;
cInstLibBase *m_inst_lib;
class cInstEntry2 {
public:
@@ -72,7 +61,7 @@
static const cInstruction inst_default;
public:
- cInstSet();
+ cInstSet(cWorld* world);
cInstSet(const cInstSet & in_inst_set);
~cInstSet();
Modified: branches/brysonda/source/main/cLandscape.cc
===================================================================
--- branches/brysonda/source/main/cLandscape.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cLandscape.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -294,11 +294,11 @@
int test_id = 0;
while ((test_id < min_tests) ||
(test_id < max_tests && (total_neut_found + total_pos_found) < min_found)) {
- g_random.Choose(genome_size, mut_lines);
+ m_world->GetRandom().Choose(genome_size, mut_lines);
test_fitness = 1.0;
for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {
test_fitness *=
- fitness_chart(mut_lines[j], g_random.GetUInt(inst_size));
+ fitness_chart(mut_lines[j], m_world->GetRandom().GetUInt(inst_size));
}
total_fitness += test_fitness;
total_sqr_fitness += test_fitness * test_fitness;
@@ -418,12 +418,12 @@
int test_id = 0;
while ((test_id < min_tests) ||
(test_id < max_tests && (total_neg_found + total_neut_found + total_pos_found) < min_found)) {
- g_random.Choose(genome_size, mut_lines);
+ m_world->GetRandom().Choose(genome_size, mut_lines);
test_fitness = 1.0;
for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {
int base_inst = base_genome[ mut_lines[j] ].GetOp();
- int mut_inst = g_random.GetUInt(inst_size);
- while (mut_inst == base_inst) mut_inst = g_random.GetUInt(inst_size);
+ int mut_inst = m_world->GetRandom().GetUInt(inst_size);
+ while (mut_inst == base_inst) mut_inst = m_world->GetRandom().GetUInt(inst_size);
test_fitness *= fitness_chart(mut_lines[j], mut_inst);
if (test_fitness == 0.0) break;
}
@@ -524,7 +524,7 @@
for (cur_trial = 0; cur_trial < in_trials; cur_trial++) {
// Choose the lines to mutate...
- g_random.Choose(genome_size, mut_lines);
+ m_world->GetRandom().Choose(genome_size, mut_lines);
// Choose the new instructions for those lines...
for (mut_num = 0; mut_num < distance; mut_num++) {
@@ -602,7 +602,7 @@
// Loop through all the lines of genome, testing many combinations.
for (int i = 0; i < trials; i++) {
// Choose the lines to mutate...
- g_random.Choose(genome_size, mut_lines);
+ m_world->GetRandom().Choose(genome_size, mut_lines);
// Choose the new instructions for those lines...
for (int mut_num = 0; mut_num < 2; mut_num++) {
Modified: branches/brysonda/source/main/cMutationRates.cc
===================================================================
--- branches/brysonda/source/main/cMutationRates.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cMutationRates.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -5,24 +5,16 @@
// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
//////////////////////////////////////////////////////////////////////////////
-#ifndef MUTATION_RATES_HH
#include "cMutationRates.h"
-#endif
-#ifndef TOOLS_HH
-#include "cTools.h"
-#endif
+#include "cWorld.h"
-////////////////////
-// cMutationRates
-////////////////////
-
-cMutationRates::cMutationRates()
+cMutationRates::cMutationRates(cWorld* world) : m_world(world)
{
Clear();
}
-cMutationRates::cMutationRates(const cMutationRates & in_muts)
+cMutationRates::cMutationRates(const cMutationRates & in_muts) : m_world(in_muts.m_world)
{
Copy(in_muts);
}
@@ -59,46 +51,44 @@
divide.parent_mut_prob = in_muts.divide.parent_mut_prob;
divide.crossover_prob = in_muts.divide.crossover_prob;
divide.aligned_cross_prob = in_muts.divide.aligned_cross_prob;
-
- // if (copy.copy_mut_prob != 0) cerr << "Copying non-zero copy mut rate!" << endl;
}
bool cMutationRates::TestPointMut() const
{
- return g_random.P(exec.point_mut_prob);
+ return m_world->GetRandom().P(exec.point_mut_prob);
}
bool cMutationRates::TestCopyMut() const
{
- return g_random.P(copy.copy_mut_prob);
+ return m_world->GetRandom().P(copy.copy_mut_prob);
}
bool cMutationRates::TestDivideMut() const
{
- return g_random.P(divide.divide_mut_prob);
+ return m_world->GetRandom().P(divide.divide_mut_prob);
}
bool cMutationRates::TestDivideIns() const
{
- return g_random.P(divide.divide_ins_prob);
+ return m_world->GetRandom().P(divide.divide_ins_prob);
}
bool cMutationRates::TestDivideDel() const
{
- return g_random.P(divide.divide_del_prob);
+ return m_world->GetRandom().P(divide.divide_del_prob);
}
bool cMutationRates::TestParentMut() const
{
- return g_random.P(divide.parent_mut_prob);
+ return m_world->GetRandom().P(divide.parent_mut_prob);
}
bool cMutationRates::TestCrossover() const
{
- return g_random.P(divide.crossover_prob);
+ return m_world->GetRandom().P(divide.crossover_prob);
}
bool cMutationRates::TestAlignedCrossover() const
{
- return g_random.P(divide.aligned_cross_prob);
+ return m_world->GetRandom().P(divide.aligned_cross_prob);
}
Modified: branches/brysonda/source/main/cMutationRates.h
===================================================================
--- branches/brysonda/source/main/cMutationRates.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cMutationRates.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -8,8 +8,12 @@
#ifndef MUTATION_RATES_HH
#define MUTATION_RATES_HH
+class cWorld;
+
class cMutationRates {
private:
+ cWorld* m_world;
+
// Mutations are divided up by when they occur...
// ...anytime during execution...
@@ -41,7 +45,7 @@
void operator=(const cMutationRates & in_muts)
{ (void) in_muts; } // Disable operator=
public:
- cMutationRates();
+ cMutationRates(cWorld* world);
cMutationRates(const cMutationRates & in_muts);
~cMutationRates();
Modified: branches/brysonda/source/main/cMxCodeArray.cc
===================================================================
--- branches/brysonda/source/main/cMxCodeArray.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cMxCodeArray.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -47,7 +47,7 @@
for (int i = 0; i < size; i++)
{
- data[i].SetOp(g_random.GetUInt(m_world->GetNumInstructions()));
+ data[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
}
}
@@ -120,7 +120,7 @@
// Fill in the un-filled-in bits...
for (int i = size; i < new_size; i++) {
- data[i].SetOp(g_random.GetUInt(m_world->GetNumInstructions()));
+ data[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
}
size = new_size;
@@ -197,7 +197,7 @@
int i;
for (i = 0; i < size; i++)
{
- data[i].SetOp(g_random.GetUInt(m_world->GetNumInstructions()));
+ data[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
}
}
Modified: branches/brysonda/source/main/cOrganism.cc
===================================================================
--- branches/brysonda/source/main/cOrganism.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cOrganism.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -38,6 +38,7 @@
, genotype(NULL)
, phenotype(world)
, initial_genome(in_genome)
+ , mut_rates(world)
, mut_info(world->GetEnvironment().GetMutationLib(), in_genome.GetSize())
, pop_interface(world)
, input_pointer(0)
@@ -64,7 +65,7 @@
if (m_world->GetConfig().DEATH_METHOD.Get() > 0) {
max_executed = m_world->GetConfig().AGE_LIMIT.Get();
if (m_world->GetConfig().AGE_DEVIATION.Get() > 0.0) {
- max_executed += (int) (g_random.GetRandNormal() * m_world->GetConfig().AGE_DEVIATION.Get());
+ max_executed += (int) (m_world->GetRandom().GetRandNormal() * m_world->GetConfig().AGE_DEVIATION.Get());
}
if (m_world->GetConfig().DEATH_METHOD.Get() == DEATH_METHOD_MULTIPLE) {
max_executed *= initial_genome.GetSize();
Modified: branches/brysonda/source/main/cPhenotype.cc
===================================================================
--- branches/brysonda/source/main/cPhenotype.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cPhenotype.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -118,7 +118,7 @@
time_used = 0;
age = 0;
fault_desc = "";
- neutral_metric = parent_phenotype.neutral_metric + g_random.GetRandNormal();
+ neutral_metric = parent_phenotype.neutral_metric + m_world->GetRandom().GetRandNormal();
life_fitness = fitness;
// Setup flags...
@@ -304,7 +304,7 @@
if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
gestation_start = 0;
time_used = 0;
- neutral_metric += g_random.GetRandNormal();
+ neutral_metric += m_world->GetRandom().GetRandNormal();
}
if (m_world->GetConfig().GENERATION_INC_METHOD.Get() == GENERATION_INC_BOTH) generation++;
@@ -443,7 +443,7 @@
time_used = 0;
age = 0;
fault_desc = "";
- neutral_metric = clone_phenotype.neutral_metric + g_random.GetRandNormal();
+ neutral_metric = clone_phenotype.neutral_metric + m_world->GetRandom().GetRandNormal();
life_fitness = fitness;
// Setup flags...
Modified: branches/brysonda/source/main/cPopulation.cc
===================================================================
--- branches/brysonda/source/main/cPopulation.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cPopulation.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -101,7 +101,7 @@
for (int cell_id = 0; cell_id < num_cells; cell_id++) {
int x = cell_id % world_x;
int y = cell_id / world_x;
- cell_array[cell_id].Setup(cell_id, default_mut_rates);
+ cell_array[cell_id].Setup(world, cell_id, default_mut_rates);
if ((y == 0) && (geometry == nGeometry::GRID)) {
@@ -416,7 +416,7 @@
int num_neighbors = parent.GetNeighborhoodSize();
cOrganism * target_organism =
- parent_cell.connection_list.GetPos(g_random.GetUInt(num_neighbors))->GetOrganism();
+ parent_cell.connection_list.GetPos(m_world->GetRandom().GetUInt(num_neighbors))->GetOrganism();
if(target_organism==NULL)
return false;
@@ -779,7 +779,7 @@
// Pick which demes should be in the next generation.
tArray<int> new_demes(num_demes);
for (int i = 0; i < num_demes; i++) {
- double birth_choice = (double) g_random.GetDouble(total_fitness);
+ double birth_choice = (double) m_world->GetRandom().GetDouble(total_fitness);
double test_total = 0;
for (int test_deme = 0; test_deme < num_demes; test_deme++) {
test_total += deme_fitness[test_deme];
@@ -1023,9 +1023,9 @@
// Try out global/full-deme birth methods first...
if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
- int out_pos = g_random.GetUInt(cell_array.GetSize());
+ int out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
while (parent_ok == false && out_pos == parent_cell.GetID()) {
- out_pos = g_random.GetUInt(cell_array.GetSize());
+ out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
}
return GetCell(out_pos);
}
@@ -1040,9 +1040,9 @@
else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
const int parent_id = parent_cell.GetID();
const int cur_deme = parent_id / deme_size;
- int out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
+ int out_pos = m_world->GetRandom().GetUInt(deme_size) + deme_size * cur_deme;
while (parent_ok == false && out_pos == parent_cell.GetID()) {
- out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
+ out_pos = m_world->GetRandom().GetUInt(deme_size) + deme_size * cur_deme;
}
deme_birth_count[cur_deme]++;
return GetCell(out_pos);
@@ -1092,7 +1092,7 @@
if (found_list.GetSize() == 0) return parent_cell;
// Choose the organism randomly from those in the list, and return it.
- int choice = g_random.GetUInt(found_list.GetSize());
+ int choice = m_world->GetRandom().GetUInt(found_list.GetSize());
return *( found_list.GetPos(choice) );
}
@@ -1117,7 +1117,7 @@
// debug_fp << stats.GetUpdate() << " "
// << cell.GetOrganism()->GetCellID() << " "
// << cell.GetOrganism()->GetGenotype()->GetID() << " "
- // << g_random.GetDouble() << " "
+ // << m_world->GetRandom().GetDouble() << " "
// << cell.GetOrganism()->GetHardware().GetMemory().AsString() << " "
// << endl;
@@ -1825,7 +1825,7 @@
schedule = new cConstSchedule(cell_array.GetSize());
break;
case SLICE_PROB_MERIT:
- schedule = new cProbSchedule(cell_array.GetSize());
+ schedule = new cProbSchedule(m_world, cell_array.GetSize());
break;
case SLICE_INTEGRATED_MERIT:
schedule = new cIntegratedSchedule(cell_array.GetSize());
@@ -2014,7 +2014,7 @@
// Remove the proper number of cells.
const int removal_size = num_organisms - transfer_size;
for (int i = 0; i < removal_size; i++) {
- int j = (int) g_random.GetUInt(transfer_pool.size());
+ int j = (int) m_world->GetRandom().GetUInt(transfer_pool.size());
KillOrganism(cell_array[transfer_pool[j]]);
transfer_pool[j] = transfer_pool.back();
transfer_pool.pop_back();
Modified: branches/brysonda/source/main/cPopulationCell.cc
===================================================================
--- branches/brysonda/source/main/cPopulationCell.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cPopulationCell.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -14,20 +14,25 @@
using namespace std;
cPopulationCell::cPopulationCell()
- : organism(NULL)
+ : m_world(NULL)
+ , organism(NULL)
+ , mutation_rates(NULL)
, cur_input(0)
, organism_count(0)
{
}
cPopulationCell::cPopulationCell(const cPopulationCell & in_cell)
- : organism(in_cell.organism)
+ : m_world(in_cell.m_world)
+ , organism(in_cell.organism)
+ , mutation_rates(NULL)
, cur_input(in_cell.cur_input)
, cell_id(in_cell.cell_id)
, organism_count(in_cell.organism_count)
{
for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
- mutation_rates.Copy(in_cell.mutation_rates);
+ mutation_rates = new cMutationRates(m_world);
+ mutation_rates->Copy(*in_cell.mutation_rates);
tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
cPopulationCell * test_cell;
while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
@@ -37,12 +42,14 @@
void cPopulationCell::operator=(const cPopulationCell & in_cell)
{
+ m_world = in_cell.m_world;
organism = in_cell.organism;
for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
cur_input = in_cell.cur_input;
cell_id = in_cell.cell_id;
organism_count = in_cell.organism_count;
- mutation_rates.Copy(in_cell.mutation_rates);
+ if (mutation_rates == NULL) mutation_rates = new cMutationRates(m_world);
+ mutation_rates->Copy(*in_cell.mutation_rates);
tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
cPopulationCell * test_cell;
while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
@@ -50,10 +57,12 @@
}
}
-void cPopulationCell::Setup(int in_id, const cMutationRates & in_rates)
+void cPopulationCell::Setup(cWorld* world, int in_id, const cMutationRates & in_rates)
{
+ m_world = world;
cell_id = in_id;
- mutation_rates.Copy(in_rates);
+ if (mutation_rates == NULL) mutation_rates = new cMutationRates(world);
+ mutation_rates->Copy(in_rates);
}
void cPopulationCell::Rotate(cPopulationCell & new_facing)
Modified: branches/brysonda/source/main/cPopulationCell.h
===================================================================
--- branches/brysonda/source/main/cPopulationCell.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cPopulationCell.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -30,9 +30,10 @@
class cPopulationCell {
friend class cPopulation;
private:
- cOrganism * organism; // The occupent of this cell.
+ cWorld* m_world;
+ cOrganism* organism; // The occupent of this cell.
tList<cPopulationCell> connection_list; // A list of neighboring cells.
- cMutationRates mutation_rates; // Mutation rates at this cell.
+ cMutationRates* mutation_rates; // Mutation rates at this cell.
tArray<int> input_array; // Environmental Inputs...
int cur_input; // Next input to give organism.
@@ -50,13 +51,13 @@
void operator=(const cPopulationCell & in_cell);
- void Setup(int in_id, const cMutationRates & in_rates);
+ void Setup(cWorld* world, int in_id, const cMutationRates & in_rates);
void Rotate(cPopulationCell & new_facing);
cOrganism * GetOrganism() const { return organism; }
tList<cPopulationCell> & ConnectionList() { return connection_list; }
- const cMutationRates & MutationRates() const { return mutation_rates; }
- cMutationRates & MutationRates() { return mutation_rates; }
+ const cMutationRates & MutationRates() const { return *mutation_rates; }
+ cMutationRates & MutationRates() { return *mutation_rates; }
int GetInput();
int GetInput(int);
int GetInputAt(int & input_pointer);
Modified: branches/brysonda/source/main/cWorld.cc
===================================================================
--- branches/brysonda/source/main/cWorld.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/main/cWorld.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -30,14 +30,9 @@
void cWorld::Setup() {
// Setup Random Number Generator
const int rand_seed = m_conf->RANDOM_SEED.Get();
- /* DDD - for right now we need to still use g_random
cout << "Random Seed: " << rand_seed;
m_rng.ResetSeed(rand_seed);
if (rand_seed != m_rng.GetSeed()) cout << " -> " << m_rng.GetSeed();
- */
- cout << "Random Seed: " << rand_seed;
- g_random.ResetSeed(rand_seed);
- if (rand_seed != g_random.GetSeed()) cout << " -> " << g_random.GetSeed();
cout << endl;
// The default directory should end in a '/'.
Modified: branches/brysonda/source/tools/cProbSchedule.cc
===================================================================
--- branches/brysonda/source/tools/cProbSchedule.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/tools/cProbSchedule.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -9,7 +9,7 @@
#include "cChangeList.h"
#include "cMerit.h"
-#include "cTools.h"
+#include "cWorld.h"
///////////////////
@@ -18,8 +18,9 @@
// The larger merits cause problems here; things need to be re-thought out.
-cProbSchedule::cProbSchedule(int _item_count)
+cProbSchedule::cProbSchedule(cWorld* world, int _item_count)
: cSchedule(_item_count)
+ , m_world(world)
, chart(_item_count)
{
}
@@ -32,7 +33,7 @@
int cProbSchedule::GetNextID()
{
assert(chart.GetTotalWeight() > 0);
- const double position = g_random.GetDouble(chart.GetTotalWeight());
+ const double position = m_world->GetRandom().GetDouble(chart.GetTotalWeight());
return chart.FindPosition(position);
}
Modified: branches/brysonda/source/tools/cProbSchedule.h
===================================================================
--- branches/brysonda/source/tools/cProbSchedule.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/tools/cProbSchedule.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -22,12 +22,14 @@
class cWeightedIndex; // aggregate
class cMerit;
+class cWorld;
class cProbSchedule : public cSchedule {
private:
+ cWorld* m_world;
cWeightedIndex chart;
public:
- cProbSchedule(int num_cells);
+ cProbSchedule(cWorld* world, int num_cells);
~cProbSchedule();
void Adjust(int item_id, const cMerit & merit);
Modified: branches/brysonda/source/tools/cTools.cc
===================================================================
--- branches/brysonda/source/tools/cTools.cc 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/tools/cTools.cc 2005-10-23 04:09:39 UTC (rev 358)
@@ -24,8 +24,6 @@
# endif
#endif
-cRandom g_random;
-
using namespace std;
bool cTools::MkDir(const cString & dirname, bool verbose)
Modified: branches/brysonda/source/tools/cTools.h
===================================================================
--- branches/brysonda/source/tools/cTools.h 2005-10-22 01:56:38 UTC (rev 357)
+++ branches/brysonda/source/tools/cTools.h 2005-10-23 04:09:39 UTC (rev 358)
@@ -10,12 +10,6 @@
#ifndef TOOLS_HH
#define TOOLS_HH
-#ifndef cRandom_h
-#include "cRandom.h"
-#endif
-
-extern cRandom g_random;
-
/*
* Filesystem tools...
*/
More information about the Avida-cvs
mailing list