Index: /applications/doprava/traffic_agent.h
===================================================================
--- /applications/doprava/traffic_agent.h (revision 1026)
+++ /applications/doprava/traffic_agent.h (revision 1070)
@@ -1,6 +1,6 @@
 /*!
-  \file
-  \brief Traffic Light Agents 
-  \author Vaclav Smidl.
+\file
+\brief Traffic Light Agents 
+\author Vaclav Smidl.
 */
 
@@ -10,5 +10,5 @@
 
 #include <base/participants.h>
-	
+
 using namespace bdm;
 
@@ -17,73 +17,74 @@
 //! detector of traffic variables
 class Lane{
-	public:
-		Array<string> inputs;
-		Array<string> 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);
-			
-		}
+public:
+	Array<string> inputs;
+	Array<string> outputs;
+	vec input_distances;
+	vec output_distances;
+	vec alpha; //size of outputs
+	//! percent of queue lenght (for "multiline queues")
+	double beta;
+	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);
+		UI::get(beta, set, "beta");
+	}
 };
 
 //! 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<lane0.inputs.length();i++){
-				rv_inputs.add(RV(lane.inputs(i), 2));
-			}
-			for (int i=0;i<lane0.outputs.length();i++){
-				rv_outputs.add(RV(lane.outputs(i), 2)); 
-			}
-			rv_queue.add(RV(lane.queue, 1)); 
-			inputs.set_size(rv_inputs._dsize());
-		}
-		
-		
-		void connect_data(BaseTrafficAgent &agent0);
-
-		//! computes expected density in cars/s
-		double expected_density();
-
-		//! arbitrary function that computes the need of the signal group for green light in common units (number of waiting cars?)
-		double expected_output(double green_time);
+protected:
+	//! pointer to physical lane
+	const Lane &lane;
+	//! agent pointer
+	BaseTrafficAgent *agent;
+
+public:
+	//! actual data from the relevant signal group
+	vec inputs;
+	//! queue length
+	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<lane0.inputs.length();i++){
+			rv_inputs.add(RV(lane.inputs(i), 2));
+		}
+		for (int i=0;i<lane0.outputs.length();i++){
+			rv_outputs.add(RV(lane.outputs(i), 2)); 
+		}
+		rv_queue.add(RV(lane.queue, 1)); 
+		inputs.set_size(rv_inputs._dsize());
+	}
+
+
+	void connect_data(BaseTrafficAgent &agent0);
+
+	//! computes expected density in cars/s
+	double expected_density();
+
+	//! arbitrary function that computes the need of the signal group for green light in common units (number of waiting cars?)
+	double expected_output(double green_time);
 };
 
