| 1128 | |
| 1129 | static const cString GetDescription() { return "Arguments: [string fname='lineage_counts.dat']\n WARNING: This will only have the appropriate header if all lineages are present before this action is run for the first time."; } |
| 1130 | void Process(cAvidaContext&) |
| 1131 | { |
| 1132 | const int update = m_world->GetStats().GetUpdate(); |
| 1133 | const double generation = m_world->GetStats().SumGeneration().Average(); |
| 1134 | |
| 1135 | //only loop through living organisms |
| 1136 | const Apto::Array<cOrganism*, Apto::Smart>& living_orgs = m_world->GetPopulation().GetLiveOrgList(); |
| 1137 | |
| 1138 | Apto::Map<int, int> lineage_label_counts; |
| 1139 | |
| 1140 | //build hash of lineage_label -> count |
| 1141 | for(int i = 0; i < living_orgs.GetSize(); i++) { |
| 1142 | const int cur_lineage_label = living_orgs[i]->GetLineageLabel(); |
| 1143 | if (lineage_label_counts.Has(cur_lineage_label)) lineage_label_counts[cur_lineage_label]++; |
| 1144 | else lineage_label_counts[cur_lineage_label] = 1; |
| 1145 | } |
| 1146 | |
| 1147 | //setup lineage labels in the first pass |
| 1148 | if (first_run == false) { |
| 1149 | for (Apto::Map<int, int>::KeyIterator it = lineage_label_counts.Keys(); it.Next();) lineage_labels.Push(*it.Get()); |
| 1150 | first_run = true; |
| 1151 | } |
| 1152 | |
| 1153 | Avida::Output::FilePtr df = Avida::Output::File::StaticWithPath(m_world->GetNewWorld(), (const char*)m_filename); |
| 1154 | df->Write(update, "Update"); |
| 1155 | df->Write(generation, "Generation"); |
| 1156 | |
| 1157 | //for each lineage label, output the counts |
| 1158 | //@LZ - handle dead lineages appropriately |
| 1159 | for (int i = 0; i < lineage_labels.GetSize(); i++) { |
| 1160 | //default to 0 in case this lineage is dead |
| 1161 | int count = 0; |
| 1162 | |
| 1163 | lineage_label_counts.Get(lineage_labels[i], count); |
| 1164 | |
| 1165 | df->Write(count, cStringUtil::Stringf("Lineage Label %d", lineage_labels[i])); |
| 1166 | } |
| 1167 | |
| 1168 | df->Endl(); |
| 1169 | } |
| 1170 | }; |
| 1171 | |
| 1172 |
nothing calls this directly
no test coverage detected