Changeset 840 for applications/doprava

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

aimsunDS minor correction + improvements in Agents

Location:
applications/doprava
Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/CMakeLists.txt

    r831 r840  
    1919add_library(traffic_agents traffic_agent.cpp traffic_agent.h) 
    2020 
     21IF(WIN32) 
    2122include_directories ( aimsun_bdm/eh_api aimsun_bdm/els3/include aimsun_bdm/vgs_api ) 
    22 # executable 
    23 EXEC(main_loop traffic_agents aimsun_bdm eh_api vgs_api) 
     23        # executable 
     24        EXEC(main_loop traffic_agents aimsun_bdm eh_api vgs_api) 
     25ELSE(WIN32) 
     26        EXEC(main_loop aimsun_bdm traffic_agents ) 
     27ENDIF(WIN32) 
    2428 
     29 
  • applications/doprava/Zlicin.cfg

    r836 r840  
    1717  input = ( // remote detectors  
    1818    { 
    19       name = "601DVA1"; 
     19      name = "601_DVA1"; 
    2020                distance = 100; 
    2121      to_sg = ("VC","VD"); 
    2222    }, 
    2323    { 
    24       name = "601DVA"; 
     24      name = "601_DVA"; 
    2525                distance = 100; 
    2626      to_sg = ("VC","VD"); 
     
    3030     { 
    3131      from = ("VC"); 
    32                 detector ="495DVC"; 
     32                detector = "495_DVC"; 
    3333      to = "601"; 
    3434      } 
     
    4444    { name = "VA"; 
    4545      detectors = ( 
    46                 { name = "DVA1"; distance = 10; },  
    47                  {name = "DVA"; distance = 20; } 
     46                { name = "DVA"; distance = 10; },  
     47                 {name = "DVAa"; distance = 20; } 
    4848      ); 
    4949    },  
  • applications/doprava/aimsun_bdm/CMakeLists.txt

    r830 r840  
    11# Simulator library 
    2 add_subdirectory(eh_api) 
    3 add_subdirectory(vgs_api) 
     2IF(WIN32) 
     3        add_subdirectory(eh_api) 
     4        add_subdirectory(vgs_api) 
    45 
    5 include_directories(./els3/include ./eh_api ./vgs_api) 
    6 add_definitions(-DBASE_PATH="${CMAKE_CURRENT_SOURCE_DIR}") 
    7 add_library (aimsun_bdm aimsun_ds.cpp aimsun_ds.h tools.cpp tools.h) 
     6        include_directories(./els3/include ./eh_api ./vgs_api) 
     7        add_definitions(-DBASE_PATH="${CMAKE_CURRENT_SOURCE_DIR}") 
     8        add_library (aimsun_bdm aimsun_ds.cpp aimsun_ds.h tools.cpp tools.h) 
     9ELSE(WIN32) 
     10        add_library (aimsun_bdm aimsun_fake.cpp aimsun_fake.h) 
     11endif(WIN32) 
  • applications/doprava/aimsun_bdm/aimsun_ds.h

    r829 r840  
    4040    //! Wait for new data and copy them out to local buffers 
    4141    void step(); 
    42  
     42         
     43        //! number of steps 
     44        int max_length() {return 960;} 
     45         
    4346    // TODO dodelat void to_setting( Setting &root ) const; 
    4447private: 
  • applications/doprava/main_loop.cpp

    r836 r840  
    99#include "base/user_info.h" 
    1010#include "base/loggers.h" 
     11#ifdef _WIN32 
    1112#include "aimsun_bdm/aimsun_ds.h" 
     13#else  
     14#include "aimsun_bdm/aimsun_fake.h" 
     15#endif 
    1216#include "traffic_agent.h" 
    1317 
     
    6771                        Ags(i) -> broadcast(Queue); 
    6872                } 
     73                //DBG 
     74                MsgStore.writeFile("xxx"); 
    6975                // parse message queue 
    7076                for ( int m=Queue.getLength()-1; m>=0; m-- ) { // go backwards - last mesages are discarded 
     
    9197                 
    9298                for ( int i=0; i<Ags.length(); i++ ) { 
     99                        Ags(i) -> log_write(); 
    93100                        Ags(i) -> step(); 
    94101                } 
  • applications/doprava/traffic_agent.cpp

    r820 r840  
    1414    bdm::Participant::from_setting(set); 
    1515         
     16        // load from file 
    1617        UI::get(sg,set,"sg", UI::compulsory); 
    1718        UI::get(requests,set,"output",UI::compulsory); 
     19        Array<DetectorIn> det_in; 
     20        UI::get(det_in, set, "input",UI::compulsory); 
     21         
     22        // process sg == create handles 
     23        sgh.set_length(sg.length()); 
     24        for(int i=0;i<sg.length();i++){ 
     25                sgh(i).connect_sg(sg(i),name); 
     26        } 
     27         
     28        // process output == handles 
     29        request_handler.set_length(requests.length()); 
     30        for(int i=0;i<requests.length();i++){ 
     31                request_handler(i).connect_request(requests(i),name); 
     32                output_rv.add(request_handler(i).rv); 
     33        } 
     34        // connect 
     35        for(int i=0;i<requests.length();i++){ 
     36                request_handler(i).outdata2out.set_connection(request_handler(i).rv, output_rv); 
     37                // search teh right section == probably inefficient 
     38/*              int j; 
     39                for (j=0;j<sg.length();j++){ 
     40                        if (sg(i).name==requests(i).from){ 
     41                                sgh(i).data2out.set_connection(output_rv, sgh(i).det_data); 
     42                                break; 
     43                        } 
     44                }*/ 
     45        } 
     46         
     47        // process DetIn - create input 
     48        for (int i=0; i<det_in.length(); i++){ 
     49                input_rv.add(RV(det_in(i).name,2)); 
     50        } 
     51        input_data.set_size(input_rv._dsize()); 
    1852} 
  • 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