Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. # # Commuting Cost Analysis in Helsinki Region
  4. #
  5. #
  6. # Valeri Tsatsishvili
  7. #
  8.  
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11.  
  12. # Initialize: input all necessary information here
  13.  
  14. FuelCons = [7 ,12] # fuel consumption highway(min) and town(max) L per 100km
  15. FuelPrice = 1.45 # how much 1L fuel costs
  16. TotalExpCar = 1200 #'how much do you spend on a car annually including regular bills and repairs/services
  17. InsTaxCar = 700 #'only fixed tax+insurance
  18. PubTrCostInt = 2.20 # Internal single ticket
  19. PubTrCostReg = 4.20 # single 2zone regional ticket
  20. PubTrCostPer = 106.5/30 # 30 day 2 zone regional ticket
  21. DrvNowCostMin = 0.46 # 'DriveNow price per min'
  22. dist=list(range(1,51)) # range of distances in km
  23.  
  24.  
  25.  
  26. # First, lets define couple of functions
  27. FuelConsRange = max(FuelCons) - min(FuelCons)
  28. Scaling = np.round(FuelConsRange/60,3) #here I assume that average speed in Helsinki region can range between 10km/h up to 70km/h.
  29.  
  30. def EstFC(FuelCons,AvgSpeed,Scaling):
  31. # rough estimate of fuel consumption based on average speed
  32. FuelConsEst = max(FuelCons) - AvgSpeed*Scaling
  33. return FuelConsEst
  34.  
  35. def CostAnalysis(dist, AvgSpeed,FuelConsEst,FuelPrice,InsTaxCar,TotalExpCar, DrvNowCostMin):
  36. # estimate costs as a function of distance
  37. TrCostCar = []
  38. TrCostTaxi = []
  39. TrCostDrvNow =[]
  40. DrvNowCostHr= DrvNowCostMin*60
  41. for d in range(1,max(dist)+1):
  42. TrCostCar.append(TotalExpCar/365 + (FuelConsEst/100 * d)*FuelPrice)
  43. TrCostTaxi.append(5.90 + d*1.60 + InsTaxCar/365)
  44. TrCostDrvNow.append(d/AvgSpeed*DrvNowCostHr+InsTaxCar/365)
  45. return TrCostCar, TrCostTaxi,TrCostDrvNow
  46.  
  47.  
  48. # In[] Visualization
  49.  
  50. get_ipython().magic('matplotlib notebook')
  51. from IPython.core.pylabtools import figsize
  52. figsize(10, 15)
  53. plt.figure()
  54. count = 0
  55.  
  56. # The script below iteratively estimates costs for disserent transports at different average speed and plot the results
  57.  
  58. for AvgSpeed in [20, 30, 40]:
  59.  
  60. FuelConsEst = EstFC(FuelCons,AvgSpeed,Scaling)
  61. [TrCostCar, TrCostTaxi,TrCostDrvNow] = CostAnalysis(dist, AvgSpeed,FuelConsEst,FuelPrice,InsTaxCar,TotalExpCar, DrvNowCostMin)
  62.  
  63. count = count + 1
  64. index = 310 + count
  65. plt.subplot(index)
  66.  
  67. plt.plot(dist,TrCostCar,'b.-')
  68. plt.plot(dist,TrCostDrvNow,'g.-')
  69. plt.plot(dist,TrCostTaxi,'r.-')
  70.  
  71. plt.plot(dist,InsTaxCar/365 + PubTrCostInt*np.ones(max(dist)),'c-.')
  72. plt.plot(dist,InsTaxCar/365 + PubTrCostReg*np.ones(max(dist)),'y-.')
  73. plt.plot(dist,InsTaxCar/365 + PubTrCostPer*np.ones(max(dist)),'k-.')
  74.  
  75. # some formatting
  76. plt.title(('Aerage speed in km/h:', AvgSpeed))
  77. plt.xlabel('Distance km')
  78. plt.ylabel('Cost Eur')
  79. plt.legend(['Car','DrvNow','Taxi','PubTrInt','PubTrReg','PubTrPer'])
  80. plt.xticks(np.arange(0,51,5))
  81. plt.xlim(0,55)
  82. plt.ylim(0,30)
  83. plt.grid()
Add Comment
Please, Sign In to add comment