Changeset 840
- Timestamp:
- 02/24/10 00:56:13 (15 years ago)
- Location:
- applications/doprava
- Files:
-
- 2 added
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/doprava/CMakeLists.txt
r831 r840 19 19 add_library(traffic_agents traffic_agent.cpp traffic_agent.h) 20 20 21 IF(WIN32) 21 22 include_directories ( aimsun_bdm/eh_api aimsun_bdm/els3/include aimsun_bdm/vgs_api ) 22 # executable 23 EXEC(main_loop traffic_agents aimsun_bdm eh_api vgs_api) 23 # executable 24 EXEC(main_loop traffic_agents aimsun_bdm eh_api vgs_api) 25 ELSE(WIN32) 26 EXEC(main_loop aimsun_bdm traffic_agents ) 27 ENDIF(WIN32) 24 28 29 -
applications/doprava/Zlicin.cfg
r836 r840 17 17 input = ( // remote detectors 18 18 { 19 name = "601 DVA1";19 name = "601_DVA1"; 20 20 distance = 100; 21 21 to_sg = ("VC","VD"); 22 22 }, 23 23 { 24 name = "601 DVA";24 name = "601_DVA"; 25 25 distance = 100; 26 26 to_sg = ("VC","VD"); … … 30 30 { 31 31 from = ("VC"); 32 detector = "495DVC";32 detector = "495_DVC"; 33 33 to = "601"; 34 34 } … … 44 44 { name = "VA"; 45 45 detectors = ( 46 { name = "DVA 1"; distance = 10; },47 {name = "DVA "; distance = 20; }46 { name = "DVA"; distance = 10; }, 47 {name = "DVAa"; distance = 20; } 48 48 ); 49 49 }, -
applications/doprava/aimsun_bdm/CMakeLists.txt
r830 r840 1 1 # Simulator library 2 add_subdirectory(eh_api) 3 add_subdirectory(vgs_api) 2 IF(WIN32) 3 add_subdirectory(eh_api) 4 add_subdirectory(vgs_api) 4 5 5 include_directories(./els3/include ./eh_api ./vgs_api) 6 add_definitions(-DBASE_PATH="${CMAKE_CURRENT_SOURCE_DIR}") 7 add_library (aimsun_bdm aimsun_ds.cpp aimsun_ds.h tools.cpp tools.h) 6 include_directories(./els3/include ./eh_api ./vgs_api) 7 add_definitions(-DBASE_PATH="${CMAKE_CURRENT_SOURCE_DIR}") 8 add_library (aimsun_bdm aimsun_ds.cpp aimsun_ds.h tools.cpp tools.h) 9 ELSE(WIN32) 10 add_library (aimsun_bdm aimsun_fake.cpp aimsun_fake.h) 11 endif(WIN32) -
applications/doprava/aimsun_bdm/aimsun_ds.h
r829 r840 40 40 //! Wait for new data and copy them out to local buffers 41 41 void step(); 42 42 43 //! number of steps 44 int max_length() {return 960;} 45 43 46 // TODO dodelat void to_setting( Setting &root ) const; 44 47 private: -
applications/doprava/main_loop.cpp
r836 r840 9 9 #include "base/user_info.h" 10 10 #include "base/loggers.h" 11 #ifdef _WIN32 11 12 #include "aimsun_bdm/aimsun_ds.h" 13 #else 14 #include "aimsun_bdm/aimsun_fake.h" 15 #endif 12 16 #include "traffic_agent.h" 13 17 … … 67 71 Ags(i) -> broadcast(Queue); 68 72 } 73 //DBG 74 MsgStore.writeFile("xxx"); 69 75 // parse message queue 70 76 for ( int m=Queue.getLength()-1; m>=0; m-- ) { // go backwards - last mesages are discarded … … 91 97 92 98 for ( int i=0; i<Ags.length(); i++ ) { 99 Ags(i) -> log_write(); 93 100 Ags(i) -> step(); 94 101 } -
applications/doprava/traffic_agent.cpp
r820 r840 14 14 bdm::Participant::from_setting(set); 15 15 16 // load from file 16 17 UI::get(sg,set,"sg", UI::compulsory); 17 18 UI::get(requests,set,"output",UI::compulsory); 19 Array<DetectorIn> det_in; 20 UI::get(det_in, set, "input",UI::compulsory); 21 22 // process sg == create handles 23 sgh.set_length(sg.length()); 24 for(int i=0;i<sg.length();i++){ 25 sgh(i).connect_sg(sg(i),name); 26 } 27 28 // process output == handles 29 request_handler.set_length(requests.length()); 30 for(int i=0;i<requests.length();i++){ 31 request_handler(i).connect_request(requests(i),name); 32 output_rv.add(request_handler(i).rv); 33 } 34 // connect 35 for(int i=0;i<requests.length();i++){ 36 request_handler(i).outdata2out.set_connection(request_handler(i).rv, output_rv); 37 // search teh right section == probably inefficient 38 /* int j; 39 for (j=0;j<sg.length();j++){ 40 if (sg(i).name==requests(i).from){ 41 sgh(i).data2out.set_connection(output_rv, sgh(i).det_data); 42 break; 43 } 44 }*/ 45 } 46 47 // process DetIn - create input 48 for (int i=0; i<det_in.length(); i++){ 49 input_rv.add(RV(det_in(i).name,2)); 50 } 51 input_data.set_size(input_rv._dsize()); 18 52 } -
applications/doprava/traffic_agent.h
r836 r840 29 29 //! detector fo incomming flow 30 30 class DetectorIn : public Detector{ 31 string from; // from agent31 public: 32 32 Array<string> to_sg; // to signal plans 33 33 void from_setting(const Setting &set){ 34 34 Detector::from_setting(set); 35 UI::get(from,set,"from",UI::compulsory);36 35 UI::get(to_sg, set, "to_sg", UI::compulsory); 37 36 } … … 76 75 datalink data2out; 77 76 public: 78 SignalGroupHandler(SignalGroup *sg0, const string &agent_name):rv_det_data(){79 sg= sg0;77 void connect_sg(SignalGroup &sg0, const string &agent_name){ 78 sg=&sg0; 80 79 for (int i=0;i<sg->detectors.length();i++){ 81 rv_det_data.add(RV(agent_name + sg->detectors(i).name, 1)); //TODO intensity occupancy80 rv_det_data.add(RV(agent_name +"_"+ sg->detectors(i).name, 2)); //TODO intensity occupancy 82 81 } 83 82 … … 101 100 datalink outdata2out; 102 101 public: 103 RequestHandler(RequestOut *rq0, const string &agent_name){104 rq= rq0;102 void connect_request(RequestOut &rq0, const string &agent_name){ 103 rq=&rq0; 105 104 for (int i=0;i<rq->from.length();i++){ 106 rv.add(RV(agent_name + rq->from(i), 1)); //TODO intensity occupancy105 rv.add(RV(agent_name +"_"+ rq->from(i), 2)); //TODO intensity occupancy 107 106 } 108 107 } … … 131 130 //! description of broadcast dataind 132 131 RV output_rv; 133 134 RV action_rv; 135 136 datalink_part action2ds; 137 132 138 133 //! output recepient 139 134 Array<RequestOut> requests; 140 135 Array<RequestHandler> request_handler; 141 136 137 //! action description 138 RV action_rv; 139 140 datalink_part action2ds; 141 142 142 public: 143 143 void validate(){ 144 144 // write internal checks if all was loaded OK 145 146 // set action variable == this is a feature of the agent! 147 action_rv = RV(name+"_Tc", 1); // <======= example 145 148 } 146 149 void receive(const Setting &msg){ … … 150 153 if (what=="data"){ // 151 154 // field data 152 // ! decription of detected data155 // extract decription of teh received datavector 153 156 shared_ptr<RV> rv=UI::build<RV>(msg,"rv",UI::compulsory); 157 // find if it is needed 154 158 ivec ind=rv->dataind(input_rv); // position of rv in in_rv; 155 if (ind.length()>0){ //data belong here159 if (ind.length()>0){ //data are interesting 156 160 vec dt; 157 UI::get(dt, msg, "value",UI::compulsory); 161 UI::get(dt, msg, "value",UI::compulsory); // get data 158 162 set_subvector(input_data, ind, dt); //check size? 159 163 } … … 162 166 } 163 167 } 168 void log_register(logger &L, const string &prefix){ 169 root::log_register ( L, prefix ); 170 logrec->ids.set_size(sg.length()+2); 171 int i; 172 for (i=0;i <sg.length(); i++) { 173 logrec->ids(i)=logrec->L.add_vector(sgh(i).rv_det_data, ""); 174 } 175 logrec->ids(i)=logrec->L.add_vector(input_rv,"in_"); i++; 176 logrec->ids(i)=logrec->L.add_vector(output_rv,"out_"); 177 } 178 void log_write() const { 179 int i; 180 for (i=0;i <sg.length(); i++) { 181 logrec->L.log_vector(logrec->ids(i), sgh(i).det_data); 182 } 183 logrec->L.log_vector(logrec->ids(i),input_data); i++; 184 logrec->L.log_vector(logrec->ids(i),output_data); i++; 185 } 186 164 187 void broadcast(Setting& set){ 165 188 // broadcast data to all neighbours … … 169 192 170 193 // copy from create message 194 // create msg with fields {to=..., what=data, rv=..., value = ...} 171 195 Setting &m_to=msg.add("to",Setting::TypeString); 172 196 m_to=requests(i).to; … … 181 205 } 182 206 } 183 void adapt(const vec &glob_dt){ 207 void adapt(const vec &glob_dt){ 184 208 // copy data from global vector to sSGHandlers 185 209 for (int i=0; i<sgh.length();i++){ … … 193 217 needs(i) = sgh(i).expected_load(); 194 218 } 195 vec action = needs/sum(needs); // trivial stuff219 vec action; // trivial stuff 196 220 action2ds.filldown(action,glob_ut); 197 221 } … … 199 223 void ds_register(const DS &ds){ 200 224 for (int i=0; i<sgh.length(); i++){ 201 sgh(i).ds2data.set_connection( ds._drv(), sgh(i).rv_det_data);202 } 203 action2ds.set_connection( action_rv, ds._urv());225 sgh(i).ds2data.set_connection(sgh(i).rv_det_data, ds._drv()); 226 } 227 action2ds.set_connection( ds._urv(), action_rv); 204 228 } 205 229