[986] | 1 | #include "traffic_agent.h" |
---|
| 2 | |
---|
| 3 | void LaneHandler::connect_data(BaseTrafficAgent& agent0) |
---|
| 4 | { |
---|
| 5 | agent = &agent0; |
---|
| 6 | agentin2input.set_connection(rv_inputs, agent->rv_inputs); |
---|
| 7 | ivec queue_index_tmp = agent->rv_queues.dataind(rv_queue); |
---|
| 8 | if (queue_index_tmp.length()==1){ |
---|
| 9 | queue_index=queue_index_tmp(0); |
---|
| 10 | } else { |
---|
| 11 | bdm_error("queue " + lane.queue + " not found"); |
---|
| 12 | } |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | double LaneHandler::expected_output(double green_time){ |
---|
| 16 | double last_inputs=0.0; |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | agentin2input.filldown(agent->inputs, inputs); |
---|
| 21 | queue = agent->queues(queue_index); |
---|
| 22 | |
---|
| 23 | double exp_output=0.0; |
---|
| 24 | |
---|
| 25 | ///////// |
---|
| 26 | |
---|
| 27 | agentin2input.filldown(agent->inputs,inputs); |
---|
| 28 | |
---|
| 29 | for (int i=0;i<inputs.length();i+=2) { |
---|
| 30 | last_inputs+=inputs(i); |
---|
| 31 | } |
---|
| 32 | |
---|
[1026] | 33 | exp_output=last_inputs*(green_time/agent->step_length); |
---|
[986] | 34 | |
---|
| 35 | //////// |
---|
| 36 | return exp_output; |
---|
| 37 | } |
---|
| 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) { |
---|
[1026] | 45 | density+=inputs(i)/agent->step_length; |
---|
[986] | 46 | } |
---|
| 47 | |
---|
| 48 | return density; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void BaseTrafficAgent::from_setting(const Setting& set) |
---|
| 52 | { |
---|
[1026] | 53 | step_length=90; |
---|
| 54 | cycle_length=80; |
---|
[986] | 55 | |
---|
| 56 | bdm::Participant::from_setting(set); |
---|
| 57 | |
---|
| 58 | // load from file |
---|
| 59 | if (set.exists("lanes")){ |
---|
| 60 | Setting &Slanes=set["lanes"]; |
---|
| 61 | lanes.set_length(Slanes.getLength()); |
---|
| 62 | for(int l=0; l<lanes.length(); l++){ |
---|
| 63 | lanes(l).from_setting(Slanes[l]); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | //UI::get(lanes,set,"lanes", UI::compulsory); |
---|
| 67 | UI::get(neighbours, set, "neighbours", UI::optional); |
---|
| 68 | } |
---|