FRED
Behavior.h
00001 /*
00002   Copyright 2009 by the University of Pittsburgh
00003   Licensed under the Academic Free License version 3.0
00004   See the file "LICENSE" for more information
00005 */
00006 
00007 //
00008 //
00009 // File: Behavior.h
00010 //
00011 
00012 #ifndef _FRED_BEHAVIOR_H
00013 #define _FRED_BEHAVIOR_H
00014 
00015 #include <stdio.h>
00016 #include <vector>
00017 
00018 class Person;
00019 class Attitude;
00020 class Household;
00021 
00022 enum Behavior_strategy {REFUSE, ACCEPT, FLIP, IMITATE_PREVALENCE, IMITATE_CONSENSUS, IMITATE_COUNT, HBM};
00023 #define BEHAVIOR_STRATEGIES 7
00024 #define NUMBER_WEIGHTS 7
00025 
00026 typedef struct {
00027   // COMMON
00028   char name[32];
00029   int first;
00030   int enabled;
00031   int frequency;
00032   int strategy_cdf_size;
00033   double strategy_cdf[BEHAVIOR_STRATEGIES];
00034   int strategy_dist[BEHAVIOR_STRATEGIES];
00035   // FLIP
00036   double min_prob;
00037   double max_prob;
00038   // IMITATE params
00039   int imitation_enabled;
00040   // IMITATE PREVALENCE
00041   double imitate_prevalence_weight[NUMBER_WEIGHTS];
00042   double imitate_prevalence_total_weight;
00043   double imitate_prevalence_update_rate;
00044   double imitate_prevalence_threshold;
00045   int imitate_prevalence_count;
00046   // IMITATE CONSENSUS
00047   double imitate_consensus_weight[NUMBER_WEIGHTS];
00048   double imitate_consensus_total_weight;
00049   double imitate_consensus_update_rate;
00050   double imitate_consensus_threshold;
00051   int imitate_consensus_count;
00052   // IMITATE COUNT
00053   double imitate_count_weight[NUMBER_WEIGHTS];
00054   double imitate_count_total_weight;
00055   double imitate_count_update_rate;
00056   double imitate_count_threshold;
00057   int imitate_count_count;
00058   // HBM
00059   double susceptibility_threshold_distr[2];
00060   double severity_threshold_distr[2];
00061   double benefits_threshold_distr[2];
00062   double barriers_threshold_distr[2];
00063   double memory_decay_distr[2];
00064   double base_odds_ratio;
00065   double susceptibility_odds_ratio;
00066   double severity_odds_ratio;
00067   double benefits_odds_ratio;
00068   double barriers_odds_ratio;
00069 } Behavior_params;
00070 
00071 typedef struct {
00072   int * yes_responses;
00073   int * total_responses;
00074   int yes;
00075   int total;
00076   int * previous_yes_responses;
00077   int * previous_total_responses;
00078   int previous_yes;
00079   int previous_total;
00080   int last_update;
00081 } Behavior_survey;
00082 
00083 
00084 class Behavior {
00085 
00086 public:
00087 
00092   Behavior(Person *p);
00093   ~Behavior();
00094   void initialize_adult_behavior(Person * person);
00095 
00101   void update(int day);
00102 
00103   bool adult_is_staying_home(int day);
00104   bool adult_is_taking_sick_leave(int day);
00105   bool child_is_staying_home(int day);
00106   bool acceptance_of_vaccine();
00107   bool acceptance_of_another_vaccine_dose();
00108   bool child_acceptance_of_vaccine();
00109   bool child_acceptance_of_another_vaccine_dose();
00110   void set_adult_decision_maker(Person * person) { adult_decision_maker = person; }
00111   Person * get_adult_decision_maker() { return adult_decision_maker; }
00112   void select_adult_decision_maker(Person *unavailable_person);
00113   void terminate();
00114 
00115 private:
00116   Person * self;
00117   Person * adult_decision_maker;
00118   void get_parameters();
00119   void get_parameters_for_behavior(char * behavior_name, Behavior_params * par);
00120   Attitude * setup(Person * self, Behavior_params * params, Behavior_survey * survey);
00121   void report_distribution(Behavior_params * params);
00122   Person * select_adult(Household *h, int relationship, Person * unavailable_person);
00123   
00124   Attitude * take_sick_leave;
00125   Attitude * stay_home_when_sick;
00126   Attitude * keep_child_home_when_sick;
00127   Attitude * accept_vaccine;
00128   Attitude * accept_vaccine_dose;
00129   Attitude * accept_vaccine_for_child;
00130   Attitude * accept_vaccine_dose_for_child;
00131 
00132   static bool parameters_are_set;
00133   static int number_of_vaccines;
00134 
00135   // run-time parameters for behaviors
00136   static Behavior_params stay_home_when_sick_params;
00137   static Behavior_params take_sick_leave_params;
00138   static Behavior_params keep_child_home_when_sick_params;
00139   static Behavior_params accept_vaccine_params;
00140   static Behavior_params accept_vaccine_dose_params;
00141   static Behavior_params accept_vaccine_for_child_params;
00142   static Behavior_params accept_vaccine_dose_for_child_params;
00143   
00144   static Behavior_survey stay_home_when_sick_survey;
00145   static Behavior_survey take_sick_leave_survey;
00146   static Behavior_survey keep_child_home_when_sick_survey;
00147   static Behavior_survey accept_vaccine_survey;
00148   static Behavior_survey accept_vaccine_dose_survey;
00149   static Behavior_survey accept_vaccine_for_child_survey;
00150   static Behavior_survey accept_vaccine_dose_for_child_survey;
00151   
00152 };
00153 
00154 inline
00155 void Behavior::report_distribution(Behavior_params * params) {
00156   if (params->first) {
00157     printf("BEHAVIOR %s dist: ", params->name);
00158     for (int i = 0; i < BEHAVIOR_STRATEGIES; i++) {
00159       printf("%d ", params->strategy_dist[i]);
00160     }
00161     printf("\n"); fflush(stdout);
00162     params->first = 0;
00163   }
00164 }
00165 
00166 #endif // _FRED_BEHAVIOR_H
00167 
 All Classes Functions