Changeset 1081 for applications/doprava
- Timestamp:
- 06/11/10 00:37:01 (15 years ago)
- Location:
- applications/doprava
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/Zlicingw.cfg
r1074 r1081 54 54 // simulation in our case starts always at 00:00:00. Default simulation 55 55 // length is 24 hours (24:00:00). 56 stop_time = "0 1:00:00";56 stop_time = "00:15:00"; 57 57 58 58 }; -
applications/doprava/traffic_agent_offset.h
r1071 r1081 28 28 string accepted_from; 29 29 30 //TODO currently useless list of neighbours asking for expectations 30 31 list<string> seznam; 31 32 32 33 double car_leaving; //s; how long is 1 car leaving queue 33 34 35 // some state variables 34 36 bool need_exps; 35 37 bool new_stable_state; … … 37 39 bool final_state; 38 40 //bool reset_negot_offset; 41 42 //! sum of final planned_offset values since last reach of cycle_count 43 int total_offset; 44 //! number of finished cycles since last reach of cycle_count 45 int negot_cycle; 46 //! after cycle_count cycles, we count avarege planned_offseta send it to Aimsun 47 int cycle_count; 39 48 40 49 //! counts all expected cars going from each lane, saves to outputs and rv_outputs … … 95 104 RV rv_vector; 96 105 vec vector; 97 datalink exps2vector;98 106 99 107 for (int i=0;i<lanes.length();i++) { … … 105 113 int l=0; 106 114 for (int j=0;j<rv_recieved_exps.length();j++) { 107 t_cars_begin.set_size(l+1,true);108 t_cars_end.set_size(l+1,true);109 cars_count.set_size(l+1,true);110 115 111 116 int result=rv_recieved_exps.name(j).find(lanes(i).inputs(k)+"-"); 112 117 if (result>=0) { 118 119 t_cars_begin.set_size(l+1,true); 120 t_cars_end.set_size(l+1,true); 121 cars_count.set_size(l+1,true); 122 113 123 114 124 rv_vector = RV(rv_recieved_exps.name(j),3); … … 124 134 } 125 135 if (found) { 136 126 137 //counting rating 127 138 string group = name+"_"+lanes(i).sg; //e.g. 495_VA … … 138 149 virtual_queue=lanehs(i)->queue; 139 150 140 //cycle goes through all stoppingpoints and counts queue lenght at these points151 //cycle goes through all "stopping" points and counts queue lenght at these points 141 152 do { 142 153 k=min_i(t_cars_begin); … … 151 162 if (t_cars_end(k)<=t_act) { 152 163 virtual_queue+=cars_count(k); 153 //jen prodlouzime, t_act zustava, odstranime k-ty predpoklad (mozna hned, mozna az na konci164 154 165 cars_count.del(k); 155 166 t_cars_begin.del(k); … … 158 169 } 159 170 else { 160 //prodlouzujeme do casu t_green_begin,161 //pak bud green_begin posuneme do t_act162 171 double pomer=(t_cars_begin(k)-t_act)/(t_cars_end(k)-t_cars_begin(k)); 163 172 virtual_queue+=cars_count(k)*pomer; … … 166 175 } 167 176 else if (t_cars_begin(k)==t_act) { 168 //mixujeme az do t_cars_end nebo t_green_end169 //posuneme t_act na jeden z tech casu170 177 if (t_cars_end(k)<t_green_end) { 171 178 virtual_queue+=cars_count(k)-(t_cars_end(k)-t_act)/car_leaving; … … 176 183 t_cars_end.del(k); 177 184 } 178 // t_cars_end>=t_green_end185 //if t_cars_end>=t_green_end 179 186 else { 180 187 virtual_queue+=cars_count(k)-(t_green_end-t_act)/car_leaving; … … 188 195 189 196 } 190 // t_cars_begin(k)>=t_act197 //if t_cars_begin(k)>=t_act 191 198 else { 192 //zkracujeme frontu az do t_cars_end(k) nebo t_green_end a posuneme t_act193 199 if (t_cars_end(k)<t_green_end) { 194 200 virtual_queue-=(t_cars_end(k)-t_act)/car_leaving; … … 201 207 } 202 208 } 209 //if no other expectations found 203 210 else { 204 211 virtual_queue-=(t_green_end-t_act)/car_leaving; … … 219 226 //! finds best offset using recieved_exps. Returns found offset 220 227 int find_best_offset(const int center, int interval) { 221 //! rating if offset is rised 228 //! rating if offset is rised 222 229 double rating_p; 223 230 //! rating if offset is unchaged (=center) … … 368 375 } 369 376 370 //! returns offset value shifted to fit interval <0;cycle_length> 371 int normalize_offset(int offset) { 372 while (offset<0 || offset>cycle_length) { 373 if (offset<0) { 374 offset+=cycle_length; 375 } 376 else { 377 offset-=cycle_length; 378 } 379 } 380 return offset; 381 } 377 /*! 378 returns offset value shifted to fit interval <-cycle_length/2;cycle_length/2> 379 or (when second parameter is false)) <0;cycle_length> 380 */ 381 int normalize_offset(int offset, bool zero=true) { 382 if (zero) { 383 while ((offset<(-cycle_length/2)) || (offset>(cycle_length/2))) { 384 if (offset<0) { 385 offset+=cycle_length; 386 } 387 else { 388 offset-=cycle_length; 389 } 390 } 391 return offset; 392 } 393 else { 394 while (offset<0 || offset>cycle_length) { 395 if (offset<0) { 396 offset+=cycle_length; 397 } 398 else { 399 offset-=cycle_length; 400 } 401 } 402 return offset; 403 } 404 } 405 406 382 407 383 408 //! returns value shifted to fit interval <0;cycle_length> 409 //currently not in use 384 410 template<class T> T normalize(T time) { 385 411 while (time<0 && time<cycle_length) { … … 394 420 } 395 421 422 //! converts t to string 396 423 template <class T> inline string to_string (const T& t) 397 424 { … … 414 441 } 415 442 416 //! returns index of smallest element in vector sx443 //! returns index of smallest element in vector 417 444 int min_i(vec vector) { 418 445 if (vector.length()>0) { … … 440 467 double planned_rating; 441 468 //! rating of planned next offset 442 double planned_next_rating; 443 469 double planned_next_rating; 444 470 //! avarage speed of cars 445 471 int VP; … … 653 679 RV rv_exp; 654 680 655 std::ofstream ofile;656 ofile.open("greentimes.txt");657 ofile.close();658 659 681 car_leaving=2; 660 682 VP=45; 661 683 actual_time=0; 684 685 negot_cycle=1; 686 cycle_count=5; 687 total_offset=0; 662 688 663 689 negot_offset=8; … … 681 707 682 708 void act(vec &glob_ut){ 683 vec action; 684 action.set_size(rv_action._dsize()); 685 686 ivec index = rv_action.dataind(RV(name+"_offset",1)); 687 688 action(index(0))=planned_offset; 709 if (negot_cycle==cycle_count) { 710 711 vec action; 712 action.set_size(rv_action._dsize()); 713 714 ivec index = rv_action.dataind(RV(name+"_offset",1)); 715 716 action(index(0))=normalize_offset(total_offset/cycle_count, false); 717 action2ds.filldown(action,glob_ut); 718 719 total_offset=0; 720 negot_cycle=1; 721 722 } 723 else { 724 total_offset+=planned_offset; 725 726 negot_cycle++; 727 } 728 689 729 last_offset=planned_offset; 690 action2ds.filldown(action,glob_ut);691 692 730 actual_time+=step_length; 693 731 } 732 694 733 695 734 };