A hostel PMS developer explains how first-fit bed placement leaves sellable nights stranded and replaces it with augmenting-path bipartite matching, where hard rules prune the graph and preferences live in a cost function.
Key points
- First-fit placement strands a 4-bed dorm at 14 of 28 bed-nights and rejects a three-night request.
- The solver models reservations against beds as bipartite matching with a time dimension and recursive augmenting paths.
- `DisplaceesFor` returns only overlapping stays, so guests on different nights can occupy the same bed.
- `CostOf` sums over-provisioning as a fraction of rate, bed-type change, room fill and displacement, all counted in moves.
- `DisplaceCost` ramps with `DisruptionWeight` divided by the square of the days left until check-in.
- Checked-in guests, worse-bed and worse-price moves, staff locks and split groups are removed as graph edges, not penalties.
Why it matters
Anyone building reservation, seat or capacity logic in .NET hits the same wall: greedy placement works until inventory fragments, and then the fix is a manual shuffle at the front desk. The transferable idea here is the split between rules that delete options from the graph and preferences that only change their price; that is what keeps a backtracking search debuggable.
Before borrowing it, note two limits the author states: plans are locally cheap, not globally optimal, and a new booking never triggers a reshuffle. Concurrency between two simultaneous bookings and how a plan is persisted are left for you to design.
Real-world use
- A 4-bed dorm over one week where a three-night request has no single free bed under first-fit placement
- Re-planning when a bed goes out of service and several guests need new places
- A four-person group booking that must land in one room or be refused
- Interchangeable inventory sold by time slot, such as desks, parking spots or rental bikes
This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original