Guest User

Untitled

a guest
Apr 29th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. import java.util.Map;
  2. /**
  3. * Defines a passenger arrival function.
  4. * An arrival function provides the number of passengers
  5. * expected to arrive during a specified interval of time.
  6. * Resolution is by minute (1440 discrete minutes per day).
  7. * <P>
  8. * The arrival function is comprised of
  9. * constituent functions corresponding to
  10. * specific time periods:
  11. * Off-Peak, Morning-Peak, and Evening-Peak.
  12. * Off-Peak is modeled by uniform distribution.
  13. * Morning-Peak and Evening-Peak are modeled by
  14. * Poisson distributions about their respective means
  15. * of 07:30 and 17:00.
  16. * </P><P>
  17. * The function chooses the maximum of the
  18. * values of each of the constituent functions.
  19. * </P>
  20.  
  21. * @version 1.1
  22. * ($Id: PassengerArrivalFunction.java 287 2016-04-26 21:58:40Z nikolaus $)
  23. */
  24.  
  25. public class PassengerArrivalFunction {
  26. /** Number of arrival times that occur.*/
  27. private static final int NUMBER_OF_ARRIVAL_TIMES
  28. = Time.HOURS_PER_DAY * Time.MINUTES_PER_HOUR;
  29.  
  30. /** Default number of passenger arrivals per station per day.*/
  31. public static final int DEFAULT_ARRIVALS_PER_DAY = 5000;
  32.  
  33. /** Default fraction of passenger arrivals during
  34. the morning peak period.*/
  35. public static final double MORNING_PEAK_FRACTION = 0.40;
  36.  
  37. /** Default fraction of passenger arrivals.*/
  38. public static final double EVENING_PEAK_FRACTION = 0.35;
  39.  
  40. /** Default fraction of passenger arrivals during non-peak times.*/
  41. public static final double OFF_PEAK_FRACTION
  42. = 1.00 - (MORNING_PEAK_FRACTION
  43. + EVENING_PEAK_FRACTION);
  44. /** Default probability distribution for Off-Peak.*/
  45. public static final ProbabilityDistribution DEFAULT_OFF_PEAK_DIST
  46. = new Uniform();
  47.  
  48. /** Default probability distribution for Morning-Peak.*/
  49. public static final ProbabilityDistribution DEFAULT_MORNING_PEAK_DIST
  50. = new Poisson();
  51.  
  52. /** Default probability distribution for Evening-Peak.*/
  53. public static final ProbabilityDistribution DEFAULT_EVENING_PEAK_DIST
  54. = new Poisson();
  55.  
  56. /** Start time for Off-Peak.*/
  57. public static final Time OFF_PEAK_START = new Time(0, 00);
  58.  
  59. /** End time for Off-Peak.*/
  60. public static final Time OFF_PEAK_END = new Time(23, 59);
  61.  
  62. /** Mean time for Off-Peak.*/
  63. public static final Time MEAN_OFF_PEAK_TIME = new Time(12, 00);
  64.  
  65. /** Start time for Morning-Peak.*/
  66. public static final Time MORNING_PEAK_START = new Time(6, 00);
  67.  
  68. /**End time for Morning-Peak.*/
  69. public static final Time MORNING_PEAK_END = new Time(9, 00);
  70.  
  71. /** Mean time for Morning-Peak.*/
  72. public static final Time MEAN_MORNING_PEAK_TIME = new Time(7, 30);
  73.  
  74. /** Start time for Evening-Peak.*/
  75. public static final Time EVENING_PEAK_START = new Time(15, 30);
  76.  
  77. /** End time for Evening-Peak.*/
  78. public static final Time EVENING_PEAK_END = new Time(18, 30);
  79.  
  80. /**Mean time for Evening-Peak.*/
  81. public static final Time MEAN_EVENING_PEAK_TIME = new Time(17, 0);
  82.  
  83. /** Enumeration of time periods. */
  84. public enum TimePeriod {
  85. /** Off Peak enum.*/
  86. OFF_PEAK("Off Peak"),
  87. /** Morning Peak enum.*/
  88. MORNING_PEAK("Morning Peak"),
  89. /** Evening Peak.*/
  90. EVENING_PEAK("Evening Peak"),
  91. /** All Day enum.*/
  92. ALL_DAY("All Day");
  93. /** Human-oriented description. */
  94. private String descriptor;
  95. /**
  96. * Constructs a time period with an associated description.
  97. * @param description the description
  98. */
  99. TimePeriod(final String description) {
  100. this.descriptor = description;
  101. }
  102. }
  103.  
  104. /** Expected number of passenger arrivals per day. */
  105. private int passengersExpectedPerDay;
  106.  
  107. /** Off peak time probability distribution. */
  108. private ProbabilityDistribution distributionOffPeak;
  109.  
  110. /** Morning peak time probability distribution. */
  111. private ProbabilityDistribution distributionMorningPeak;
  112.  
  113. /** Evening peak time probability distribution. */
  114. private ProbabilityDistribution distributionEveningPeak;
  115.  
  116. /** Fraction of passengers arriving during off peak time. */
  117. private double offPeakArrivalFraction;
  118.  
  119. /** Fraction of passengers arriving during morning peak time. */
  120. private double morningPeakArrivalFraction;
  121.  
  122. /** Fraction of passengers arriving during evening peak time. */
  123. private double eveningPeakArrivalFraction;
  124.  
  125. /**
  126. * Constructs a default passenger arrival function.
  127. */
  128. public PassengerArrivalFunction() {
  129. this(PassengerArrivalFunction.DEFAULT_ARRIVALS_PER_DAY,
  130. PassengerArrivalFunction.DEFAULT_OFF_PEAK_DIST,
  131. PassengerArrivalFunction.DEFAULT_MORNING_PEAK_DIST,
  132. PassengerArrivalFunction.DEFAULT_EVENING_PEAK_DIST,
  133. PassengerArrivalFunction.OFF_PEAK_FRACTION,
  134. PassengerArrivalFunction.MORNING_PEAK_FRACTION,
  135. PassengerArrivalFunction.EVENING_PEAK_FRACTION);
  136. }
  137. /**
  138. * Constructs a passenger arrival function,
  139. * using specified expected number of passenger arrivals per day.
  140. * Defaults used for amount and distributions of passenger arrivals
  141. * associated with time periods.
  142. *
  143. * @param expectedPassengersPerDay the total number of passengers expected
  144. * per day
  145. */
  146. public PassengerArrivalFunction(final int expectedPassengersPerDay) {
  147. this(expectedPassengersPerDay,
  148. PassengerArrivalFunction.DEFAULT_OFF_PEAK_DIST,
  149. PassengerArrivalFunction.DEFAULT_MORNING_PEAK_DIST,
  150. PassengerArrivalFunction.DEFAULT_EVENING_PEAK_DIST,
  151. PassengerArrivalFunction.OFF_PEAK_FRACTION,
  152. PassengerArrivalFunction.MORNING_PEAK_FRACTION,
  153. PassengerArrivalFunction.EVENING_PEAK_FRACTION);
  154. }
  155. /**
  156. * Constructs a passenger arrival function,
  157. * using specified expected number of passenger arrivals per day
  158. * and probability distributions for time periods.
  159. * Default used for portion of total passenger arrivals
  160. * occurring during each time period.
  161. *
  162. * @param expectedPassengersPerDay the total number of passengers expected
  163. * per day
  164. * @param offPeakDistribution the probability distribution class for
  165. * off-peak periods
  166. * @param morningPeakDistribution the probability distribution class for
  167. * morning-peak
  168. * @param eveningPeakDistribution the probability distribution class for
  169. * evening-peak
  170. */
  171. public PassengerArrivalFunction(final int expectedPassengersPerDay,
  172. final ProbabilityDistribution offPeakDistribution,
  173. final ProbabilityDistribution morningPeakDistribution,
  174. final ProbabilityDistribution eveningPeakDistribution) {
  175. this(expectedPassengersPerDay,
  176. offPeakDistribution,
  177. morningPeakDistribution,
  178. eveningPeakDistribution,
  179. PassengerArrivalFunction.OFF_PEAK_FRACTION,
  180. PassengerArrivalFunction.MORNING_PEAK_FRACTION,
  181. PassengerArrivalFunction.EVENING_PEAK_FRACTION);
  182. }
  183. /**
  184. * Constructs a passenger arrival function,
  185. * using specified expected number of passenger arrivals per day,
  186. * probability distributions for time periods, and fraction of
  187. * arrivals for time periods.
  188. *
  189. * @param expectedPassengersPerDay the total number of passengers expected
  190. * per day
  191. * @param offPeakDistribution the probability distribution class for
  192. * off-peak periods
  193. * @param morningPeakDistribution the probability distribution class for
  194. * morning-peak
  195. * @param eveningPeakDistribution the probability distribution class for
  196. * evening-peak
  197. * @param fractionOffPeak the fraction of arrivals occuring during off-peak
  198. * periods
  199. * @param fractionMorningPeak the fraction of arrivals occuring during the
  200. * morning-peak
  201. * @param fractionEveningPeak the fraction of arrivals occuring during the
  202. * evening-peak
  203. */
  204. public PassengerArrivalFunction(final int expectedPassengersPerDay,
  205. final ProbabilityDistribution offPeakDistribution,
  206. final ProbabilityDistribution morningPeakDistribution,
  207. final ProbabilityDistribution eveningPeakDistribution,
  208. final double fractionOffPeak,
  209. final double fractionMorningPeak,
  210. final double fractionEveningPeak) {
  211. passengersExpectedPerDay = expectedPassengersPerDay;
  212. distributionOffPeak = offPeakDistribution;
  213. distributionMorningPeak = morningPeakDistribution;
  214. distributionEveningPeak = eveningPeakDistribution;
  215. morningPeakArrivalFraction = fractionMorningPeak;
  216. eveningPeakArrivalFraction = fractionEveningPeak;
  217. offPeakArrivalFraction = fractionOffPeak;
  218. }
  219. /**
  220. * Retrieves the number of passengers arriving
  221. * at each discrete minute throughout the day.
  222. * @return all computed values of the function
  223. */
  224. public int[] passengerArrivals() {
  225. return null;
  226. }
  227. /**
  228. * Determines the number of passengers arriving
  229. * in the specified interval.
  230. * @param startTime the beginning of the interval (inclusive)
  231. * @param endTime the end of the interval (exclusive)
  232. * @return the number of passengers arriving during the specified interval
  233. */
  234. public Integer numberOfArrivingPassengers(final Time startTime,
  235. final Time endTime) {
  236. return null;
  237. }
  238. /**
  239. * Retrieves the underlying functions values.
  240. * @return all computed values of the composing functions
  241. */
  242. public Map<TimePeriod, int[]> composingValues() {
  243. return null;
  244. }
  245. /**
  246. * Determines the maximum of three values.
  247. * @param value1 first value
  248. * @param value2 second value
  249. * @param value3 third value
  250. * @return the maximum of the three values
  251. */
  252. private static double maximum(final double value1, final double value2,
  253. final double value3) {
  254. return Math.max(value1, Math.max(value2, value3));
  255. }
  256.  
  257. /**
  258. * Return the number of passengers expected to arrive per day.
  259. * @return The number of passengers expected to arrive per day.
  260. */
  261. protected int getExpectedPassengersPerDay() {
  262. return passengersExpectedPerDay;
  263. }
  264.  
  265. /**
  266. * Return the off peak time probability distribution.
  267. * @return Off peak time probability distribution.
  268. */
  269. protected ProbabilityDistribution getOffPeakDistribution() {
  270. return distributionOffPeak;
  271. }
  272.  
  273. /**
  274. * Return the off peak time probability distribution.
  275. * @return Off peak time probability distribution.
  276. */
  277. protected ProbabilityDistribution getMorningPeakDistribution() {
  278. return distributionMorningPeak;
  279. }
  280.  
  281. /**
  282. * Return the off peak time probability distribution.
  283. * @return Off peak time probability distribution.
  284. */
  285. protected ProbabilityDistribution getEveningPeakDistribution() {
  286. return distributionEveningPeak;
  287. }
  288.  
  289. /**
  290. * Return the off peak arrival fraction.
  291. * @return Off peak arrival fraction.
  292. */
  293. protected double getOffPeakArrivalFraction() {
  294. return offPeakArrivalFraction;
  295. }
  296. /**
  297. * Return the morning peak arrival fraction.
  298. * @return Morning peak arrival fraction.
  299. */
  300. protected double getMorningPeakArrivalFraction() {
  301. return morningPeakArrivalFraction;
  302. }
  303. /**
  304. * Return the evening peak arrival fraction.
  305. * @return Evening peak arrival fraction.
  306. */
  307. protected double getEveningPeakArrivalFraction() {
  308. return eveningPeakArrivalFraction;
  309. }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment