Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- from binomialPoisson import *
- hugeNumber = float("inf")
- unused = -1000
- stages = 10
- seats = 50
- fullFare = 500
- discountFare = 250
- costOccupied = 8
- meanFullDemand = numpy.array([unused,
- 1.3, 1.4, 1.9, 2.0, 2.2,
- 2.8, 2.2, 2.4, 1.8, 3.7])
- maxCanRelease = [unused, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5]
- f = numpy.zeros([stages+2, seats+1])
- x = numpy.zeros([stages+1, seats+1], dtype=int)
- # Iterate through stages
- for t in range(stages, 0, -1):
- # Iterate through possible states (ie, number of seats occupied)
- for i in range(seats + 1):
- demandProbability = poisson(meanFullDemand[t], seats)
- value = -hugeNumber
- maxReleased = min(maxCanRelease[t], seats-i)
- for p in range(maxReleased+1):
- moveValue = -costOccupied*p + 250*p
- seats_unoccupied = seats - i - p
- for r in range(seats_unoccupied+1):
- j = seats_unoccupied - r
- moveValue += demandProbability[r]*(500*r + f[t+1, j])
- if moveValue > value:
- value = moveValue
- bestMove = p
- f[t, i] = value
- x[t, i] = bestMove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement