Index: applications/doprava/traffic_agent_offset.h
===================================================================
--- applications/doprava/traffic_agent_offset.h (revision 1111)
+++ applications/doprava/traffic_agent_offset.h (revision 1118)
@@ -137,90 +137,89 @@
 					}
 				}
-				if (found) {			
-
-					//counting rating
-					string group = name+"_"+lanes(i).sg;		//e.g. 495_VA
-					int index=group_index(group);
-
-					t_green_begin=green_starts(index) + offset;
-					double green_time=green_times(index)*cycle_length;
-					t_green_end=t_green_begin+green_time;
-
-					/************** counting with all exps ****************/
-
-					int k;
-					double t_act=t_green_begin;
-					virtual_queue=lanehs(i)->queue;
-
-					//cycle goes through all "stopping" points and counts queue lenght at these points
-					do {
-						k=min_i(t_cars_begin);
-
-						if (k!=-1) {						
-							double a=cars_count(k);
-							double b=t_cars_begin(k);
-							double c=t_cars_end(k);
-
-							//in case there are cars comming before t_green begin
-							if (t_cars_begin(k)<t_act) {
-								if (t_cars_end(k)<=t_act) {
-									virtual_queue+=cars_count(k);
-									
-									cars_count.del(k);
-									t_cars_begin.del(k);
-									t_cars_end.del(k);
-
-								}
-								else {
-									double pomer=(t_cars_begin(k)-t_act)/(t_cars_end(k)-t_cars_begin(k));
-									virtual_queue+=cars_count(k)*pomer;
-									t_cars_begin(k)=t_act;
-								}
+
+			}
+			if (found) {			
+
+				//counting rating
+				string group = name+"_"+lanes(i).sg;		//e.g. 495_VA
+				int index=group_index(group);
+
+				t_green_begin=green_starts(index) + offset;
+				double green_time=green_times(index)*cycle_length;
+				t_green_end=t_green_begin+green_time;
+
+				/************** counting with all exps ****************/
+
+				int k;
+				double t_act=t_green_begin;
+				virtual_queue=lanehs(i)->queue;
+
+				//cycle goes through all "stopping" points and counts queue lenght at these points
+				do {
+					k=min_i(t_cars_begin);
+
+					if (k!=-1) {						
+						double a=cars_count(k);
+						double b=t_cars_begin(k);
+						double c=t_cars_end(k);
+
+						//in case there are cars comming before t_green begin
+						if (t_cars_begin(k)<t_act) {
+							if (t_cars_end(k)<=t_act) {
+								virtual_queue+=cars_count(k);
+
+								cars_count.del(k);
+								t_cars_begin.del(k);
+								t_cars_end.del(k);
+
 							}
-							else if (t_cars_begin(k)==t_act) {
-								if (t_cars_end(k)<t_green_end) {
-									virtual_queue+=cars_count(k)-(t_cars_end(k)-t_act)/car_leaving;
-									t_act=t_cars_end(k);
-
-									cars_count.del(k);
-									t_cars_begin.del(k);
-									t_cars_end.del(k);
-								}
-								//if t_cars_end>=t_green_end
-								else {
-									virtual_queue+=cars_count(k)-(t_green_end-t_act)/car_leaving;
-									t_act=t_green_end;
-
-									cars_count.del(k);
-									t_cars_begin.del(k);
-									t_cars_end.del(k);							
-								}
-
-
-							}
-							//if t_cars_begin(k)>=t_act
 							else {
-								if (t_cars_end(k)<t_green_end) {
-									virtual_queue-=(t_cars_end(k)-t_act)/car_leaving;
-									t_act=t_cars_end(k);
-								}
-								else {
-									virtual_queue-=(t_green_end-t_act)/car_leaving;
-									t_act=t_green_end;
-								}
+								double pomer=(t_cars_begin(k)-t_act)/(t_cars_end(k)-t_cars_begin(k));
+								virtual_queue+=cars_count(k)*pomer;
+								t_cars_begin(k)=t_act;
 							}
 						}
-						//if no other expectations found
+						else if (t_cars_begin(k)==t_act) {
+							if (t_cars_end(k)<t_green_end) {
+								virtual_queue+=cars_count(k)-(t_cars_end(k)-t_act)/car_leaving;
+								t_act=t_cars_end(k);
+
+								cars_count.del(k);
+								t_cars_begin.del(k);
+								t_cars_end.del(k);
+							}
+							//if t_cars_end>=t_green_end
+							else {
+								virtual_queue+=cars_count(k)-(t_green_end-t_act)/car_leaving;
+								t_act=t_green_end;
+
+								cars_count.del(k);
+								t_cars_begin.del(k);
+								t_cars_end.del(k);							
+							}
+						}
+						//if t_cars_begin(k)>=t_act
 						else {
-							virtual_queue-=(t_green_end-t_act)/car_leaving;
-							t_act=t_green_end;
+							if (t_cars_end(k)<t_green_end) {
+								virtual_queue-=(t_cars_end(k)-t_act)/car_leaving;
+								t_act=t_cars_end(k);
+							}
+							else {
+								virtual_queue-=(t_green_end-t_act)/car_leaving;
+								t_act=t_green_end;
+							}
 						}
-						if (virtual_queue<0) {
-							rating-=virtual_queue;
-							virtual_queue=0;
-						}
-
-					} while (t_act<t_green_end);
-				}
+					}
+					//if no other expectations found
+					else {
+						virtual_queue-=(t_green_end-t_act)/car_leaving;
+						t_act=t_green_end;
+					}
+					if (virtual_queue<0) {
+						rating-=virtual_queue;
+						virtual_queue=0;
+					}
+
+				} while (t_act<t_green_end);
 			}
 		}
