Changeset 1026
- Timestamp:
- 06/02/10 00:13:50 (15 years ago)
- Location:
- applications/doprava
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/Zlicin.cfg
r903 r1026 2 2 { // agent 1 3 3 class = "BaseTrafficAgent"; 4 name = "495"; 5 sg = ( 6 { name = "VA"; 7 detectors = ( 8 { name = "DVA1"; distance = 10;}, 9 {name = "DVA"; distance = 20; } 10 ); 11 }, 12 { name = "VB"; 13 detectors = (); 14 input = {}; 15 output = {}; 16 }); 17 input = ( // remote detectors 18 { 19 name = "601_DVAa"; 20 distance = 100; 21 to_sg = ("VC","VD"); 22 }, 23 { 24 name = "601_DVA"; 25 distance = 100; 26 to_sg = ("VC","VD"); 27 } 28 ); 29 output = ( // 30 { 31 detectors = ("495_DVC"); 32 to = "601"; 33 } 34 ); 35 36 offset = 40; //s 37 moje_special=14; 4 name = "495"; 5 lanes = ( 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";} 8 ); 9 neighbours = ("601"); 10 offset = 10; //s 11 moje_special=14; 38 12 }, 39 13 { //agent 2 40 14 class = "BaseTrafficAgent"; 41 name = "601"; 42 sg = ( 43 { name = "VA"; 44 detectors = ( 45 { name = "DVA"; distance = 10; }, 46 {name = "DVAa"; distance = 20; } 47 ); 48 }, 49 { name = "VB"; 50 detectors = (); 51 } 52 ); 53 54 offset = 60; //s 55 input = (); 56 output = ({to="495"; detectors=("601_DVAa","601_DVA");}); 15 name = "601"; 16 lanes = ( 17 { sg="VA"; inputs = ("601_DVA","601_DVB"); outputs= ("495_DVA"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q1";}, 18 { sg="VB"; inputs = ("601_DVC","601_DVD"); outputs= ("495_DVB"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";} 19 ); 20 neighbours = ("495"); 21 offset = 40; 22 57 23 } 24 58 25 ); 59 26 60 logger = {class="memlog"; filename = "zlicin"; maxlen = 1000;}; 27 logger = {class="memlog"; filename = "mujlog"; maxlen = 1000;}; 28 29 30 61 31 62 32 system = { … … 72 42 // length is 24 hours (24:00:00). 73 43 stop_time = "01:00:00"; 44 74 45 }; 46 47 //Number of recieve/broadcast calls before end of negotiation 48 negotiation_cycles = 5; -
applications/doprava/Zlicingw.cfg
r986 r1026 4 4 name = "495"; 5 5 lanes = ( 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";} 6 { sg="VA"; inputs = ("495_DVA1"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q1";}, 7 { sg="VB"; inputs = ("495_DVB1"); outputs= ("601_DVA","601_DVAa"); input_distances=[30]; output_distances=[200,200]; alpha= [0.5,0.5 ]; queue="495_Q2";}, 8 { sg="VC"; inputs = ("495_DVC"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q1";}, 9 { sg="VD"; inputs = ("495_DVD"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q2";}, 10 { sg="VE"; inputs = ("495_DVE"); outputs= ("601_DVA","601_DVAa"); input_distances=[30]; output_distances=[200,200]; alpha= [0.5,0.5 ]; queue="495_Q1";}, 11 { sg="VF"; inputs = ("495_DVF1"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q2";} 8 12 ); 9 13 neighbours = ("601"); … … 17 21 name = "601"; 18 22 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";} 23 { sg="VA"; inputs = ("601_DVA"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q1";}, 24 { sg="VA"; inputs = ("601_DVAa"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";}, 25 { sg="VB"; inputs = ("601_DVB1"); outputs= ("495_DVC","495_DVD"); input_distances=[30]; output_distances=[200,200]; alpha= [0.5,0.5 ]; queue="601_Q1";}, 26 { sg="VB"; inputs = ("601_DVB1"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";}, 27 { sg="VC"; inputs = ("601_DVC"); outputs= ("495_DVC","495_DVD"); input_distances=[30]; output_distances=[200,200]; alpha= [1.0 ]; queue="601_Q1";}, 28 { sg="VD"; inputs = ("601_DVD1"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";}, 29 { sg="SE"; inputs = ("601_DSE1"); outputs= (""); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q1";}, 30 { sg="VE"; inputs = ("601_DVE1"); outputs= ("495_DVC","495_DVD"); input_distances=[30]; output_distances=[200,200]; alpha= [0.5,0.5 ]; queue="601_Q2";} 21 31 ); 22 32 neighbours = ("495"); … … 28 38 ); 29 39 30 logger = {class="memlog"; filename = " zlicin"; maxlen = 1000;};40 logger = {class="memlog"; filename = "mujzlicin"; maxlen = 1000;}; 31 41 32 42 … … 44 54 // simulation in our case starts always at 00:00:00. Default simulation 45 55 // length is 24 hours (24:00:00). 46 stop_time = "00: 05:00";56 stop_time = "00:30:00"; 47 57 48 58 }; 49 59 50 60 //Number of recieve/broadcast calls before end of negotiation 51 negotiation_cycles = 5;61 negotiation_cycles = 15; -
applications/doprava/main_loop.cpp
r932 r1026 36 36 // LOGGER 37 37 shared_ptr<logger> L = UI::build <logger>( Cfg, "logger" ); 38 if (!L) {L=new stdlog();} // DEFAULT LOGGER <== poor choice, use better ones 38 if (!L) { 39 L=new stdlog(); // DEFAULT LOGGER <== poor choice, use better ones 40 } 39 41 40 42 … … 105 107 } 106 108 while ((Queue.getLength()>0) && (cycle<max_cycles)); 109 if (cycle==max_cycles) { 110 bdm_warning("Reached maximum number of cycles"); 111 } 107 112 108 113 for ( int i=0; i<Ags.length(); i++ ) { -
applications/doprava/traffic_agent.cpp
r986 r1026 31 31 } 32 32 33 exp_output=last_inputs*(green_time/agent->step_ time);33 exp_output=last_inputs*(green_time/agent->step_length); 34 34 35 35 //////// … … 43 43 44 44 for (int i=0;i<inputs.length();i+=2) { 45 density+=inputs(i)/agent->step_ time;45 density+=inputs(i)/agent->step_length; 46 46 } 47 47 … … 51 51 void BaseTrafficAgent::from_setting(const Setting& set) 52 52 { 53 step_ time=90;54 cycle_ time=80;53 step_length=90; 54 cycle_length=80; 55 55 56 56 bdm::Participant::from_setting(set); -
applications/doprava/traffic_agent.h
r986 r1026 135 135 136 136 //! simulator's step length in seconds 137 int step_ time;137 int step_length; 138 138 139 139 //! lenght of cycle in seconds 140 int cycle_ time;140 int cycle_length; 141 141 142 142 public: -
applications/doprava/traffic_agent_offset.h
r986 r1026 4 4 class GreenWaveTrafficAgent : public BaseTrafficAgent { 5 5 protected: 6 double stable_state_loss; 7 double best_offset; 6 double rating_change; 7 int negot_offset; 8 9 RV rv_change_request; 10 vec change_request; 8 11 9 12 RV rv_recieved_exps; 10 13 vec recieved_exps; 11 14 15 RV rv_recieved_changes; 16 vec recieved_changes; 17 18 //! name of agent, whose change we have accepted 19 string accepted_from; 20 12 21 list<string> seznam; 13 22 14 15 23 double car_leaving; //s; how long is 1 car leaving queue 16 24 17 bool recieved_exp_request; 18 19 //counts all expected cars going from each lane 25 bool need_exps; 26 bool new_stable_state; 27 bool send_requests; 28 bool final_state; 29 //bool reset_negot_offset; 30 31 //! counts all expected cars going from each lane, saves to outputs and rv_outputs 20 32 void expected_cars(/*const string dest*/) { 21 33 double start_time; … … 23 35 for (int i=0;i<lanes.length();i++) { 24 36 for (int j=0;j<lanes(i).outputs.length();j++) { 25 // if (lanes(i).outputs(j).substr(0,3)==dest) {26 //27 37 string group = name+"_"+lanes(i).sg; //e.g. 495_VA 28 38 ivec index=rv_inputs.dataind(RV(group,1)); 29 39 vec green_time=inputs(index); 30 40 31 32 41 rv_outputs.add(RV(lanes(i).outputs(j)+"-"+group,3)); 33 42 outputs.set_size(rv_outputs._dsize()); 34 43 35 ivec ind exes= rv_outputs.dataind(RV(lanes(i).outputs(j)+"-"+group,3));44 ivec ind = rv_outputs.dataind(RV(lanes(i).outputs(j)+"-"+group,3)); 36 45 37 46 //Number of cars 38 outputs(ind exes(0))=lanehs(i)->expected_output(green_time(0));47 outputs(ind(0))=lanehs(i)->expected_output(green_time(0)); 39 48 40 49 start_time = green_starts(sg_index(lanes(i).sg)) + lanes(i).output_distances(j)/VP + planned_offset; 41 50 //first car arrive time 42 outputs(ind exes(1))=start_time;51 outputs(ind(1))=start_time; 43 52 //last car arrive time 44 outputs(indexes(2))= start_time + green_time(0); 45 46 //} 47 } 48 } 49 } 50 51 public: 52 int last_offset; 53 int planned_offset; 54 double actual_rating; 55 56 //! array of existing signal groups 57 Array<string> sgs; 58 //! relative starts of green for signal groups 59 ivec green_starts; 60 61 //! avarage speed of cars 62 int VP; 63 64 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 77 BaseTrafficAgent::validate(); 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; 88 } 89 90 void adapt(const vec &glob_dt) { 91 BaseTrafficAgent::adapt(glob_dt); 92 93 planned_offset=last_offset; 94 } 95 //! counts actual rating using planned_offset and recieved_exps 96 void count_rating() { 53 outputs(ind(2))= start_time + green_time(0); 54 } 55 } 56 }; 57 58 //! counts planned rating using offset and recieved_exps 59 double count_rating(const int offset) { 97 60 double virtual_queue; 98 61 double t_emptiyng; … … 101 64 double t_cars_begin; 102 65 double t_cars_end; 66 // vec t_cars_begin; 67 // vec t_cars_end; 103 68 double t_mixing; 104 69 bool found; 105 70 106 actual_rating=0.0;107 108 for (int i=0;i<lane hs.length();i++) {71 double rating=0.0; 72 73 for (int i=0;i<lanes.length();i++) { 109 74 110 75 //Finding, if we have some expectations 111 76 found=false; 112 for (int j=0;j<rv_recieved_exps.length();j++) { 113 for (int k=0;k<lanes(i).inputs.length();k++) { 77 for (int k=0;k<lanes(i).inputs.length();k++) { 78 // t_cars_begin.set_size(lanes(i).inputs.length()); 79 // t_cars_end.set_size(lanes(i).inputs.length()); 80 81 for (int j=0;j<rv_recieved_exps.length();j++) { 114 82 int result=rv_recieved_exps.name(j).find(lanes(i).inputs(k)+"-"); 115 83 if (result>=0) { 116 ivec ind exes= rv_recieved_exps.dataind(RV(rv_recieved_exps.name(j),3));117 118 t_cars_begin=recieved_exps(ind exes(1));119 t_cars_end=recieved_exps(ind exes(2));84 ivec ind = rv_recieved_exps.dataind(RV(rv_recieved_exps.name(j),3)); 85 86 t_cars_begin=recieved_exps(ind(1)); //TODO now using only last found exp. 87 t_cars_end=recieved_exps(ind(2)); 120 88 found=true; 121 89 } 122 90 } 123 91 } 92 124 93 if (!found) { 125 94 t_cars_begin=0; 126 t_cars_end=cycle_time; 127 } 128 95 t_cars_end=cycle_length; 96 } 129 97 //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 98 t_green_begin=green_starts(sg_index(lanes(i).sg)) + offset; 99 ivec ind = rv_inputs.dataind(RV(name+"_"+lanes(i).sg,1)); 100 t_green_end=t_green_begin+inputs(ind(0)); 101 102 //TODO use real queues lenghts 134 103 if (t_green_begin<t_cars_begin) { 135 virtual_queue=lanehs(i)->queue-(t_cars_begin-t_green_begin)/car_leaving; 104 //virtual_queue=lanehs(i)->queue-(t_cars_begin-t_green_begin)/car_leaving; 105 //virtual_queue=(rand()%8)-(t_cars_begin-t_green_begin)/car_leaving; 106 virtual_queue=5-(t_cars_begin-t_green_begin)/car_leaving; 136 107 } 137 108 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 109 //virtual_queue=lanehs(i)->queue+(t_green_begin-t_cars_begin)*lanehs(i)->expected_density(); 110 //virtual_queue=(rand()%9)+(t_green_begin-t_cars_begin)*lanehs(i)->expected_density(); 111 virtual_queue=4+(t_green_begin-t_cars_begin)*lanehs(i)->expected_density(); 112 } 141 113 142 114 t_emptiyng=virtual_queue/(1/car_leaving - lanehs(i)->expected_density()); 143 115 t_mixing=min(t_green_end,t_cars_end)-max(t_green_begin,t_cars_begin); 144 116 145 actual_rating+=max((t_mixing-t_emptiyng)*lanehs(i)->expected_density(),0.0); 146 } 147 } 148 117 rating+=max((t_mixing-t_emptiyng)*lanehs(i)->expected_density(),0.0); 118 } 119 return rating; 120 } 121 122 //! finds best offset using recieved_exps. Returns found offset 123 int find_best_offset(const int center, int interval) { 124 //! rating if offset is rised 125 double rating_p; 126 //! rating if offset is unchaged (=center) 127 double rating_c; 128 //! rating if offset is lowered 129 double rating_n; 130 131 int new_center; 132 133 rating_p=count_rating(center+interval); 134 rating_c=count_rating(center); 135 rating_n=count_rating(center-interval); 136 137 new_center=center; 138 int max_index=max_of_three(rating_p,rating_c,rating_n); 139 switch (max_index) { 140 case 0: 141 new_center+=interval; 142 break; 143 case 1: 144 break; 145 case 2: 146 new_center-=interval; 147 break; 148 } 149 150 if (interval>2) { 151 interval/=2; 152 new_center=find_best_offset(new_center,interval); 153 } 154 155 return new_center; 156 } 157 158 //! finds if changing neighbour's offset could have positive effect, returns found offset change 159 int find_best_exps(const int offset_change, const string neighbour, double &rating_change) { 160 //! expectations recieved from neighbour 161 vec original_exps; 162 //! expactations after positve change of neighbour's offset 163 vec positive_exps; 164 //! expactations after negative change of neighbour's offset 165 vec negative_exps; 166 //! rating if offset is rised 167 double rating_p; 168 //! rating if offset is unchaged 169 double rating_c; 170 //! rating if offset is lowered 171 double rating_n; 172 original_exps.set_size(recieved_exps.length()); 173 174 original_exps=recieved_exps; 175 positive_exps=recieved_exps; 176 negative_exps=recieved_exps; 177 178 for (int j=0;j<rv_recieved_exps.length();j++) { 179 int res = rv_recieved_exps.name(j).find("-"+neighbour); 180 if (res>0) { 181 ivec ind = rv_recieved_exps.dataind(RV(rv_recieved_exps.name(j),3)); 182 rating_n=count_rating(planned_offset); 183 184 positive_exps(ind(1))+=offset_change; 185 positive_exps(ind(2))+=offset_change; 186 187 negative_exps(ind(1))-=offset_change; 188 negative_exps(ind(2))-=offset_change; 189 } 190 } 191 192 rating_c=count_rating(planned_offset); 193 194 recieved_exps=positive_exps; 195 rating_p=count_rating(planned_offset); 196 197 recieved_exps=negative_exps; 198 rating_n=count_rating(planned_offset); 199 200 recieved_exps=original_exps; 201 202 int max_index=max_of_three(rating_p,rating_c,rating_n); 203 switch (max_index) { 204 case 0: 205 rating_change=rating_p-rating_c; 206 return offset_change; 207 break; 208 case 1: 209 rating_change=0; 210 return 0; 211 break; 212 case 2: 213 rating_change=rating_n-rating_c; 214 return -offset_change; 215 break; 216 } 217 rating_change=NULL; 218 return NULL; 219 } 220 221 //! returns index of signal group sg 222 int sg_index(const string sg) { 223 for (int i=0;i<sgs.length();i++) { 224 if (sgs(i)==sg) { 225 return i; 226 } 227 } 228 return -1; 229 } 230 231 //! returns offset value shifted to fit interval <0;cycle_length> 232 int normalize_offset(int offset) { 233 while (offset<0 && offset<cycle_length) { 234 if (offset<0) { 235 offset+=cycle_length; 236 } 237 else { 238 offset-=cycle_length; 239 } 240 } 241 return offset; 242 } 243 244 245 //! returns index of maximum of entered values 246 int max_of_three(const double a, const double b, const double c) { 247 int index = a > b ? 0 : 1; 248 249 if (index == 0) { 250 index = a > c ? 0 : 2; 251 } 252 else { 253 index = b > c ? 1 : 2; 254 } 255 return index; 256 } 257 258 public: 259 //! offset set in last simulation step 260 int last_offset; 261 //! actual planned offset to set for next simulation step 262 int planned_offset; 263 //! rating of actual planned offset 264 double planned_rating; 265 266 //! array of existing signal groups 267 Array<string> sgs; 268 //! relative starts of green for signal groups 269 ivec green_starts; 270 271 //! avarage speed of cars 272 int VP; 273 274 void validate() { 275 rv_action = RV(name+"_offset", 1); // <======= example 276 277 for (int i=0; i<sgs.length();i++) { 278 rv_inputs.add(RV(name+"_"+sgs(i),1)); 279 } 280 inputs.set_size(rv_inputs._dsize()); 281 282 BaseTrafficAgent::validate(); 283 284 for (int i=0;i<lanehs.length();i++) { 285 ivec index = rv_queues.dataind(RV(lanes(i).queue,1)); 286 lanehs(i)->queue_index=index(0); 287 } 288 289 290 } 291 292 void adapt(const vec &glob_dt) { 293 BaseTrafficAgent::adapt(glob_dt); 294 295 for (int i=0;i<lanehs.length();i++) { 296 lanehs(i)->queue=queues(lanehs(i)->queue_index); 297 } 298 299 planned_offset=last_offset; 300 301 //set state variables to default values 302 final_state=false; 303 new_stable_state=false; 304 send_requests=false; 305 need_exps=true; 306 negot_offset=8; 307 } 149 308 150 309 void broadcast(Setting& set){ 151 310 152 311 //ask neighbours for exptected arrive times 153 if ( true) {312 if (need_exps) { 154 313 for (int i=0; i<neighbours.length(); i++){ 155 314 Setting &msg =set.add(Setting::TypeGroup); … … 159 318 UI::save ( (string)"expected_times_request", msg, "what"); 160 319 } 161 }162 320 need_exps=false; 321 } 163 322 164 323 // broadcast expected cars 165 324 if (!seznam.empty()) { 325 expected_cars(); 166 326 do { 167 vec value;168 169 expected_cars();170 327 Setting &msg =set.add(Setting::TypeGroup); 171 328 UI::save ( seznam.back(), msg, "to"); … … 175 332 UI::save ( outputs, msg, "value"); 176 333 seznam.pop_back(); 177 178 } while (!seznam.empty()); 334 } while (!seznam.empty()); 335 } 336 337 // broadcast new stable state (new stable expectations) 338 if (new_stable_state) { 339 expected_cars(); 340 for (int i=0;i<neighbours.length();i++) { 341 Setting &msg = set.add(Setting::TypeGroup); 342 UI::save ( neighbours(i), msg, "to"); 343 UI::save ( name, msg, "from"); 344 UI::save ( (string)"new_stable_state2", msg, "what"); 345 UI::save ( &(rv_outputs), msg, "rv"); 346 UI::save ( outputs, msg, "value"); 347 } 348 new_stable_state=false; 349 } 350 351 // broadcast requests to change offset(s) 352 if (send_requests) { 353 for (int i=0;i<neighbours.length();i++) { 354 Setting &msg = set.add(Setting::TypeGroup); 355 UI::save ( neighbours(i), msg, "to"); 356 UI::save ( name, msg, "from"); 357 UI::save ( (string)"offset_change_request", msg, "what"); 358 UI::save ( &(rv_change_request), msg, "rv"); 359 UI::save ( change_request, msg, "value"); 360 } 361 send_requests=false; 362 } 363 364 /*if (reset_negot_offset) { 365 for (int i=0;i<neighbours.length();i++) { 366 Setting &msg = set.add(Setting::TypeGroup); 367 UI::save ( neighbours(i), msg, "to"); 368 UI::save ( name, msg, "from"); 369 UI::save ( (string)"reset_negot_offset", msg, "what"); 370 } 371 }*/ 372 373 374 375 // reached final offset. Log value? 376 if (final_state) { 179 377 180 } 181 378 //cout << "Jmenuji se "<<name<< " a skoncil jsem na offsetu " << planned_offset << " s hodnocenim " << planned_rating <<endl; 379 final_state=false; 380 } 182 381 } 183 382 … … 185 384 string what; 186 385 string to; 386 187 387 string from; 188 388 vec value; … … 194 394 UI::get(rv, msg, "rv"); 195 395 UI::get(value, msg, "value"); 396 196 397 if (what=="expected_times_request"){ 197 recieved_exp_request=true;198 398 seznam.push_back(from); 199 200 399 } 201 400 else if (what=="new_expected_cars") { 202 401 rv_recieved_exps=*rv; 203 402 recieved_exps=value; 204 count_rating(); 205 //TODO skutecne vyjednavani 206 } 403 404 last_offset=planned_offset; 405 406 planned_offset=find_best_offset(planned_offset,8); 407 planned_offset=normalize_offset(planned_offset); 408 409 410 /*if (planned_offset!=last_offset) { 411 reset_negot_offset=true; 412 }*/ 413 planned_rating=count_rating(planned_offset); 414 // we have new stable state to broadcast 415 new_stable_state=true; 416 } 417 else if (what=="new_stable_state2") { 418 rv_recieved_exps=*rv; 419 recieved_exps=value; 420 planned_rating=count_rating(planned_offset); 421 422 for (int i=0;i<neighbours.length();i++) { 423 rv_change_request.add(RV(neighbours(i)+"_change",2)); 424 change_request.set_size(rv_change_request._dsize()); 425 ivec ind=rv_change_request.dataind(RV(neighbours(i)+"_change",2)); 426 // offset change 427 change_request(ind(0))=find_best_exps(negot_offset,neighbours(i),rating_change); 428 // rating change 429 change_request(ind(1))=rating_change; 430 } 431 432 if (negot_offset>2) { 433 negot_offset/=2; 434 send_requests=true; 435 } 436 else { 437 final_state=true; 438 } 439 } 440 else if (what=="offset_change_request") { 441 double final_rating_diff; 442 443 rv_recieved_changes=*rv; 444 recieved_changes=value; 445 446 for (int i=0;i<rv_recieved_changes.length();i++) { 447 448 ivec ind=rv_recieved_changes.dataind(RV(rv_recieved_changes.name(i),2)); 449 450 final_rating_diff=-planned_rating+count_rating(planned_offset+(int)recieved_changes(ind(0)))-recieved_changes(ind(0)); 451 if (final_rating_diff>0) { 452 planned_offset+=(int)recieved_changes(ind(0)); 453 planned_rating+=final_rating_diff; 454 accepted_from=from; 455 } 456 } 457 //need_exps=true;s 458 new_stable_state=true; 459 } 460 /*else if (what=="reset_negot_offset") { 461 negot_offset=8; 462 }*/ 207 463 else { 208 464 BaseTrafficAgent::receive(msg); … … 213 469 BaseTrafficAgent::ds_register(ds); 214 470 action2ds.set_connection( ds._urv(), rv_action); 215 216 471 } 217 472 … … 219 474 BaseTrafficAgent::from_setting(set); 220 475 476 srand(time(NULL)); 477 221 478 car_leaving=2; 222 479 VP=45; 223 recieved_exp_request=false; 480 481 negot_offset=8; 224 482 225 483 // load from file … … 232 490 vec action; 233 491 action.set_size(rv_action._dsize()); 234 492 235 493 ivec index = rv_action.dataind(RV(name+"_offset",1)); 236 494 action(index(0))=planned_offset; 495 last_offset=planned_offset; 237 496 238 497 action2ds.filldown(action,glob_ut);