-
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.
InertialModel: Created InertialAgent
The InertialAgent has a velocity also. Co-authored-by: Moritz Sallermann <[email protected]>
- Loading branch information
1 parent
f7386a3
commit b04c5fc
Showing
1 changed file
with
68 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include "agent.hpp" | ||
#include "agent_io.hpp" | ||
#include <util/misc.hpp> | ||
|
||
namespace Seldon | ||
{ | ||
|
||
struct InertialAgentData | ||
{ | ||
double opinion = 0; // x_i | ||
double activity = 0; // alpha_i | ||
double reluctance = 1.0; // m_i | ||
double velocity = 0.0; // d(x_i)/dt | ||
}; | ||
|
||
using InertialAgent = Agent<InertialAgentData>; | ||
|
||
template<> | ||
inline std::string agent_to_string<InertialAgent>( const InertialAgent & agent ) | ||
{ | ||
return fmt::format( | ||
"{}, {}, {}, {}", agent.data.opinion, agent.data.velocity, agent.data.activity, agent.data.reluctance ); | ||
} | ||
|
||
template<> | ||
inline std::string opinion_to_string<InertialAgent>( const InertialAgent & agent ) | ||
{ | ||
return fmt::format( "{}", agent.data.opinion ); | ||
} | ||
|
||
template<> | ||
inline InertialAgent agent_from_string<InertialAgent>( const std::string & str ) | ||
{ | ||
InertialAgent res{}; | ||
|
||
auto callback = [&]( int idx_list, std::string & substr ) | ||
{ | ||
if( idx_list == 0 ) | ||
{ | ||
res.data.opinion = std::stod( substr ); | ||
} | ||
else if( idx_list == 1 ) | ||
{ | ||
res.data.velocity = std::stod( substr ); | ||
} | ||
else if( idx_list == 2 ) | ||
{ | ||
res.data.activity = std::stod( substr ); | ||
} | ||
else if( idx_list == 3 ) | ||
{ | ||
res.data.reluctance = std::stod( substr ); | ||
} | ||
}; | ||
|
||
Seldon::parse_comma_separated_list( str, callback ); | ||
|
||
return res; | ||
}; | ||
|
||
template<> | ||
inline std::vector<std::string> agent_to_string_column_names<InertialAgent>() | ||
{ | ||
return { "opinion", "velocity", "activity", "reluctance" }; | ||
} | ||
} // namespace Seldon |