Changeset 840 for applications/doprava/traffic_agent.h
- Timestamp:
- 02/24/10 00:56:13 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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