@@ -93,159 +94,181 @@
 */
 class BaseTrafficAgent : public Participant {
-	LOG_LEVEL(BaseTrafficAgent,logdata);
-	public:
-		//! Signal Groups
-		Array<Lane> lanes;
-
-		Array<LaneHandler*> 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<string> neighbours;
-		
-		Array<RV> rv_neighbours_out;
-		
-		Array<datalink> 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; l<lanes.length(); l++){
-				lanehs(l) = new LaneHandler(lanes(l));
-				
-				rv_inputs.add(lanehs(l)->rv_inputs);
-				rv_outputs.add(lanehs(l)->rv_outputs);
-				rv_queues.add(lanehs(l)->rv_queue);
+
+LOG_LEVEL(BaseTrafficAgent,logdata);
+public:
+	//! Signal Groups
+	Array<Lane> lanes;
+
+	Array<LaneHandler*> 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;
+
+	//! 
+	vec green_starts;
+
+	//!
+	vec green_times;
+
+	//!
+	Array<string> green_names;
+
+	//!
+	Array<string> stage_names;
+
+	//!
+	vec stage_times;
+
+
+
+
+
+	//! 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<string> neighbours;
+
+	Array<RV> rv_neighbours_out;
+
+	Array<datalink> output2neighbour;
+
+	//! simulator's step length in seconds
+	static const int step_length=90;
+
+	//! lenght of cycle in seconds
+	static const int cycle_length=80;
+
+
+
+public:
+	void validate(){
+
+		lanehs.set_length(lanes.length());
+		for (int l=0; l<lanes.length(); l++){
+			lanehs(l) = new LaneHandler(lanes(l));
+
+			rv_inputs.add(lanehs(l)->rv_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; l<lanes.length(); l++){
+			lanehs(l)->connect_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; i<neighbours.length(); i++){
+			for (int r=0; r<rv_outputs.length(); r++){
+				int str_pos = rv_outputs.name(r).compare(neighbours(i));
+				if (str_pos>neighbours(i).length()){
+					rv_neighbours_out(i).add(rv_outputs.subselect(vec_1(r)));
+				}
 			}
-			inputs.set_size(rv_inputs._dsize());
-			outputs.set_size(rv_outputs._dsize());
-			queues.set_size(rv_queues._dsize());
-			
-			for (int l=0; l<lanes.length(); l++){
-				lanehs(l)->connect_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; i<neighbours.length(); i++){
-				for (int r=0; r<rv_outputs.length(); r++){
-					int str_pos = rv_outputs.name(r).compare(neighbours(i));
-					if (str_pos>neighbours(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> rv=UI::build<RV>(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<neighbours.length(); i++){
-				Setting &msg =set.add(Setting::TypeGroup);
-				
-				// if...
-				// copy from create message
-				// create msg with fields {to=..., what=data, rv=..., value = ...}
-				UI::save ( neighbours(i), msg, "to");
-				UI::save ( (string)"new_stable_state", msg, "what");
-				UI::save ( &(rv_neighbours_out(i)), msg, "rv");
-				UI::save( output2neighbour(i).pushdown(outputs), msg, "value");
-			}
-			
-		}
-		void adapt(const vec &glob_dt){
-			// copy data from global vector to sSGHandlers
-			ds2inputs.filldown(glob_dt, inputs);
-			//copy data from neighbours
-			ds2queues.filldown(glob_dt, queues);
-			// copy sg_length ... and others...
-		}
-		void act(vec &glob_ut){
-			vec action; // trivial stuff
-			action2ds.filldown(action,glob_ut);
-		}
-		
-		void ds_register(const DS &ds){
-			//register ds2output
-			ds2inputs.set_connection(rv_inputs, ds._drv());
-			ds2queues.set_connection(rv_queues, ds._drv());
-			
-			inputs.set_size(rv_inputs._dsize());
-			action2ds.set_connection( ds._urv(), rv_action);
-
-		}
-		
-		void from_setting(const Setting &set);
+			// 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> rv=UI::build<RV>(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<neighbours.length(); i++){
+			Setting &msg =set.add(Setting::TypeGroup);
+
+			// if...
+			// copy from create message
+			// create msg with fields {to=..., what=data, rv=..., value = ...}
+			UI::save ( neighbours(i), msg, "to");
+			UI::save ( (string)"new_stable_state", msg, "what");
+			UI::save ( &(rv_neighbours_out(i)), msg, "rv");
+			UI::save( output2neighbour(i).pushdown(outputs), msg, "value");
+		}
+
+	}
+	void adapt(const vec &glob_dt){
+		// copy data from global vector to sSGHandlers
+		ds2inputs.filldown(glob_dt, inputs);
+		//copy data from neighbours
+		ds2queues.filldown(glob_dt, queues);
+		// copy sg_length ... and others...
+	}
+	void act(vec &glob_ut){
+		vec action; // trivial stuff
+		action2ds.filldown(action,glob_ut);
+	}
+
+	void ds_register(const DS &ds){
+		//register ds2output
+		ds2inputs.set_connection(rv_inputs, ds._drv());
+		ds2queues.set_connection(rv_queues, ds._drv());
+
+		inputs.set_size(rv_inputs._dsize());
+		action2ds.set_connection( ds._urv(), rv_action);
+
+	}
+
+	void from_setting(const Setting &set);
 };
 UIREGISTER(BaseTrafficAgent);
Index: /applications/doprava/Zlicin.cfg
===================================================================
--- /applications/doprava/Zlicin.cfg (revision 1026)
+++ /applications/doprava/Zlicin.cfg (revision 1070)
@@ -4,10 +4,22 @@
 	name = "495";
 	lanes = (
-			{ sg="VA"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVA"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q1";}, 
-			{ sg="VB"; inputs = ("495_DVA1","495_DVB");  outputs= ("601_DVB"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="495_Q2";}
+			{ sg="VA"; inputs = ("495_DVA1");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_QA"; beta=1;}, 
+			{ sg="VB"; inputs = ("495_DVB1");  outputs= ("601_DVA","601_DVAa"); input_distances=[30]; output_distances=[190,190]; alpha= [0.5,0.5 ]; queue="495_QB"; beta=1;},
+			{ sg="VC"; inputs = ("495_DVC");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_QC"; beta=1;}, 
+			{ sg="VD"; inputs = ("495_DVD");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_QD"; beta=1;},
+			{ sg="VE"; inputs = ("495_DVE");  outputs= ("601_DVA","601_DVAa"); input_distances=[30]; output_distances=[190,190]; alpha= [0.5,0.5 ]; queue="495_QE"; beta=1;}, 
+			{ sg="VF"; inputs = ("495_DVF1");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="495_QF"; beta=1;}
 	);
+	// alfa - pomer odboceni
+	// beta (Kamil) jeho vlastni pomerna cast fronty
 	neighbours = ("601");
   	offset = 10; //s
   	moje_special=14;
+  green_names = ("495_VA","495_VB","495_VC","495_VD","495_VE","495_VF");
+  green_starts=[72,4,5,35,36,71];
+  green_times = [];// ratios of green of 80s
+  stage_names = ("495_F1","495_F2","495_F3");
+  stage_times = [30,30,20];
+  
 },
 { //agent 2
@@ -15,9 +27,24 @@
 	name = "601";
 	lanes = (
-			{ sg="VA"; inputs = ("601_DVA","601_DVB");  outputs= ("495_DVA"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q1";}, 
-			{ sg="VB"; inputs = ("601_DVC","601_DVD");  outputs= ("495_DVB"); input_distances=[30,30]; output_distances=[200]; alpha= [1.0 ]; queue="601_Q2";}
+			{ sg="VA"; inputs = ("601_DVA");  outputs= ("DUMMY_DET","DUMMY_DET"); input_distances=[30]; output_distances=[200,200]; alpha= [0.54, 0.46 ]; queue="601_QA"; beta=0.5;}, 
+			{ sg="VA"; inputs = ("601_DVAa");  outputs= ("DUMMY_DET","DUMMY_DET"); input_distances=[30]; output_distances=[200,200]; alpha= [0.44,0.56]; queue="601_QA"; beta=0.5;},
+			{ sg="VB"; inputs = ("601_DVB1");  outputs= ("DUMMY_DET","495_DVC","495_DVD"); input_distances=[30]; output_distances=[200,190,190]; alpha= [0.1,0.4,0.5 ]; queue="601_QB"; beta=0.5;}, 
+			{ sg="VB"; inputs = ("601_DVB1");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_QB"; beta=0.5;},
+			{ sg="VC"; inputs = ("601_DVC");  outputs= ("495_DVC","495_DVD","DUMMY_DET"); input_distances=[30]; output_distances=[190,190,200]; alpha= [0.35,0.35,0.3 ]; queue="601_QC"; beta=1;}, 
+			{ sg="VD"; inputs = ("601_DVD1");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_QD"; beta=1;},
+			{ sg="SE"; inputs = ("601_DSE1");  outputs= ("DUMMY_DET"); input_distances=[30]; output_distances=[200]; alpha= [1.0 ]; queue="601_QSE"; beta=1;}, 
+			{ sg="VE"; inputs = ("601_DVE1");  outputs= ("495_DVC","495_DVD"); input_distances=[30]; output_distances=[190,190]; alpha= [0.5,0.5 ]; queue="601_QE"; beta=1;}
 	);  
 	neighbours = ("495");
 	offset = 40;
+	green_names = ("601_VA","601_VB","601_VC","601_VD","601_VE","601_VF");
+  green_starts=[72,4,5,35,36,71];
+  green_times = [];// ratios of green of 80s
+  stage_names = ("601_F1","601_F2","601_F3");
+  stage_times = [30,30,20];
+	
+	
+	
+  
 
 }
@@ -26,7 +53,4 @@
 
 logger = {class="memlog"; filename = "mujlog"; maxlen = 1000;};
-
-
-
 
 system = {
@@ -41,5 +65,5 @@
 	// simulation in our case starts always at 00:00:00. Default simulation
 	// length is 24 hours (24:00:00).
-	stop_time = "01:00:00";
+	stop_time = "00:05:00";
 	
 };
@@ -47,2 +71,5 @@
 //Number of recieve/broadcast calls before end of negotiation
 negotiation_cycles = 5;
+
+cycle_lenght=80; 
+step_length=90; //simulator's step length
Index: /applications/doprava/traffic_agent.cpp
===================================================================
--- /applications/doprava/traffic_agent.cpp (revision 1026)
+++ /applications/doprava/traffic_agent.cpp (revision 1070)
@@ -51,7 +51,4 @@
 void BaseTrafficAgent::from_setting(const Setting& set)
 {
-	step_length=90;
-	cycle_length=80;
-
 	bdm::Participant::from_setting(set);
 	
@@ -66,3 +63,8 @@
 	//UI::get(lanes,set,"lanes", UI::compulsory);
 	UI::get(neighbours, set, "neighbours", UI::optional);
+	UI::get(green_names, set, "green_names", UI::compulsory);
+	UI::get(green_starts, set, "green_starts", UI::compulsory);
+	UI::get(green_times, set, "green_times", UI::compulsory);
+	UI::get(stage_names, set, "stage_names", UI::compulsory);
+	UI::get(stage_times, set, "stage_times", UI::compulsory);
 }
