Changeset 941

Show
Ignore:
Timestamp:
05/14/10 01:35:51 (14 years ago)
Author:
ondrak
Message:

greenwave agents sending and receiving some expectations
very basic expected_output counting in Lane_Handler

Location:
applications/doprava
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/Zlicingw.cfg

    r932 r941  
    99        neighbours = ("601"); 
    1010        offset = 40; //s 
     11        sgs=("VA","VB","VC","VD","VE","VF"); 
    1112        moje_special=14; 
    1213}, 
     
    1516        name = "601";   
    1617        neighbours = ("495"); 
     18        sgs=("VA","VB","VC","VD","VE"); 
    1719} 
    1820 
     
    3537        // simulation in our case starts always at 00:00:00. Default simulation 
    3638        // length is 24 hours (24:00:00). 
    37         stop_time = "01:00:00"; 
     39        stop_time = "00:05:00"; 
    3840         
    3941}; 
  • applications/doprava/traffic_agent.cpp

    r927 r941  
    1414 
    1515double LaneHandler::expected_output(double green_time){ 
     16        double last_inputs=0.0; 
     17 
    1618        agentin2input.filldown(agent->inputs, inputs); 
    1719        queue = agent->queues(queue_index); 
    1820         
    1921        double exp_output=0.0; 
     22         
    2023        ///////// 
    21          
    22          
     24        //Velmi jednoduchy odhad 
     25        agentin2input.filldown(agent->inputs,inputs); 
     26 
     27                for (int i=0;i<inputs.length();i+=2) { 
     28                last_inputs+=inputs(i); 
     29        } 
     30 
     31        exp_output=last_inputs*(green_time/agent->step_time); 
     32 
    2333        //////// 
    2434        return exp_output; 
  • applications/doprava/traffic_agent.h

    r927 r941  
    107107                RV rv_queues; 
    108108                 
    109                 //! datalink from DS to output variables 
     109                //! datalink from DS to input variables 
    110110                datalink ds2inputs; 
    111111 
    112112                //! datalink from DS to output variables 
    113113                datalink ds2queues; 
    114                  
     114 
    115115                //! action description 
    116116                RV action_rv; 
     
    123123                 
    124124                Array<datalink> output2neighbour; 
     125 
     126                //! simulator's step length in seconds 
     127                int step_time; 
     128 
     129                //! lenght of cycle in seconds 
     130                int cycle_time; 
    125131                 
    126132        public: 
    127133                void validate(){ 
     134                        //TODO Tohle asi ne 
     135                        step_time=90; 
     136                        cycle_time=80; 
     137                         
    128138                        lanehs.set_length(lanes.length()); 
    129139                        for (int l=0; l<lanes.length(); l++){ 
     
    211221                        // copy data from global vector to sSGHandlers 
    212222                        ds2inputs.filldown(glob_dt, inputs); 
    213                         //copy data fro neighbours 
     223                        //copy data from neighbours 
    214224                        ds2queues.filldown(glob_dt, queues); 
    215225                        // copy sg_length ... and others... 
     
    224234                        ds2inputs.set_connection(rv_inputs, ds._drv()); 
    225235                        ds2queues.set_connection(rv_queues, ds._drv()); 
     236                         
    226237                        inputs.set_size(rv_inputs._dsize()); 
    227238                        action2ds.set_connection( ds._urv(), action_rv); 
     239 
    228240                } 
    229241                 
  • applications/doprava/traffic_agent_offset.h

    r927 r941  
     1#include <map> 
     2 
    13class GreenWaveTrafficAgent : public BaseTrafficAgent { 
    24protected: 
    35        double stable_state_loss; 
     6        double best_offset; 
     7        map<string,double> expected; 
     8        map<string,double>::iterator expected_i; 
    49         
    5         double best_offset; 
     10        //counts all expected cars to "dest" 
     11        double expected_cars(const string dest) { 
     12 
     13                double expected=0.0; 
     14 
     15                //finds lanes which lead to "dest" 
     16                for (int i=0;i<lanes.length();i++) { 
     17                        for (int j=0;j<lanes(i).outputs.length();j++) { 
     18                                if (lanes(i).outputs(j).substr(0,3)==dest) { 
     19                                        //we have some matching outputs, count cars 
     20                                        string group = name+"_"+lanes(i).sg; 
     21                                        ivec index=rv_greentimes.dataind(RV(group,1)); 
     22                                        vec green_time=greentimes(index); 
     23 
     24                                        expected+=lanehs(i)->expected_output(green_time(0)); 
     25                                         
     26                                } 
     27                        } 
     28                } 
     29                return expected; 
     30        } 
     31 
    632public: 
     33        datalink ds2greentimes; 
     34        vec greentimes; 
     35        RV rv_greentimes; 
     36         
     37        //! array of existing signal groups 
     38        Array<string> sgs; 
     39 
    740        void validate() { 
    841                BaseTrafficAgent::validate(); 
    942                action_rv = RV(name+"_offset", 1); // <======= example 
     43 
     44                for (int i=0; i<sgs.length();i++) { 
     45                        rv_greentimes.add(RV(name+"_"+sgs(i),1)); 
     46                } 
    1047        } 
    11         void GreeWaveTrafficAgent(); 
     48 
     49        void adapt(const vec &glob_dt) { 
     50                BaseTrafficAgent::adapt(glob_dt); 
     51                                 
     52                ds2greentimes.filldown(glob_dt,greentimes); 
     53        } 
     54 
     55        void broadcast(Setting& set){ 
     56                         
     57                //ask neighbours for exptected arrive times 
     58                if (true) { 
     59                        for (int i=0; i<neighbours.length(); i++){ 
     60                                Setting &msg =set.add(Setting::TypeGroup); 
     61 
     62                                UI::save ( neighbours(i), msg, "to"); 
     63                                UI::save (name,msg,"from"); 
     64                                UI::save ( (string)"expected_times_request", msg, "what"); 
     65                        } 
     66                } 
     67 
     68 
     69                // broadcast expected cars 
     70                while (!expected.empty()) { 
     71                        expected_i=expected.begin(); 
     72 
     73                        Setting &msg =set.add(Setting::TypeGroup); 
     74 
     75                        UI::save ( expected_i->first, msg, "to"); 
     76                        UI::save ( name, msg, "from"); 
     77                        UI::save ( (string)"new_expected_cars", msg, "what"); 
     78                        //UI::save ( &(rv_neighbours_out(i)), msg, "rv"); 
     79                        UI::save(expected_i->second, msg, "value"); 
     80                        expected.erase(expected_i); 
     81                } 
     82 
     83        } 
     84 
     85        void receive(const Setting &msg){ 
     86                string what; 
     87                string to; 
     88                string from; 
     89                double value; 
     90                 
     91 
     92                UI::get(what, msg, "what", UI::compulsory); 
     93                UI::get(to, msg, "to", UI::compulsory); 
     94                UI::get(from, msg, "from"); 
     95                UI::get(value, msg, "value"); 
     96                if (what=="expected_times_request"){   
     97                        expected[from]=expected_cars(from); 
     98                }  
     99                else if (what=="new_expected_cars") { 
     100                        cout << "Jsem "<< name << " a dostal jsem od "<< from << " predpoklad: " << value << endl; 
     101                        //expected=0; 
     102                } 
     103                else { 
     104                        BaseTrafficAgent::receive(msg); 
     105                } 
     106        } 
     107         
     108        void ds_register(const DS &ds) { 
     109                BaseTrafficAgent::ds_register(ds); 
     110                ds2greentimes.set_connection(rv_greentimes, ds._drv()); 
     111        } 
     112 
     113        void from_setting(const Setting &set) { 
     114                BaseTrafficAgent::from_setting(set); 
     115                        // load from file 
     116                 
     117                UI::get(sgs, set, "sgs", UI::compulsory);        
     118         
     119        } 
    12120}; 
    13121UIREGISTER(GreenWaveTrafficAgent);