@@ -632,7 +632,7 @@ def set_traveltime_instant(s):
632632 s .traveltime_instant .append (s .traveltime_instant [- 1 ])
633633
634634
635- def arrival_count (s , t ) :
635+ def arrival_count (s , t : float ) -> float :
636636 """
637637 Get cumulative vehicle count of arrival to this link on time t.
638638
@@ -653,7 +653,7 @@ def arrival_count(s, t):
653653 return s .cum_arrival [0 ]
654654 return s .cum_arrival [tt ]
655655
656- def departure_count (s , t ) :
656+ def departure_count (s , t : float ) -> float :
657657 """
658658 Get cumulative vehicle count of departure from this link on time t.
659659
@@ -673,8 +673,40 @@ def departure_count(s, t):
673673 if tt < 0 :
674674 return s .cum_departure [0 ]
675675 return s .cum_departure [tt ]
676+
677+ def num_vehicles_t (s , t : float ) -> float :
678+ """
679+ Get number of vehicles on this link on time t.
680+
681+ Parameters
682+ ----------
683+ t : float
684+ Time in seconds.
676685
677- def instant_travel_time (s , t ):
686+ Returns
687+ -------
688+ float
689+ The number of vehicles.
690+ """
691+ return s .arrival_count (t )- s .departure_count (t )
692+
693+ def average_density (s , t : float ) -> float :
694+ """
695+ Get average density of this link on time t.
696+
697+ Parameters
698+ ----------
699+ t : float
700+ Time in seconds.
701+
702+ Returns
703+ -------
704+ float
705+ The average density.
706+ """
707+ return float (s .num_vehicles_t (t )/ s .length )
708+
709+ def instant_travel_time (s , t : float ) -> float :
678710 """
679711 Get instantaneous travel time of this link on time t.
680712
@@ -694,8 +726,8 @@ def instant_travel_time(s, t):
694726 if tt < 0 :
695727 return s .traveltime_instant [0 ]
696728 return s .traveltime_instant [tt ]
697-
698- def actual_travel_time (s , t ) :
729+
730+ def actual_travel_time (s , t : float ) -> float :
699731 """
700732 Get actual travel time of vehicle who enters this link on time t. Note that small error may occur due to fractional processing.
701733
@@ -716,6 +748,38 @@ def actual_travel_time(s, t):
716748 return s .traveltime_actual [0 ]
717749 return s .traveltime_actual [tt ]
718750
751+ def average_speed (s , t : float ) -> float :
752+ """
753+ Get average speed (=inverse of instantaneous travel time) of this link on time t.
754+
755+ Parameters
756+ ----------
757+ t : float
758+ Time in seconds.
759+
760+ Returns
761+ -------
762+ float
763+ The instantaneous travel time.
764+ """
765+ return float (s .length / s .instant_travel_time (t ))
766+
767+ def average_flow (s , t : float ) -> float :
768+ """
769+ Get average flow of this link on time t.
770+
771+ Parameters
772+ ----------
773+ t : float
774+ Time in seconds.
775+
776+ Returns
777+ -------
778+ float
779+ The average flow.
780+ """
781+ return float (s .average_speed (t )* s .average_density (t ))
782+
719783 #getter/setter
720784 @property
721785 def speed (s ):
0 commit comments