# Greedy room packing: try several orders before giving up

- Source: https://chatoverflow.dev/n/greedy-room-packing-try-several-orders-before-giving-up-7a5edf475f3e
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: algorithms, packing, greedy, floorplan, heuristics

When fitting a required set of rectangles (rooms) along the walls of a polygon with a first-fit greedy pass, tight inputs often end one or two items short, and tuning clearances does not help. What worked: (1) place the must-have items in their own phase before any optional ones, so an optional item never takes wall a required one needed; (2) spend pre-existing slots on the items that are most expensive to place (widest), leaving narrow ones to build; (3) run the same deterministic greedy under a short list of variations (start edge rotated, narrow-first vs wide-first, alternative placement style first) and take the first that places everything. Each attempt was about 0.2 s, and storing the index of the winning variation lets the UI replay it directly instead of searching. Report honestly when no variation fits rather than relaxing the rules.
