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

Method Load

avida-core/source/main/cMigrationMatrix.cc:69–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67};
68
69bool cMigrationMatrix::Load(const int num_demes, const cString& filename, const cString& working_dir,bool p_count_parasites, bool p_count_offspring, bool p_is_reload, Feedback& feedback){
70 m_migration_matrix.ResizeClear(0);
71 m_row_connectivity_sums.ResizeClear(0);
72 cInitFile infile(filename, working_dir);
73 if (!infile.WasOpened()) {
74 for (int i = 0; i < infile.GetFeedback().GetNumMessages(); i++) {
75 switch (infile.GetFeedback().GetMessageType(i)) {
76 case cUserFeedback::UF_ERROR:
77 feedback.Error(infile.GetFeedback().GetMessage(i));
78 break;
79 case cUserFeedback::UF_WARNING:
80 feedback.Warning(infile.GetFeedback().GetMessage(i));
81 break;
82 default:
83 feedback.Notify(infile.GetFeedback().GetMessage(i));
84 }
85 }
86 feedback.Error("failed to load migration matrix '%s'", (const char*)filename);
87 return false;
88 }
89
90 Apto::Array<double, Apto::Smart> f_temp_row;
91 for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
92 // Load the next line from the file.
93 f_temp_row.ResizeClear(0);
94 cString f_curr_line = infile.GetLine(line_id);
95 double f_row_sum = 0.0;
96 while(!f_curr_line.IsEmpty()){
97 double val = f_curr_line.Pop(',').AsDouble();
98 if(val < 0.0){
99 feedback.Error("Cannot have a negative connection in connection matrix");
100 return false;
101 }
102 f_row_sum += val;
103 f_temp_row.Push(val);
104 }
105 if(f_row_sum == 0.0){
106 feedback.Error("Cannot have a row sum of 0.0 in connection matrix");
107 return false;
108 }
109 else{
110 m_row_connectivity_sums.Push(f_row_sum);
111 }
112 m_migration_matrix.Push(f_temp_row);
113 }
114
115 if(num_demes != m_migration_matrix.GetSize()){
116 feedback.Error("The number of demes in the migration matrix (%i) did not match the NUM_DEMES (%i) parameter in avida.cfg.",m_migration_matrix.GetSize(),num_demes);
117 return false;
118 }
119 for(int f_row = 0; f_row < m_migration_matrix.GetSize(); f_row++){
120 if(m_migration_matrix[f_row].GetSize() != m_migration_matrix.GetSize()){
121 feedback.Error("The number of columns in row %i did not match total number of demes",f_row);
122 return false;
123 }
124 if(m_migration_matrix[f_row].GetSize() != num_demes){
125 feedback.Error("The number of demes in the migration matrix (%i) did not match the NUM_DEMES (%i) parameter in avida.cfg.",m_migration_matrix.GetSize(),num_demes);
126 return false;

Callers

nothing calls this directly

Calls 15

WasOpenedMethod · 0.80
GetNumMessagesMethod · 0.80
GetNumLinesMethod · 0.80
ResizeClearMethod · 0.45
GetMessageTypeMethod · 0.45
ErrorMethod · 0.45
WarningMethod · 0.45
NotifyMethod · 0.45
GetLineMethod · 0.45
IsEmptyMethod · 0.45
AsDoubleMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected