Changeset 932

Show
Ignore:
Timestamp:
05/11/10 00:12:39 (14 years ago)
Author:
ondrak
Message:

Extended negotiation cycle

Location:
applications/doprava
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/Zlicingw.cfg

    r927 r932  
    22        { // agent 1 
    33        class = "GreenWaveTrafficAgent"; 
    4                 name = "495"; 
    5                 lanes = ( 
     4        name = "495"; 
     5        lanes = ( 
    66                        { sg="VA"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); alpha= [1.0 ]; queue="495_Q1";},  
    77                        { sg="VB"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); alpha= [1.0 ]; queue="495_Q2";} 
    8               ); 
    9                 neighbours = ("601"); 
    10   offset = 40; //s 
    11   moje_special=14; 
     8        ); 
     9        neighbours = ("601"); 
     10        offset = 40; //s 
     11        moje_special=14; 
    1212}, 
    1313{ //agent 2 
    1414        class = "GreenWaveTrafficAgent"; 
    15   name = "601";   
    16                 neighbours = ("495"); 
     15        name = "601";   
     16        neighbours = ("495"); 
    1717} 
     18 
    1819); 
    1920 
    2021logger = {class="memlog"; filename = "zlicin"; maxlen = 1000;}; 
     22 
     23 
     24 
    2125 
    2226system = { 
     
    3236        // length is 24 hours (24:00:00). 
    3337        stop_time = "01:00:00"; 
     38         
    3439}; 
     40 
     41//Number of recieve/broadcast calls before end of negotitaion 
     42negotiation_cycles = 5; 
  • applications/doprava/main_loop.cpp

    r927 r932  
    2121int main ( int argc, char* argv[] ) { 
    2222        const char *fname; 
     23        int max_cycles=5; //max. number of sending/recieving during negotiation, changed to number from config file, if present (negotiation_cycles) 
     24 
    2325        if ( argc>1 ) {fname = argv[1]; } 
    2426        else { cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"<<endl; abort(); } 
     
    3537        shared_ptr<logger> L = UI::build <logger>( Cfg, "logger" ); 
    3638        if (!L) {L=new stdlog();} // DEFAULT LOGGER <== poor choice, use better ones 
     39 
     40 
    3741 
    3842        Config MsgStore; 
     
    6266        glob_ut[11] = 20; 
    6367 
     68        //LENGTH OF NEGOTIATION 
     69        UI::get(max_cycles,Cfg,"negotiation_cycles"); 
     70 
    6471        for ( int tK=0; tK < Ds->max_length(); tK++ ) { 
     72 
    6573                Ds->log_write ( ); // write stuff to  
    6674                Ds->getdata(glob_dt); 
    67                  
    6875                for ( int i=0; i<Ags.length(); i++ ) { 
    6976                        Ags(i) -> adapt(glob_dt); 
    7077                } 
    71                  
     78 
    7279                // NEGOTIATION CYCLE 
    73                 for ( int i=0; i<Ags.length(); i++ ) { 
    74                         Ags(i) -> broadcast(Queue); 
    75                 } 
    76                 //DBG 
    77                 MsgStore.writeFile("xxx"); 
    78                 // parse message queue 
    79                 for ( int m=Queue.getLength()-1; m>=0; m-- ) { // go backwards - last mesages are discarded 
    80                         for ( int i=0; i<Ags.length(); i++ ) { 
    81                                 Setting& msg=Queue[m]; 
    82                                 string m_to=msg["to"]; 
    83                                 if (m_to==Ags(i)->_name()) { 
    84                                         Ags(i)->receive(msg); 
    85                                         Queue.remove(m); 
    86                                         break; 
    87                                         // message delivered; 
     80                // ends when Queue is empty or after defined number of cycles 
     81                int cycle=0; 
     82                do { 
     83                        //DBG 
     84                        MsgStore.writeFile("xxx"); 
     85                        // parse message queue 
     86                        for ( int m=Queue.getLength()-1; m>=0; m-- ) { // go backwards - last mesages are discarded 
     87                                for ( int i=0; i<Ags.length(); i++ ) { 
     88                                        Setting& msg=Queue[m]; 
     89                                        string m_to=msg["to"]; 
     90                                        if (m_to==Ags(i)->_name()) { 
     91                                                Ags(i)->receive(msg); 
     92                                                Queue.remove(m); 
     93                                                break; 
     94                                                // message delivered; 
     95                                        } 
    8896                                } 
    8997                        } 
    90                 } 
    91                 if (Queue.getLength()>0){bdm_error("undelivered messages - probably unknown neighbours");} 
    92                  
     98                        if (Queue.getLength()>0){bdm_error("undelivered messages - probably unknown neighbours");} 
     99 
     100                        for ( int i=0; i<Ags.length(); i++ ) { 
     101                                Ags(i) -> broadcast(Queue); 
     102                        } 
     103 
     104                        cycle++; 
     105                }  
     106                while ((Queue.getLength()>0) && (cycle<max_cycles)); 
     107 
    93108                for ( int i=0; i<Ags.length(); i++ ) { 
    94109                        Ags(i) -> act(glob_ut); 
    95110                } 
    96                  
     111 
    97112                L->step(); 
    98113                Ds->write(glob_ut); 
    99114                Ds->step();                                                     // simulator step 
    100                  
     115 
    101116                for ( int i=0; i<Ags.length(); i++ ) { 
    102117                        Ags(i) -> log_write();