-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent_io: agents_to_file and agents_from_file
Removed the corresponding functions in `agent_generation` and `io`. It makes more sense to localize the agent_io in a single header. Co-authored-by: Amrita Goswami <[email protected]>
- Loading branch information
1 parent
eae15a3
commit 4303d50
Showing
5 changed files
with
77 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,9 @@ | ||
#pragma once | ||
#include "agent_io.hpp" | ||
#include "util/misc.hpp" | ||
#include <cstddef> | ||
#include <vector> | ||
|
||
namespace Seldon::AgentGeneration | ||
{ | ||
|
||
template<typename AgentT> | ||
std::vector<AgentT> generate_from_file( const std::string & file ) | ||
{ | ||
std::vector<AgentT> agents{}; | ||
|
||
std::string file_contents = get_file_contents( file ); | ||
bool finished = false; | ||
size_t start_of_line = 0; | ||
|
||
while( !finished ) | ||
{ | ||
// Find the end of the current line | ||
auto end_of_line = file_contents.find( '\n', start_of_line ); | ||
if( end_of_line == std::string::npos ) | ||
{ | ||
finished = true; | ||
} | ||
// Get the current line as a substring | ||
auto line = file_contents.substr( start_of_line, end_of_line - start_of_line ); | ||
start_of_line = end_of_line + 1; | ||
|
||
if( line.empty() ) | ||
{ | ||
break; | ||
} | ||
if( line[0] == '#' ) | ||
{ | ||
continue; | ||
} | ||
|
||
// First column is the index of the agent | ||
auto end_of_first_column = line.find( ',', 0 ); | ||
auto opinion_substring = line.substr( end_of_first_column + 1, end_of_line ); | ||
|
||
agents.push_back( agent_from_string<AgentT>( opinion_substring ) ); | ||
} | ||
|
||
return agents; | ||
} | ||
|
||
} // namespace Seldon::AgentGeneration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters