/*!
\file
\brief Traffic Light Agents
\author Vaclav Smidl.
*/
#ifndef TRAGE_H
#define TRAGE_H
#include
using namespace bdm;
class BaseTrafficAgent;
//! detector of traffic variables
class Lane{
public:
Array inputs;
Array outputs;
vec input_distances;
vec output_distances;
vec alpha; //size of outputs
string queue;
string sg;
//! function loading info from Setting
void from_setting(const Setting &set){
UI::get(inputs,set,"inputs",UI::compulsory);
UI::get(outputs,set,"outputs",UI::compulsory);
UI::get(input_distances,set,"input_distances",UI::compulsory);
UI::get(output_distances,set,"output_distances",UI::compulsory);
UI::get(alpha,set,"alpha",UI::compulsory);
UI::get(queue,set,"queue",UI::compulsory);
UI::get(sg,set,"sg",UI::compulsory);
}
};
//! class that operates on a signal group
class LaneHandler {
protected:
//! pointer to physical lane
const Lane &lane;
//! agent pointer
BaseTrafficAgent *agent;
public:
//! actual data from the relevant signal group
vec inputs;
//!
double queue;
//!
//! description of det_data
RV rv_inputs;
//! description of det_data
RV rv_outputs;
//! description of det_data
RV rv_queue;
//! link from global measured data
datalink agentin2input;
//!
datalink output2agentout;
//!
int queue_index;
public:
LaneHandler(const Lane &lane0): lane(lane0){
for (int i=0;i lanes;
Array lanehs;
//!data from messages
vec inputs;
//! decription of msg_data
RV rv_inputs;
//! data to broadcast
vec outputs;
//! description of broadcast dataind
RV rv_outputs;
vec queues;
//! description of queues
RV rv_queues;
//! datalink from DS to input variables
datalink ds2inputs;
//! datalink from DS to output variables
datalink ds2queues;
//! action description
RV rv_action;
datalink_part action2ds;
Array neighbours;
Array rv_neighbours_out;
Array output2neighbour;
//! simulator's step length in seconds
int step_length;
//! lenght of cycle in seconds
int cycle_length;
public:
void validate(){
lanehs.set_length(lanes.length());
for (int l=0; lrv_inputs);
rv_outputs.add(lanehs(l)->rv_outputs);
rv_queues.add(lanehs(l)->rv_queue);
}
inputs.set_size(rv_inputs._dsize());
outputs.set_size(rv_outputs._dsize());
queues.set_size(rv_queues._dsize());
for (int l=0; lconnect_data(*this);
}
//for -- rv_outputs --
// TODO vybrat rv pro sousedy
rv_neighbours_out.set_length(neighbours.length());
output2neighbour.set_length(neighbours.length());
for (int i=0; ineighbours(i).length()){
rv_neighbours_out(i).add(rv_outputs.subselect(vec_1(r)));
}
}
// connect datasource
output2neighbour(i).set_connection(rv_neighbours_out(i), rv_outputs);
}
// lanehs knows RVS
// write internal checks if all was loaded OK
}
void receive(const Setting &msg){
string what;
UI::get(what, msg, "what", UI::compulsory);
if (what=="new_stable_state"){ //
// field data
// extract decription of teh received datavector
shared_ptr rv=UI::build(msg,"rv",UI::compulsory);
// find if it is needed
ivec ind=rv->dataind(rv_inputs); // position of rv in in_rv;
if (ind.length()>0){ //data are interesting
vec dt;
UI::get(dt, msg, "value",UI::compulsory); // get data
set_subvector(inputs, ind, dt); //check size?
}
} else {
Participant::receive(msg);
}
}
void log_register(logger &L, const string &prefix){
root::log_register ( L, prefix );
if ( log_level[logdata]){
L.add_vector ( log_level, logdata, RV ( 1 ), prefix );
}
}
void log_write() const {
if (log_level[logdata]){
log_level.store(logdata, inputs);
}
}
void broadcast(Setting& set){
// broadcast data to all neighbours
for (int i=0; i