root/library/bdm/base/participants.h @ 927

Revision 927, 2.0 kB (checked in by smidl, 14 years ago)

traffic agents -- pro BDM > r904

Line 
1/*!
2  \file
3  \brief Higher-level Objects - Participants
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#ifndef PARTICIPANTS_H
14#define PARTICIPANTS_H
15
16
17#include "bdmbase.h"
18#include "../base/user_info.h"
19
20namespace bdm {
21/*!
22* \brief Basic Participant
23
24This object is an active unit with name and capability to store results
25
26*/
27class Participant : public root {
28protected:
29        //! name - ID of the participant
30        string name;
31public:
32        //! Empty constructor
33        Participant(){}
34        //! set name
35        void set_name(const string &name0){name=name0;}
36        //! Process data
37        virtual void adapt(const vec &glob_dt){}
38        /*! create message -- use exclusively this function
39        Writes the following structure into \c msg:
40        \code
41        to = A1;                      // recepients
42        what = predictor;             // sort code
43        data = message_body;          // data itself
44        \endcode
45       
46        */
47        void create_message(Setting &msg,const string &to, const string &what, const root &data){
48                Setting &m_to=msg.add("to",Setting::TypeString);
49                m_to=to;
50                Setting &m_what=msg.add("what",Setting::TypeString);
51                m_what=what;
52                //Setting &m_data=msg.add("data",Setting::TypeGroup);
53                UI::save(&data, msg, "data");
54        }       
55        /*! Broadcast communication to the others. Add message(s) to the provided queue.
56        */
57        virtual void broadcast(Setting& queue){}
58        //! Receive one message from the queue
59        virtual void receive(const Setting& msg){
60                bdm_warning("unhandled message");
61        }
62        //! Design control strategy
63        virtual void act(vec &glob_ut){}
64        //! Time step
65        virtual void step(){}
66        //! read only name
67        void from_setting(const Setting& set){
68                UI::get(name,set,"name",UI::compulsory);
69        }
70        void to_setting(Setting& set) const {
71                UI::save(name,set,"name");
72        }
73        //!access function
74        const string &_name() {return name;}
75        //! register data source where to get data
76        virtual void ds_register(const DS &ds){ }
77       
78};
79
80}; //namespace
81
82#endif // PARTICIPANTS_H
Note: See TracBrowser for help on using the browser.