| 59 | |
| 60 | |
| 61 | void cTestCPU::InitResources(cAvidaContext& ctx, int res_method, cResourceHistory* res, int update, int cpu_cycle_offset) |
| 62 | { |
| 63 | //FOR DEMES |
| 64 | m_deme_resource_count.SetSize(0); |
| 65 | |
| 66 | m_res_method = (eTestCPUResourceMethod)res_method; |
| 67 | // Make sure it's valid |
| 68 | if (res_method < 0 || res_method >= RES_LAST) m_res_method = RES_INITIAL; |
| 69 | |
| 70 | // Setup the resources... |
| 71 | m_res = res; |
| 72 | m_res_cpu_cycle_offset = cpu_cycle_offset; |
| 73 | m_res_update = update; |
| 74 | |
| 75 | // Adjust updates if time_spent_offset is greater than a time slice |
| 76 | int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get(); |
| 77 | m_res_update += m_res_cpu_cycle_offset / ave_time_slice; |
| 78 | m_res_cpu_cycle_offset %= ave_time_slice; |
| 79 | assert(m_res_cpu_cycle_offset >= 0); |
| 80 | |
| 81 | // If they didn't send anything (usually during an avida run as opposed to analyze mode), |
| 82 | // then we set up a static variable (or just point to it) that reflects the initial conditions of the run |
| 83 | // from the environment file. (JEB -- This code moved from cAnalyze::cAnalyze). |
| 84 | if (m_res_method == RES_INITIAL) |
| 85 | { |
| 86 | // Initialize the time oriented resource list to be just the initial |
| 87 | // concentrations of the resources in the environment. This will only |
| 88 | // be changed if LOAD_RESOURCES analyze command is called. If there are |
| 89 | // no resources in the environment or there is no environment, the list |
| 90 | // is empty then the all resources will default to 0.0 |
| 91 | m_res = &m_world->GetEnvironment().GetResourceLib().GetInitialResourceLevels(); |
| 92 | } |
| 93 | |
| 94 | const cResourceLib& resource_lib = m_world->GetEnvironment().GetResourceLib(); |
| 95 | assert(resource_lib.GetSize() >= 0); |
| 96 | |
| 97 | // Set the resource count to zero by default |
| 98 | m_resource_count.SetSize(resource_lib.GetSize()); |
| 99 | m_faced_cell_resource_count.SetSize(resource_lib.GetSize()); |
| 100 | m_cell_resource_count.SetSize(resource_lib.GetSize()); |
| 101 | for (int i = 0; i < resource_lib.GetSize(); i++) { |
| 102 | m_resource_count.Set(ctx, i, 0.0); |
| 103 | m_faced_cell_resource_count.Set(ctx, i, 0.0); |
| 104 | m_cell_resource_count.Set(ctx, i, 0.0); |
| 105 | } |
| 106 | |
| 107 | if (m_test_solo_res == -1) SetResourceUpdate(ctx, m_res_update, false); |
| 108 | // Round down to the closest update to choose how to initialize resources |
| 109 | else m_resource_count.Set(ctx, m_test_solo_res, m_test_solo_res_lev); |
| 110 | } |
| 111 | |
| 112 | void cTestCPU::UpdateResources(cAvidaContext& ctx, int cpu_cycles_used) |
| 113 | { |