@@ -244,5 +243,5 @@
 
 		new_center=center;
-		int max_index=max_of_three(rating_p,rating_c,rating_n);
+		int max_index=max_i_of_three(rating_p,rating_c,rating_n);
 		switch (max_index) {
 			case 0:
@@ -309,5 +308,5 @@
 		recieved_exps=original_exps;
 
-		int max_index=max_of_three(rating_p,rating_c,rating_n);
+		int max_index=max_i_of_three(rating_p,rating_c,rating_n);
 		switch (max_index) {
 			case 0:
@@ -433,5 +432,5 @@
 
 	//! returns index of maximum of entered values
-	int max_of_three(const double a, const double b, const double c) {
+	int max_i_of_three(const double a, const double b, const double c) {
 		int index = a > b ? 0 : 1;
 
@@ -606,8 +605,10 @@
 			//split_exps();
 			
-			last_offset=planned_offset;
-
-			planned_offset=find_best_offset(planned_offset,8);
-			planned_offset=normalize_offset(planned_offset);
+			
+			if (!passive) {
+				last_offset=planned_offset;
+				planned_offset=find_best_offset(planned_offset,8);
+				planned_offset=normalize_offset(planned_offset);
+			}
 			
 
@@ -748,15 +749,17 @@
 	}
 
-	//void log_register(logger &l, const string &prefix){
-	//	if ( log_level[logoffset]){
-	//		l.add_vector ( log_level, logoffset, RV("mujoffset",1), prefix );	
-	//	}
-	//}
-	//void log_write() const {
-	//	if (log_level[logoffset]){
-	//		log_level.store(logoffset, (double)planned_offset);
-	//		//log_level.store(logoffset, planned_rating);
-	//	}
-	//}
+	void log_register(logger &l, const string &prefix){
+		if ( log_level[logoffset]){
+			l.add_vector ( log_level, logoffset, RV("mujoffset",1), prefix );	//TODO 
+		}
+	}
+	void log_write() const {
+		if (log_level[logoffset]){
+			vec offset_vec(1);
+			offset_vec(0)=(double)planned_offset;
+			log_level.store(logoffset, offset_vec);
+			//log_level.store(logoffset, planned_rating);
+		}
+	}
 
 
