Changeset 932 for applications/doprava/main_loop.cpp
- Timestamp:
- 05/11/10 00:12:39 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/main_loop.cpp
r927 r932 21 21 int main ( int argc, char* argv[] ) { 22 22 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 23 25 if ( argc>1 ) {fname = argv[1]; } 24 26 else { cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"<<endl; abort(); } … … 35 37 shared_ptr<logger> L = UI::build <logger>( Cfg, "logger" ); 36 38 if (!L) {L=new stdlog();} // DEFAULT LOGGER <== poor choice, use better ones 39 40 37 41 38 42 Config MsgStore; … … 62 66 glob_ut[11] = 20; 63 67 68 //LENGTH OF NEGOTIATION 69 UI::get(max_cycles,Cfg,"negotiation_cycles"); 70 64 71 for ( int tK=0; tK < Ds->max_length(); tK++ ) { 72 65 73 Ds->log_write ( ); // write stuff to 66 74 Ds->getdata(glob_dt); 67 68 75 for ( int i=0; i<Ags.length(); i++ ) { 69 76 Ags(i) -> adapt(glob_dt); 70 77 } 71 78 72 79 // 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 } 88 96 } 89 97 } 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 93 108 for ( int i=0; i<Ags.length(); i++ ) { 94 109 Ags(i) -> act(glob_ut); 95 110 } 96 111 97 112 L->step(); 98 113 Ds->write(glob_ut); 99 114 Ds->step(); // simulator step 100 115 101 116 for ( int i=0; i<Ags.length(); i++ ) { 102 117 Ags(i) -> log_write();