Changeset 986

Show
Ignore:
Timestamp:
05/25/10 23:53:49 (14 years ago)
Author:
ondrak
Message:

added queues 601_Q1 and 601_Q2 to aimsun_ds.cpp
added function to count expected_density to LaneHandler?
added compulsory input_distances and output_distances to cfg
action_rv renamed to rv_action (to match convention)
some work on GreenWaveTrafficAgent?

Location:
applications/doprava
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/Zlicingw.cfg

    r941 r986  
    44        name = "495"; 
    55        lanes = ( 
    6                         { sg="VA"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); alpha= [1.0 ]; queue="495_Q1";},  
    7                         { sg="VB"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); alpha= [1.0 ]; queue="495_Q2";} 
     6                        { sg="VA"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q1";},  
     7                        { sg="VB"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVB"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q2";} 
    88        ); 
    99        neighbours = ("601"); 
    10         offset = 40; //s 
     10        offset = 10; //s 
    1111        sgs=("VA","VB","VC","VD","VE","VF"); 
     12        green_starts=[72,4,5,35,36,71]; 
    1213        moje_special=14; 
    1314}, 
    1415{ //agent 2 
    1516        class = "GreenWaveTrafficAgent"; 
    16         name = "601";   
     17        name = "601"; 
     18        lanes = ( 
     19                        { sg="VA"; inputs = ("601_DVA","601_DVB");  outputs= ("495_DVA"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q1";},  
     20                        { sg="VB"; inputs = ("601_DVC","601_DVD");  outputs= ("495_DVB"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";} 
     21        );   
    1722        neighbours = ("495"); 
    18         sgs=("VA","VB","VC","VD","VE"); 
     23        offset = 40; 
     24        sgs=("VA","VB","VC","VD","VE","SE"); 
     25        green_starts=[54,9,26,25,9,9]; 
    1926} 
    2027 
     
    4148}; 
    4249 
    43 //Number of recieve/broadcast calls before end of negotitaion 
     50//Number of recieve/broadcast calls before end of negotiation 
    4451negotiation_cycles = 5; 
  • applications/doprava/aimsun_bdm/aimsun_ds.cpp

    r927 r986  
    5757    "601_S6  601_S6a  601_S7   601_S8   601_S9   601_S9a " 
    5858    "495_Q1 495_Q2 " 
     59        "601_Q1 601_Q2 " 
    5960    "}", 
    6061        "    1,      1,      1,      1,      1,       1,      " 
     
    6465        "    2,      2,      2,      2,      2,       2,       2,       2,       2,       2,       2,       2," 
    6566        "    2,      2,      2,      2,      2,       2" 
     67        "    1,      1" 
    6668        "    1,      1" 
    6769        ); 
  • applications/doprava/traffic_agent.cpp

    r941 r986  
    1515double LaneHandler::expected_output(double green_time){ 
    1616        double last_inputs=0.0; 
     17         
     18 
    1719 
    1820        agentin2input.filldown(agent->inputs, inputs); 
     
    2224         
    2325        ///////// 
    24         //Velmi jednoduchy odhad 
     26         
    2527        agentin2input.filldown(agent->inputs,inputs); 
    2628 
    27                 for (int i=0;i<inputs.length();i+=2) { 
     29        for (int i=0;i<inputs.length();i+=2) { 
    2830                last_inputs+=inputs(i); 
    2931        } 
     
    3537} 
    3638 
     39double LaneHandler::expected_density() { 
     40        double density=0.0; 
     41 
     42        agentin2input.filldown(agent->inputs,inputs); 
     43         
     44        for (int i=0;i<inputs.length();i+=2) { 
     45                density+=inputs(i)/agent->step_time; 
     46        } 
     47 
     48        return density; 
     49} 
    3750 
    3851void BaseTrafficAgent::from_setting(const Setting& set) 
    3952{ 
    40     bdm::Participant::from_setting(set); 
     53        step_time=90; 
     54        cycle_time=80; 
     55 
     56        bdm::Participant::from_setting(set); 
    4157         
    4258        // load from file 
  • applications/doprava/traffic_agent.h

    r941 r986  
    2020                Array<string> inputs; 
    2121                Array<string> outputs; 
     22                vec input_distances; 
     23                vec output_distances; 
    2224                vec alpha; //size of outputs 
    2325                string queue; 
     
    2830                        UI::get(inputs,set,"inputs",UI::compulsory); 
    2931                        UI::get(outputs,set,"outputs",UI::compulsory); 
     32                        UI::get(input_distances,set,"input_distances",UI::compulsory); 
     33                        UI::get(output_distances,set,"output_distances",UI::compulsory); 
    3034                        UI::get(alpha,set,"alpha",UI::compulsory); 
    3135                        UI::get(queue,set,"queue",UI::compulsory); 
     
    6165                //! 
    6266                int queue_index; 
     67 
    6368        public: 
    6469                LaneHandler(const Lane &lane0): lane(lane0){ 
     
    7075                        } 
    7176                        rv_queue.add(RV(lane.queue, 1));  
    72                 } 
     77                        inputs.set_size(rv_inputs._dsize()); 
     78                } 
     79                 
    7380                 
    7481                void connect_data(BaseTrafficAgent &agent0); 
    75                  
     82 
     83                //! computes expected density in cars/s 
     84                double expected_density(); 
     85 
    7686                //! arbitrary function that computes the need of the signal group for green light in common units (number of waiting cars?) 
    7787                double expected_output(double green_time); 
     
    114124 
    115125                //! action description 
    116                 RV action_rv; 
     126                RV rv_action; 
    117127                                 
    118128                datalink_part action2ds; 
     
    132142        public: 
    133143                void validate(){ 
    134                         //TODO Tohle asi ne 
    135                         step_time=90; 
    136                         cycle_time=80; 
    137144                         
    138145                        lanehs.set_length(lanes.length()); 
     
    236243                         
    237244                        inputs.set_size(rv_inputs._dsize()); 
    238                         action2ds.set_connection( ds._urv(), action_rv); 
     245                        action2ds.set_connection( ds._urv(), rv_action); 
    239246 
    240247                } 
  • applications/doprava/traffic_agent_offset.cpp

    r921 r986  
    1 #include <base/participants.h> 
     1#include "traffic_agent_offset.h" 
  • applications/doprava/traffic_agent_offset.h

    r941 r986  
    1 #include <map> 
     1#include "traffic_agent.h" 
     2#include <list> 
    23 
    34class GreenWaveTrafficAgent : public BaseTrafficAgent { 
     
    56        double stable_state_loss; 
    67        double best_offset; 
    7         map<string,double> expected; 
    8         map<string,double>::iterator expected_i; 
    9          
    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" 
     8 
     9        RV rv_recieved_exps; 
     10        vec recieved_exps; 
     11         
     12        list<string> seznam; 
     13         
     14 
     15        double car_leaving; //s; how long is 1 car leaving queue 
     16 
     17        bool recieved_exp_request; 
     18                         
     19        //counts all expected cars going from each lane 
     20        void expected_cars(/*const string dest*/) { 
     21                double start_time; 
     22 
    1623                for (int i=0;i<lanes.length();i++) { 
    1724                        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; 
     25                                //              if (lanes(i).outputs(j).substr(0,3)==dest) { 
     26                                // 
     27                                string group = name+"_"+lanes(i).sg;            //e.g. 495_VA 
     28                                ivec index=rv_inputs.dataind(RV(group,1)); 
     29                                vec green_time=inputs(index); 
     30 
     31 
     32                                rv_outputs.add(RV(lanes(i).outputs(j)+"-"+group,3)); 
     33                                outputs.set_size(rv_outputs._dsize()); 
     34 
     35                                ivec indexes = rv_outputs.dataind(RV(lanes(i).outputs(j)+"-"+group,3)); 
     36 
     37                                //Number of cars 
     38                                outputs(indexes(0))=lanehs(i)->expected_output(green_time(0));   
     39 
     40                                start_time = green_starts(sg_index(lanes(i).sg)) + lanes(i).output_distances(j)/VP + planned_offset; 
     41                                //first car arrive time 
     42                                outputs(indexes(1))=start_time;                                                                  
     43                                //last car arrive time 
     44                                outputs(indexes(2))= start_time + green_time(0); 
     45 
     46                                //} 
     47                        } 
     48                } 
    3049        } 
    3150 
    3251public: 
    33         datalink ds2greentimes; 
    34         vec greentimes; 
    35         RV rv_greentimes; 
     52        int last_offset; 
     53        int planned_offset; 
     54        double actual_rating; 
    3655         
    3756        //! array of existing signal groups 
    3857        Array<string> sgs; 
     58        //! relative starts of green for signal groups 
     59        ivec green_starts; 
     60 
     61        //! avarage speed of cars 
     62        int VP; 
    3963 
    4064        void validate() { 
     65                rv_action = RV(name+"_offset", 1); // <======= example 
     66 
     67                for (int i=0; i<sgs.length();i++) { 
     68                        rv_inputs.add(RV(name+"_"+sgs(i),1)); 
     69                         
     70                        //place for expected inputs 
     71                        //rv_expected_traffic.add(RV(name+"_"+sgs(i)+"_exp",3)); 
     72                } 
     73 
     74                inputs.set_size(rv_inputs._dsize()); 
     75                //expected_traffic.set_size(rv_expected_traffic._dsize()); 
     76                 
    4177                BaseTrafficAgent::validate(); 
    42                 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                 } 
     78        } 
     79 
     80        //! returns index of signal group sg 
     81        int sg_index(string sg) { 
     82                for (int i=0;i<sgs.length();i++) { 
     83                        if (sgs(i)==sg) { 
     84                                return i; 
     85                        } 
     86                } 
     87                return -1; 
    4788        } 
    4889 
    4990        void adapt(const vec &glob_dt) { 
    5091                BaseTrafficAgent::adapt(glob_dt); 
    51                                  
    52                 ds2greentimes.filldown(glob_dt,greentimes); 
    53         } 
     92 
     93                planned_offset=last_offset; 
     94        } 
     95        //! counts actual rating using planned_offset and recieved_exps 
     96        void count_rating() { 
     97                double virtual_queue; 
     98                double t_emptiyng; 
     99                double t_green_begin; 
     100                double t_green_end; 
     101                double t_cars_begin; 
     102                double t_cars_end; 
     103                double t_mixing; 
     104                bool found; 
     105 
     106                actual_rating=0.0; 
     107 
     108                for (int i=0;i<lanehs.length();i++) { 
     109 
     110                        //Finding, if we have some expectations 
     111                        found=false; 
     112                        for (int j=0;j<rv_recieved_exps.length();j++) { 
     113                                for (int k=0;k<lanes(i).inputs.length();k++) { 
     114                                        int result=rv_recieved_exps.name(j).find(lanes(i).inputs(k)+"-"); 
     115                                        if (result>=0) { 
     116                                                ivec indexes = rv_recieved_exps.dataind(RV(rv_recieved_exps.name(j),3)); 
     117 
     118                                                t_cars_begin=recieved_exps(indexes(1)); 
     119                                                t_cars_end=recieved_exps(indexes(2)); 
     120                                                found=true; 
     121                                        } 
     122                                } 
     123                        } 
     124                        if (!found) { 
     125                                t_cars_begin=0; 
     126                                t_cars_end=cycle_time; 
     127                        } 
     128 
     129                        //counting rating 
     130                        t_green_begin=green_starts(sg_index(lanes(i).sg)) + planned_offset; 
     131                        ivec indexes = rv_inputs.dataind(RV(name+"_"+lanes(i).sg,1)); 
     132                        t_green_end=t_green_begin+inputs(indexes(0)); 
     133 
     134                        if (t_green_begin<t_cars_begin) { 
     135                                virtual_queue=lanehs(i)->queue-(t_cars_begin-t_green_begin)/car_leaving; 
     136                        }  
     137                        else if (t_green_begin>t_cars_begin) { 
     138                                virtual_queue=lanehs(i)->queue+(t_green_begin-t_cars_begin)*lanehs(i)->expected_density(); 
     139                        } 
     140                        //TODO lanehs(i)->queue je zatim prazdne => nesmyslne vysledky 
     141 
     142                        t_emptiyng=virtual_queue/(1/car_leaving - lanehs(i)->expected_density()); 
     143                        t_mixing=min(t_green_end,t_cars_end)-max(t_green_begin,t_cars_begin); 
     144 
     145                        actual_rating+=max((t_mixing-t_emptiyng)*lanehs(i)->expected_density(),0.0);   
     146                } 
     147        } 
     148 
    54149 
    55150        void broadcast(Setting& set){ 
     
    68163 
    69164                // 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); 
     165                if (!seznam.empty()) { 
     166                        do { 
     167                                vec value; 
     168                                 
     169                                expected_cars(); 
     170                                Setting &msg =set.add(Setting::TypeGroup); 
     171                                UI::save ( seznam.back(), msg, "to"); 
     172                                UI::save ( name, msg, "from"); 
     173                                UI::save ( (string)"new_expected_cars", msg, "what"); 
     174                                UI::save ( &(rv_outputs), msg, "rv"); 
     175                                UI::save ( outputs, msg, "value"); 
     176                                seznam.pop_back(); 
     177 
     178                        } while (!seznam.empty()); 
     179                         
    81180                } 
    82181 
     
    87186                string to; 
    88187                string from; 
    89                 double value; 
    90                  
    91  
     188                vec value; 
     189                RV *rv; 
     190                 
    92191                UI::get(what, msg, "what", UI::compulsory); 
    93192                UI::get(to, msg, "to", UI::compulsory); 
    94193                UI::get(from, msg, "from"); 
     194                UI::get(rv, msg, "rv"); 
    95195                UI::get(value, msg, "value"); 
    96                 if (what=="expected_times_request"){   
    97                         expected[from]=expected_cars(from); 
     196                if (what=="expected_times_request"){  
     197                        recieved_exp_request=true; 
     198                        seznam.push_back(from); 
     199 
    98200                }  
    99201                else if (what=="new_expected_cars") { 
    100                         cout << "Jsem "<< name << " a dostal jsem od "<< from << " predpoklad: " << value << endl; 
    101                         //expected=0; 
     202                        rv_recieved_exps=*rv; 
     203                        recieved_exps=value; 
     204                        count_rating(); 
     205                        //TODO skutecne vyjednavani 
    102206                } 
    103207                else { 
     
    108212        void ds_register(const DS &ds) { 
    109213                BaseTrafficAgent::ds_register(ds); 
    110                 ds2greentimes.set_connection(rv_greentimes, ds._drv()); 
     214                action2ds.set_connection( ds._urv(), rv_action); 
     215 
    111216        } 
    112217 
    113218        void from_setting(const Setting &set) { 
    114219                BaseTrafficAgent::from_setting(set); 
    115                         // load from file 
    116                  
     220                 
     221                car_leaving=2; 
     222                VP=45; 
     223                recieved_exp_request=false; 
     224                 
     225                // load from file 
    117226                UI::get(sgs, set, "sgs", UI::compulsory);        
    118          
    119         } 
     227                UI::get(green_starts, set, "green_starts", UI::compulsory); 
     228                UI::get(last_offset, set, "offset", UI::compulsory); 
     229         
     230        } 
     231        void act(vec &glob_ut){ 
     232                vec action; 
     233                action.set_size(rv_action._dsize()); 
     234                 
     235                ivec index = rv_action.dataind(RV(name+"_offset",1)); 
     236                action(index(0))=planned_offset; 
     237 
     238                action2ds.filldown(action,glob_ut); 
     239        } 
     240 
    120241}; 
    121242UIREGISTER(GreenWaveTrafficAgent);