简体   繁体   中英

PuLP - Python - Hotel Revenue Optimization

I'm trying to re-create a paper that uses linear programming to optimize hotel revenue. I have many different x[i,j] that I am trying to solve for where x is bookings accepted and i is check in day and j is check out day. I have demand for each of these [i,j] pairs that I am importing and that the bookings accepted must be <= demand. For the life of me I can't figure out how to program the constraint that on any given day k that the people already in the hotel + people checking in on day k - people checking out on day k must be <= capacity. Here is what I'm trying to code up: 约束

Here's my code so far:

import pandas as pd
import pulp

# Instantiate our problem class
model = pulp.LpProblem("Hotel revenue maximization", pulp.LpMaximize)

#Import demand info
demand= pd.DataFrame.from_csv("demandSAHRO.csv", index_col=
['Check_in_day_i', 'Check_out_day_j'])

#Will optimize for # bookings to accept for any i,j pairing
bookingsaccepted = pulp.LpVariable.dicts("bookingsaccepted",
                                 ((i, j) for i, j in demand.index), lowBound=0, cat='Integer')


# Objective Function - 0.84 is unit revenue per room
model += (
pulp.lpSum([
    0.84 * bookingsaccepted[i, j] for i, j in demand.index])
)

# Constraints
capacity = 400


#Accepted Check in before day k + accepted check in on day k - accepted check out on day k <= capacity
model +=
for i, j in demand.index:
    for k in range(1,10):
    #Day k between check in and check out dates
        while i<k<j:
            #Rooms already occupied during night k
            pulp.lpSum([bookingsaccepted[i, j] for i, j in demand.index]))
            +
            #Rooms checking in on day k

            -

            #Rooms checking out on day k

I'm new to coding in Python and brand new to using PuLP so any help is greatly appreciated.

I created some data to test some cases and I think the following should work. If it does not, please share your demandSAHRO.csv data and I will try to tweak it:

for k in range(1, T):
     model += pulp.lpSum([bookingsaccepted[i, j] \
                        + bookingsaccepted[k, j] \
                        - bookingsaccepted[i, k] \
                        for i, j in demand.index if i < k < j]) \
                        <= capacity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM