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.