Changeset 941 for applications
- Timestamp:
- 05/14/10 01:35:51 (15 years ago)
- Location:
- applications/doprava
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/Zlicingw.cfg
r932 r941 9 9 neighbours = ("601"); 10 10 offset = 40; //s 11 sgs=("VA","VB","VC","VD","VE","VF"); 11 12 moje_special=14; 12 13 }, … … 15 16 name = "601"; 16 17 neighbours = ("495"); 18 sgs=("VA","VB","VC","VD","VE"); 17 19 } 18 20 … … 35 37 // simulation in our case starts always at 00:00:00. Default simulation 36 38 // length is 24 hours (24:00:00). 37 stop_time = "0 1:00:00";39 stop_time = "00:05:00"; 38 40 39 41 }; -
applications/doprava/traffic_agent.cpp
r927 r941 14 14 15 15 double LaneHandler::expected_output(double green_time){ 16 double last_inputs=0.0; 17 16 18 agentin2input.filldown(agent->inputs, inputs); 17 19 queue = agent->queues(queue_index); 18 20 19 21 double exp_output=0.0; 22 20 23 ///////// 21 22 24 //Velmi jednoduchy odhad 25 agentin2input.filldown(agent->inputs,inputs); 26 27 for (int i=0;i<inputs.length();i+=2) { 28 last_inputs+=inputs(i); 29 } 30 31 exp_output=last_inputs*(green_time/agent->step_time); 32 23 33 //////// 24 34 return exp_output; -
applications/doprava/traffic_agent.h
r927 r941 107 107 RV rv_queues; 108 108 109 //! datalink from DS to output variables109 //! datalink from DS to input variables 110 110 datalink ds2inputs; 111 111 112 112 //! datalink from DS to output variables 113 113 datalink ds2queues; 114 114 115 115 //! action description 116 116 RV action_rv; … … 123 123 124 124 Array<datalink> output2neighbour; 125 126 //! simulator's step length in seconds 127 int step_time; 128 129 //! lenght of cycle in seconds 130 int cycle_time; 125 131 126 132 public: 127 133 void validate(){ 134 //TODO Tohle asi ne 135 step_time=90; 136 cycle_time=80; 137 128 138 lanehs.set_length(lanes.length()); 129 139 for (int l=0; l<lanes.length(); l++){ … … 211 221 // copy data from global vector to sSGHandlers 212 222 ds2inputs.filldown(glob_dt, inputs); 213 //copy data fro neighbours223 //copy data from neighbours 214 224 ds2queues.filldown(glob_dt, queues); 215 225 // copy sg_length ... and others... … … 224 234 ds2inputs.set_connection(rv_inputs, ds._drv()); 225 235 ds2queues.set_connection(rv_queues, ds._drv()); 236 226 237 inputs.set_size(rv_inputs._dsize()); 227 238 action2ds.set_connection( ds._urv(), action_rv); 239 228 240 } 229 241 -
applications/doprava/traffic_agent_offset.h
r927 r941 1 #include <map> 2 1 3 class GreenWaveTrafficAgent : public BaseTrafficAgent { 2 4 protected: 3 5 double stable_state_loss; 6 double best_offset; 7 map<string,double> expected; 8 map<string,double>::iterator expected_i; 4 9 5 double best_offset; 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" 16 for (int i=0;i<lanes.length();i++) { 17 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; 30 } 31 6 32 public: 33 datalink ds2greentimes; 34 vec greentimes; 35 RV rv_greentimes; 36 37 //! array of existing signal groups 38 Array<string> sgs; 39 7 40 void validate() { 8 41 BaseTrafficAgent::validate(); 9 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 } 10 47 } 11 void GreeWaveTrafficAgent(); 48 49 void adapt(const vec &glob_dt) { 50 BaseTrafficAgent::adapt(glob_dt); 51 52 ds2greentimes.filldown(glob_dt,greentimes); 53 } 54 55 void broadcast(Setting& set){ 56 57 //ask neighbours for exptected arrive times 58 if (true) { 59 for (int i=0; i<neighbours.length(); i++){ 60 Setting &msg =set.add(Setting::TypeGroup); 61 62 UI::save ( neighbours(i), msg, "to"); 63 UI::save (name,msg,"from"); 64 UI::save ( (string)"expected_times_request", msg, "what"); 65 } 66 } 67 68 69 // 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); 81 } 82 83 } 84 85 void receive(const Setting &msg){ 86 string what; 87 string to; 88 string from; 89 double value; 90 91 92 UI::get(what, msg, "what", UI::compulsory); 93 UI::get(to, msg, "to", UI::compulsory); 94 UI::get(from, msg, "from"); 95 UI::get(value, msg, "value"); 96 if (what=="expected_times_request"){ 97 expected[from]=expected_cars(from); 98 } 99 else if (what=="new_expected_cars") { 100 cout << "Jsem "<< name << " a dostal jsem od "<< from << " predpoklad: " << value << endl; 101 //expected=0; 102 } 103 else { 104 BaseTrafficAgent::receive(msg); 105 } 106 } 107 108 void ds_register(const DS &ds) { 109 BaseTrafficAgent::ds_register(ds); 110 ds2greentimes.set_connection(rv_greentimes, ds._drv()); 111 } 112 113 void from_setting(const Setting &set) { 114 BaseTrafficAgent::from_setting(set); 115 // load from file 116 117 UI::get(sgs, set, "sgs", UI::compulsory); 118 119 } 12 120 }; 13 121 UIREGISTER(GreenWaveTrafficAgent);