Skip to content

Commit

Permalink
wip 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MSallermann committed Mar 6, 2024
1 parent 735b713 commit 37975ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
10 changes: 5 additions & 5 deletions include/models/ActivityDrivenModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class ActivityAgentModel : public Model<Agent<ActivityAgentData>>
double convergence_tol = 1e-12; // TODO: ??

// bot @TODO: less hacky
bool bot_present = false;
size_t bot_idx = 0;
int bot_m = 0;
double bot_activity = 0.0;
double bot_opinion = 0.0;
bool bot_present = false;
size_t n_bots = 0; // The first n_bots agents are bots
std::vector<int> bot_m = {};
std::vector<double> bot_activity = {};
std::vector<double> bot_opinion = {};

ActivityAgentModel( int n_agents, Network & network, std::mt19937 & gen );

Expand Down
22 changes: 14 additions & 8 deletions src/models/ActivityDrivenModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ void Seldon::ActivityAgentModel::get_agents_from_power_law()

if( bot_present )
{
agents[bot_idx].data.opinion = bot_opinion;
agents[bot_idx].data.activity = bot_activity;
for( size_t bot_idx = 0; bot_idx < n_bots; bot_idx++ )
{
agents[bot_idx].data.opinion = bot_opinion[bot_idx];
agents[bot_idx].data.activity = bot_activity[bot_idx];
}
}
}

Expand Down Expand Up @@ -66,9 +69,9 @@ void Seldon::ActivityAgentModel::update_network_probabilistic()

int m_temp = this->m;

if( bot_present && idx_agent == bot_idx )
if( bot_present && idx_agent < n_bots )
{
m_temp = bot_m;
m_temp = bot_m[idx_agent];
}

Seldon::reservoir_sampling_A_ExpJ( m_temp, network.n_agents(), weight_callback, contacted_agents, gen );
Expand Down Expand Up @@ -152,10 +155,10 @@ void Seldon::ActivityAgentModel::update_network_mean()
// Calculate the probability of i contacting j (in 1 to m rounds, assuming
// the agent is activated

int m_temp = this->m;
if( bot_present && idx_agent == bot_idx )
int m_temp = m;
if( bot_present && idx_agent < n_bots )
{
m_temp = bot_m;
m_temp = bot_m[idx_agent];
}

for( size_t j = 0; j < network.n_agents(); j++ )
Expand Down Expand Up @@ -240,6 +243,9 @@ void Seldon::ActivityAgentModel::iteration()

if( bot_present )
{
agents[bot_idx].data.opinion = bot_opinion;
for( size_t bot_idx = 0; bot_idx < n_bots; bot_idx++ )
{
agents[bot_idx].data.opinion = bot_opinion[bot_idx];
}
}
}
18 changes: 13 additions & 5 deletions src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,19 @@ Seldon::Simulation::Simulation(
model_activityDriven->max_iterations = max_iterations;

// bot
model_activityDriven->bot_idx = 0;
model_activityDriven->bot_m = tbl["ActivityDriven"]["bot_present"].value_or<size_t>( 0 );
model_activityDriven->bot_present = tbl["ActivityDriven"]["bot_present"].value_or<bool>( false );
model_activityDriven->bot_activity = tbl["ActivityDriven"]["bot_activity"].value_or<double>( 0.0 );
model_activityDriven->bot_opinion = tbl["ActivityDriven"]["bot_opinion"].value_or<double>( 0.0 );
model_activityDriven->n_bots = tbl["ActivityDriven"]["n_bots"].value_or<size_t>( 0 );
model_activityDriven->bot_present = tbl["ActivityDriven"]["bot_present"].value_or<bool>( false );

auto * bot_opinion = tbl["bot_opinion"].as_array();
auto * bot_m = tbl["bot_m"].as_array();
auto * bot_activity = tbl["bot_activity"].as_array();

for( size_t i = 0; i < model_activityDriven->n_bots; i++ )
{
model_activityDriven->bot_opinion.push_back( bot_opinion[i].value_or<double>( 0.0 ) );
model_activityDriven->bot_m.push_back( bot_m[i].value_or<size_t>( 0 ) );
model_activityDriven->bot_activity.push_back( bot_activity[i].value_or<double>( 0.0 ) );
}

model_activityDriven->get_agents_from_power_law();
model = std::move( model_activityDriven );
Expand Down

0 comments on commit 37975ab

Please sign in to comment.