Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import numpy
  2. from binomialPoisson import *
  3.  
  4. hugeNumber = float("inf")
  5. unused = -1000
  6.  
  7. stages = 10
  8. seats = 50
  9. fullFare = 500
  10. discountFare = 250
  11. costOccupied = 8
  12.  
  13. meanFullDemand = numpy.array([unused,
  14. 1.3, 1.4, 1.9, 2.0, 2.2,
  15. 2.8, 2.2, 2.4, 1.8, 3.7])
  16.  
  17. maxCanRelease = [unused, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5]
  18.  
  19.  
  20. f = numpy.zeros([stages+2, seats+1])
  21. x = numpy.zeros([stages+1, seats+1], dtype=int)
  22.  
  23. # Iterate through stages
  24. for t in range(stages, 0, -1):
  25.  
  26. # Iterate through possible states (ie, number of seats occupied)
  27. for i in range(seats + 1):
  28.  
  29. demandProbability = poisson(meanFullDemand[t], seats)
  30.  
  31. value = -hugeNumber
  32. maxReleased = min(maxCanRelease[t], seats-i)
  33.  
  34. for p in range(maxReleased+1):
  35.  
  36. moveValue = -costOccupied*p + 250*p
  37.  
  38. seats_unoccupied = seats - i - p
  39.  
  40. for r in range(seats_unoccupied+1):
  41. j = seats_unoccupied - r
  42. moveValue += demandProbability[r]*(500*r + f[t+1, j])
  43.  
  44. if moveValue > value:
  45. value = moveValue
  46. bestMove = p
  47.  
  48. f[t, i] = value
  49. x[t, i] = bestMove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement