Changeset 986 for applications
- Timestamp:
- 05/25/10 23:53:49 (15 years ago)
- Location:
- applications/doprava
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/Zlicingw.cfg
r941 r986 4 4 name = "495"; 5 5 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_DV A"); 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";} 8 8 ); 9 9 neighbours = ("601"); 10 offset = 40; //s10 offset = 10; //s 11 11 sgs=("VA","VB","VC","VD","VE","VF"); 12 green_starts=[72,4,5,35,36,71]; 12 13 moje_special=14; 13 14 }, 14 15 { //agent 2 15 16 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 ); 17 22 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]; 19 26 } 20 27 … … 41 48 }; 42 49 43 //Number of recieve/broadcast calls before end of negoti taion50 //Number of recieve/broadcast calls before end of negotiation 44 51 negotiation_cycles = 5; -
applications/doprava/aimsun_bdm/aimsun_ds.cpp
r927 r986 57 57 "601_S6 601_S6a 601_S7 601_S8 601_S9 601_S9a " 58 58 "495_Q1 495_Q2 " 59 "601_Q1 601_Q2 " 59 60 "}", 60 61 " 1, 1, 1, 1, 1, 1, " … … 64 65 " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2," 65 66 " 2, 2, 2, 2, 2, 2" 67 " 1, 1" 66 68 " 1, 1" 67 69 ); -
applications/doprava/traffic_agent.cpp
r941 r986 15 15 double LaneHandler::expected_output(double green_time){ 16 16 double last_inputs=0.0; 17 18 17 19 18 20 agentin2input.filldown(agent->inputs, inputs); … … 22 24 23 25 ///////// 24 //Velmi jednoduchy odhad26 25 27 agentin2input.filldown(agent->inputs,inputs); 26 28 27 29 for (int i=0;i<inputs.length();i+=2) { 28 30 last_inputs+=inputs(i); 29 31 } … … 35 37 } 36 38 39 double 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 } 37 50 38 51 void BaseTrafficAgent::from_setting(const Setting& set) 39 52 { 40 bdm::Participant::from_setting(set); 53 step_time=90; 54 cycle_time=80; 55 56 bdm::Participant::from_setting(set); 41 57 42 58 // load from file -
applications/doprava/traffic_agent.h
r941 r986 20 20 Array<string> inputs; 21 21 Array<string> outputs; 22 vec input_distances; 23 vec output_distances; 22 24 vec alpha; //size of outputs 23 25 string queue; … … 28 30 UI::get(inputs,set,"inputs",UI::compulsory); 29 31 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); 30 34 UI::get(alpha,set,"alpha",UI::compulsory); 31 35 UI::get(queue,set,"queue",UI::compulsory); … … 61 65 //! 62 66 int queue_index; 67 63 68 public: 64 69 LaneHandler(const Lane &lane0): lane(lane0){ … … 70 75 } 71 76 rv_queue.add(RV(lane.queue, 1)); 72 } 77 inputs.set_size(rv_inputs._dsize()); 78 } 79 73 80 74 81 void connect_data(BaseTrafficAgent &agent0); 75 82 83 //! computes expected density in cars/s 84 double expected_density(); 85 76 86 //! arbitrary function that computes the need of the signal group for green light in common units (number of waiting cars?) 77 87 double expected_output(double green_time); … … 114 124 115 125 //! action description 116 RV action_rv;126 RV rv_action; 117 127 118 128 datalink_part action2ds; … … 132 142 public: 133 143 void validate(){ 134 //TODO Tohle asi ne135 step_time=90;136 cycle_time=80;137 144 138 145 lanehs.set_length(lanes.length()); … … 236 243 237 244 inputs.set_size(rv_inputs._dsize()); 238 action2ds.set_connection( ds._urv(), action_rv);245 action2ds.set_connection( ds._urv(), rv_action); 239 246 240 247 } -
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> 2 3 3 4 class GreenWaveTrafficAgent : public BaseTrafficAgent { … … 5 6 double stable_state_loss; 6 7 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 16 23 for (int i=0;i<lanes.length();i++) { 17 24 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 } 30 49 } 31 50 32 51 public: 33 datalink ds2greentimes;34 vec greentimes;35 RV rv_greentimes;52 int last_offset; 53 int planned_offset; 54 double actual_rating; 36 55 37 56 //! array of existing signal groups 38 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; 39 63 40 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 41 77 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; 47 88 } 48 89 49 90 void adapt(const vec &glob_dt) { 50 91 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 54 149 55 150 void broadcast(Setting& set){ … … 68 163 69 164 // 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 81 180 } 82 181 … … 87 186 string to; 88 187 string from; 89 doublevalue;90 91 188 vec value; 189 RV *rv; 190 92 191 UI::get(what, msg, "what", UI::compulsory); 93 192 UI::get(to, msg, "to", UI::compulsory); 94 193 UI::get(from, msg, "from"); 194 UI::get(rv, msg, "rv"); 95 195 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 98 200 } 99 201 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 102 206 } 103 207 else { … … 108 212 void ds_register(const DS &ds) { 109 213 BaseTrafficAgent::ds_register(ds); 110 ds2greentimes.set_connection(rv_greentimes, ds._drv()); 214 action2ds.set_connection( ds._urv(), rv_action); 215 111 216 } 112 217 113 218 void from_setting(const Setting &set) { 114 219 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 117 226 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 120 241 }; 121 242 UIREGISTER(GreenWaveTrafficAgent);