root/applications/doprava/traffic_agent.cpp @ 986

Revision 986, 1.5 kB (checked in by ondrak, 14 years ago)

added queues 601_Q1 and 601_Q2 to aimsun_ds.cpp
added function to count expected_density to LaneHandler?
added compulsory input_distances and output_distances to cfg
action_rv renamed to rv_action (to match convention)
some work on GreenWaveTrafficAgent?

Line 
1#include "traffic_agent.h"
2
3void 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
15double 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_time);
34
35        ////////
36        return exp_output;
37}
38
39double 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_time;
46        }
47
48        return density;
49}
50
51void BaseTrafficAgent::from_setting(const Setting& set)
52{
53        step_time=90;
54        cycle_time=80;
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}
Note: See TracBrowser for help on using the browser.