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

Revision 1064, 2.2 kB (checked in by mido, 14 years ago)

astyle applied all over the library

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) {
36        name=name0;
37    }
38    //! Process data
39    virtual void adapt(const vec &glob_dt) {}
40    /*! create message -- use exclusively this function
41    Writes the following structure into \c msg:
42    \code
43    to = A1;                      // recepients
44    what = predictor;             // sort code
45    data = message_body;          // data itself
46    \endcode
47
48    */
49    void create_message(Setting &msg,const string &to, const string &what, const root &data) {
50        Setting &m_to=msg.add("to",Setting::TypeString);
51        m_to=to;
52        Setting &m_what=msg.add("what",Setting::TypeString);
53        m_what=what;
54        //Setting &m_data=msg.add("data",Setting::TypeGroup);
55        UI::save(&data, msg, "data");
56    }
57    /*! Broadcast communication to the others. Add message(s) to the provided queue.
58    */
59    virtual void broadcast(Setting& queue) {}
60    //! Receive one message from the queue
61    virtual void receive(const Setting& msg) {
62        bdm_warning("unhandled message");
63    }
64    //! Design control strategy
65    virtual void act(vec &glob_ut) {}
66    //! Time step
67    virtual void step() {}
68    //! read only name
69    void from_setting(const Setting& set) {
70        UI::get(name,set,"name",UI::compulsory);
71    }
72    void to_setting(Setting& set) const {
73        UI::save(name,set,"name");
74    }
75    //!access function
76    const string &_name() {
77        return name;
78    }
79    //! register data source where to get data
80    virtual void ds_register(const DS &ds) { }
81
82};
83
84}; //namespace
85
86#endif // PARTICIPANTS_H
Note: See TracBrowser for help on using the browser.