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 | |
---|
33 | exp_output=last_inputs*(green_time/agent->step_length); |
---|
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) { |
---|
45 | density+=inputs(i)/agent->step_length; |
---|
46 | } |
---|
47 | |
---|
48 | return density; |
---|
49 | } |
---|
50 | |
---|
51 | void BaseTrafficAgent::from_setting(const Setting& set) |
---|
52 | { |
---|
53 | bdm::Participant::from_setting(set); |
---|
54 | |
---|
55 | // load from file |
---|
56 | if (set.exists("lanes")){ |
---|
57 | Setting &Slanes=set["lanes"]; |
---|
58 | lanes.set_length(Slanes.getLength()); |
---|
59 | for(int l=0; l<lanes.length(); l++){ |
---|
60 | lanes(l).from_setting(Slanes[l]); |
---|
61 | } |
---|
62 | } |
---|
63 | //UI::get(lanes,set,"lanes", UI::compulsory); |
---|
64 | UI::get(neighbours, set, "neighbours", UI::optional); |
---|
65 | UI::get(green_names, set, "green_names", UI::compulsory); |
---|
66 | UI::get(green_starts, set, "green_starts", UI::compulsory); |
---|
67 | UI::get(green_times, set, "green_times", UI::compulsory); |
---|
68 | UI::get(stage_names, set, "stage_names", UI::compulsory); |
---|
69 | UI::get(stage_times, set, "stage_times", UI::compulsory); |
---|
70 | } |
---|