Show
Ignore:
Timestamp:
02/24/10 00:56:13 (14 years ago)
Author:
smidl
Message:

aimsunDS minor correction + improvements in Agents

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/traffic_agent.h

    r836 r840  
    2929//! detector fo incomming flow 
    3030class DetectorIn : public Detector{ 
    31         string from; // from agent 
     31        public: 
    3232        Array<string> to_sg; // to signal plans 
    3333        void from_setting(const Setting &set){ 
    3434                Detector::from_setting(set); 
    35                 UI::get(from,set,"from",UI::compulsory); 
    3635                UI::get(to_sg, set, "to_sg", UI::compulsory); 
    3736        } 
     
    7675                datalink data2out; 
    7776        public: 
    78                 SignalGroupHandler(SignalGroup *sg0, const string &agent_name):rv_det_data(){ 
    79                         sg=sg0; 
     77                void connect_sg(SignalGroup &sg0, const string &agent_name){ 
     78                        sg=&sg0; 
    8079                        for (int i=0;i<sg->detectors.length();i++){ 
    81                                 rv_det_data.add(RV(agent_name + sg->detectors(i).name, 1)); //TODO intensity occupancy 
     80                                rv_det_data.add(RV(agent_name +"_"+ sg->detectors(i).name, 2)); //TODO intensity occupancy 
    8281                        } 
    8382                         
     
    101100                datalink outdata2out; 
    102101        public: 
    103                 RequestHandler(RequestOut *rq0, const string &agent_name){ 
    104                         rq=rq0; 
     102                void connect_request(RequestOut &rq0, const string &agent_name){ 
     103                        rq=&rq0; 
    105104                        for (int i=0;i<rq->from.length();i++){ 
    106                                 rv.add(RV(agent_name + rq->from(i), 1)); //TODO intensity occupancy 
     105                                rv.add(RV(agent_name +"_"+ rq->from(i), 2)); //TODO intensity occupancy 
    107106                        } 
    108107                } 
     
    131130                //! description of broadcast dataind 
    132131                RV output_rv; 
    133                          
    134                 RV action_rv; 
    135                  
    136                 datalink_part action2ds; 
    137                  
     132                                         
    138133                //! output recepient 
    139134                Array<RequestOut> requests; 
    140135                Array<RequestHandler> request_handler; 
    141136                 
     137                //! action description 
     138                RV action_rv; 
     139                 
     140                datalink_part action2ds; 
     141                 
    142142        public: 
    143143                void validate(){ 
    144144                        // write internal checks if all was loaded OK 
     145                         
     146                        // set action variable == this is a feature of the agent! 
     147                        action_rv = RV(name+"_Tc", 1); // <======= example 
    145148                } 
    146149                void receive(const Setting &msg){ 
     
    150153                        if (what=="data"){ //  
    151154                                // field data  
    152                                 //! decription of detected data 
     155                                // extract decription of teh received datavector 
    153156                                shared_ptr<RV> rv=UI::build<RV>(msg,"rv",UI::compulsory); 
     157                                // find if it is needed 
    154158                                ivec ind=rv->dataind(input_rv); // position of rv in in_rv; 
    155                                 if (ind.length()>0){ //data belong here 
     159                                if (ind.length()>0){ //data are interesting 
    156160                                        vec dt; 
    157                                         UI::get(dt, msg, "value",UI::compulsory); 
     161                                        UI::get(dt, msg, "value",UI::compulsory); // get data 
    158162                                        set_subvector(input_data, ind,  dt); //check size? 
    159163                                }                                
     
    162166                        } 
    163167                } 
     168                void log_register(logger &L, const string &prefix){ 
     169                        root::log_register ( L, prefix ); 
     170                        logrec->ids.set_size(sg.length()+2); 
     171                        int i; 
     172                        for (i=0;i <sg.length(); i++) { 
     173                                logrec->ids(i)=logrec->L.add_vector(sgh(i).rv_det_data, ""); 
     174                        } 
     175                        logrec->ids(i)=logrec->L.add_vector(input_rv,"in_"); i++; 
     176                        logrec->ids(i)=logrec->L.add_vector(output_rv,"out_"); 
     177                } 
     178                void log_write() const { 
     179                        int i; 
     180                        for (i=0;i <sg.length(); i++) { 
     181                                logrec->L.log_vector(logrec->ids(i), sgh(i).det_data); 
     182                        } 
     183                        logrec->L.log_vector(logrec->ids(i),input_data); i++; 
     184                        logrec->L.log_vector(logrec->ids(i),output_data); i++; 
     185                } 
     186                 
    164187                void broadcast(Setting& set){ 
    165188                        // broadcast data to all neighbours 
     
    169192                                 
    170193                                // copy from create message 
     194                                // create msg with fields {to=..., what=data, rv=..., value = ...} 
    171195                                Setting &m_to=msg.add("to",Setting::TypeString); 
    172196                                m_to=requests(i).to; 
     
    181205                        } 
    182206                } 
    183                 void adapt(const vec &glob_dt){                  
     207                void adapt(const vec &glob_dt){ 
    184208                        // copy data from global vector to sSGHandlers 
    185209                        for (int i=0; i<sgh.length();i++){ 
     
    193217                                needs(i) = sgh(i).expected_load(); 
    194218                        } 
    195                         vec action = needs/sum(needs); // trivial stuff 
     219                        vec action; // trivial stuff 
    196220                        action2ds.filldown(action,glob_ut); 
    197221                } 
     
    199223                void ds_register(const DS &ds){ 
    200224                        for (int i=0; i<sgh.length(); i++){ 
    201                                 sgh(i).ds2data.set_connection(ds._drv(), sgh(i).rv_det_data); 
    202                         } 
    203                         action2ds.set_connection(action_rv, ds._urv()); 
     225                                sgh(i).ds2data.set_connection(sgh(i).rv_det_data, ds._drv()); 
     226                        } 
     227                        action2ds.set_connection( ds._urv(), action_rv); 
    204228                } 
    205229