Revision 1422, 1.9 kB
(checked in by jabu, 13 years ago)
|
BaseTrafficAgentCt? - zaklad agenta pro rizeni delky cyklu
Master, Observer - rizeni centralnim agentem Master, Observer jen posila data
|
Line | |
---|
1 | #pragma once |
---|
2 | |
---|
3 | #include <cstdlib> |
---|
4 | #include <itpp/itbase.h> |
---|
5 | #include <iostream> |
---|
6 | #include "SO.h" |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | using namespace itpp; |
---|
10 | |
---|
11 | class QueueData { |
---|
12 | public: |
---|
13 | int var_len; |
---|
14 | string sep; |
---|
15 | string id; |
---|
16 | string idInput; |
---|
17 | bool dummy; // prijezdy jen z okolni site |
---|
18 | double queue; |
---|
19 | double input; |
---|
20 | double green; |
---|
21 | Array<string> outputs; |
---|
22 | vec alphas; |
---|
23 | |
---|
24 | QueueData() { |
---|
25 | sep = "##"; |
---|
26 | id = ""; |
---|
27 | idInput = ""; |
---|
28 | queue = 0; |
---|
29 | input = 0; |
---|
30 | dummy = true; |
---|
31 | } |
---|
32 | |
---|
33 | double ss() { |
---|
34 | return 0.5; |
---|
35 | } |
---|
36 | |
---|
37 | string getMessageCode() { |
---|
38 | stringstream str; |
---|
39 | str << "QueueData" << sep << id << sep << idInput; |
---|
40 | for ( int i = 0; i < outputs.length(); i++ ) { |
---|
41 | str << sep << outputs(i); |
---|
42 | } |
---|
43 | return str.str(); |
---|
44 | } |
---|
45 | |
---|
46 | void fromMessageCode( string str ) { |
---|
47 | Array <string> data = SO::explode(str, sep); |
---|
48 | id = data(1); |
---|
49 | idInput = data(2); |
---|
50 | outputs.set_length( data.length() - 3 ); |
---|
51 | for ( int i = 3; i < data.length(); i ++ ) { |
---|
52 | outputs(i-3) = data(i); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | vec getVec() { |
---|
57 | vec out = zeros( 3 + alphas.length() ); |
---|
58 | out(0) = queue; |
---|
59 | out(1) = input; |
---|
60 | out(2) = green; |
---|
61 | for ( int i = 0; i < alphas.length(); i++ ) { |
---|
62 | out(3+i) = alphas(i); |
---|
63 | } |
---|
64 | return out; |
---|
65 | } |
---|
66 | |
---|
67 | void fromVec( const vec & data ) { |
---|
68 | queue = data(0); |
---|
69 | input = data(1); |
---|
70 | green = data(2); |
---|
71 | if ( data.length() > 3 ) { |
---|
72 | alphas = zeros( data.length() - 3 ); |
---|
73 | for ( int i = 3; i < data.length(); i ++ ) { |
---|
74 | alphas(i-3) = data(i); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | string str() { |
---|
81 | stringstream str; |
---|
82 | str << "QueueData {" << endl; |
---|
83 | str << "\tid: " << id << endl; |
---|
84 | str << "\tidInput: " << idInput << endl; |
---|
85 | str << "\tqueue: " << queue << endl; |
---|
86 | str << "\tinput: " << input << endl; |
---|
87 | str << "\tgreen: " << green << endl; |
---|
88 | str << "\tdummy: " << dummy << endl; |
---|
89 | str << "\toutputs: " << outputs << endl; |
---|
90 | str << "\talphas: " << alphas << endl; |
---|
91 | str << "}" << endl; |
---|
92 | return str.str(); |
---|
93 | } |
---|
94 | }; |
---|