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

Method LoadPopulation

avida-core/source/main/cPopulation.cc:6714–7021  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6712
6713
6714bool cPopulation::LoadPopulation(const cString& filename, cAvidaContext& ctx, int cellid_offset, int lineage_offset, bool load_groups, bool load_birth_cells, bool load_avatars, bool load_rebirth, bool load_parent_dat, int traceq)
6715{
6716 // @TODO - build in support for verifying population dimensions
6717
6718 cInitFile input_file(filename, m_world->GetWorkingDir(), ctx.Driver().Feedback());
6719 if (!input_file.WasOpened()) return false;
6720
6721 // Clear out the population, unless an offset is being used
6722 if (cellid_offset == 0) {
6723 for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i], ctx);
6724 }
6725
6726 // First, we read in all the genotypes and store them in an array
6727 Apto::Array<sTmpGenotype, Apto::ManagedPointer> genotypes(input_file.GetNumLines());
6728
6729 bool structured = false;
6730 for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
6731 cString cur_line = input_file.GetLine(line_id);
6732
6733 // Setup the genotype for this line...
6734 sTmpGenotype& tmp = genotypes[line_id];
6735 tmp.props = input_file.GetLineAsDict(line_id);
6736 tmp.id_num = Apto::StrAs(tmp.props->Get("id"));
6737
6738 // Loads "num_units" preferrentially, but will fall back to "num_cpus" if present
6739 assert(tmp.props->Has("num_cpus") || tmp.props->Has("num_units"));
6740 tmp.num_cpus = (tmp.props->Has("num_units")) ? Apto::StrAs(tmp.props->Get("num_units")) : Apto::StrAs(tmp.props->Get("num_cpus"));
6741
6742 // Process resident cell ids
6743 cString cellstr(tmp.props->Get("cells"));
6744 if (structured || cellstr.GetSize()) {
6745 structured = true;
6746 while (cellstr.GetSize()) tmp.cells.Push(cellstr.Pop(',').AsInt());
6747 assert(tmp.cells.GetSize() == tmp.num_cpus);
6748 }
6749
6750 // Process gestation time offsets
6751 if (!load_rebirth) {
6752 cString offsetstr(tmp.props->Get("gest_offset"));
6753 if (offsetstr.GetSize()) {
6754 while (offsetstr.GetSize()) tmp.offsets.Push(offsetstr.Pop(',').AsInt());
6755 assert(tmp.offsets.GetSize() == tmp.num_cpus);
6756 }
6757 }
6758 // Lineage label (only set if given in file)
6759 cString lineagestr(tmp.props->Get("lineage"));
6760 while (lineagestr.GetSize()) tmp.lineage_labels.Push(lineagestr.Pop(',').AsInt());
6761 // @blw preserve compatability with older .spop files that don't have lineage labels
6762 assert(tmp.lineage_labels.GetSize() == 0 || tmp.lineage_labels.GetSize() == tmp.num_cpus);
6763
6764 // Other org specs (if given in file)
6765 if (load_rebirth) {
6766 if (tmp.props->Has("birth_cell")) {
6767 cString birthstr(tmp.props->Get("birth_cell"));
6768 while (birthstr.GetSize()) tmp.birth_cells.Push(birthstr.Pop(',').AsInt());
6769 assert(tmp.birth_cells.GetSize() == 0 || tmp.birth_cells.GetSize() == tmp.num_cpus);
6770 }
6771 if (tmp.props->Has("av_bcell") && m_world->GetConfig().USE_AVATARS.Get()) {

Callers 1

ProcessMethod · 0.80

Calls 15

FeedbackMethod · 0.80
WasOpenedMethod · 0.80
GetNumLinesMethod · 0.80
GetLineAsDictMethod · 0.80
GetConfigMethod · 0.80
GetNewWorldMethod · 0.80
ArbiterForRoleMethod · 0.80
RepresentationMethod · 0.80
SetupInjectMethod · 0.80
SetCCladeLabelMethod · 0.80
ConvertEnergyToMeritMethod · 0.80
GetStoredEnergyMethod · 0.80

Tested by

no test coverage detected