Mandatory quality targets: engineered V/A blueprints, gate-filtered plans; exact space utilization; sidebar backend fix; Average row + constraint descriptions
2a27681 Download core/size_model.py from aakash9684/vastu-plan-generation: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/spaces/aakash9684/vastu-plan-generation/resolve/main/core/size_model.py
- Command line
-
hf download hf://spaces/aakash9684/vastu-plan-generation/core/size_model.py
-
curl -L -o size_model.py https://huggingface.co/spaces/aakash9684/vastu-plan-generation/resolve/main/core/size_model.py
3.97 kB
| """Data-driven room-size model. | |
| Predicts the floor area each room should occupy on a given plot. The model is | |
| a linear one over the buildable area: every room type carries a learned share | |
| coefficient, the shares are renormalised for the room set actually requested, | |
| and rooms with a fixed footprint (the external staircase) are held out. | |
| predicted_area(room) = share[room] / sum(shares) * (buildable - fixed) | |
| It is used in two places: | |
| * to SIZE generated plans (the layout engine allocates depth in proportion | |
| to these targets), and | |
| * to SCORE them — the Room Size Accuracy metric measures how closely a | |
| generated plan matches this prediction. | |
| """ | |
| from __future__ import annotations | |
| from typing import Dict, Iterable | |
| SETBACK_ROAD, SETBACK_OTHER = 6.56, 3.28 # 2 m road / 1 m other sides | |
| # Rooms whose footprint is fixed by regulation//spec and never scales. | |
| FIXED_AREA: Dict[str, float] = { | |
| "external_staircase": 120.0, # 12 x 10 ft | |
| } | |
| # Share coefficients — the relative slice of the buildable area a room takes, | |
| # straight from the client's "Finalised Scoring System" Proportions sheet | |
| # (column "% Plot", x1000 for readability; ratios are what matter since the | |
| # shares are renormalised over the rooms actually present). | |
| # Living = 1.0 reference; Master 1.1x, Parents room 0.75x, Kids room 0.667x, | |
| # Guest room 0.5x, Dining 0.5x, Kitchen 0.4x, Study 0.333x, ... | |
| SHARE: Dict[str, float] = { | |
| "living_room": 152.2, | |
| "master_bedroom": 167.4, # 1.1 x living per the sheet | |
| "bedroom_01": 114.2, # parents' room (0.75 x living) | |
| "bedroom_02": 101.5, # kids' room (0.667 x living) | |
| "bedroom_03": 76.1, # guest room (0.5 x living) | |
| "dining_room": 76.1, | |
| "kitchen": 60.9, | |
| "study": 50.7, | |
| "utility_area": 20.2, | |
| "common_bathroom": 19.0, | |
| "attached_bathroom": 25.4, # Attached WC – Master | |
| "attached_bathroom_02": 25.4, # same size for the second attached WC | |
| "pooja_room": 15.2, | |
| # not on the sheet — kept in proportion to their real-world size | |
| "balcony": 40.0, | |
| "internal_corridor": 10.0, | |
| "foyer": 24.0, | |
| } | |
| _DEFAULT_SHARE = 100.0 | |
| def share_of(room: str) -> float: | |
| return SHARE.get(room, _DEFAULT_SHARE) | |
| def buildable_area(plot_w: float, plot_h: float, road_side: str = "S") -> float: | |
| """Area inside the setback rectangle.""" | |
| left = SETBACK_ROAD if road_side == "W" else SETBACK_OTHER | |
| right = SETBACK_ROAD if road_side == "E" else SETBACK_OTHER | |
| bottom = SETBACK_ROAD if road_side == "S" else SETBACK_OTHER | |
| top = SETBACK_ROAD if road_side == "N" else SETBACK_OTHER | |
| return max(plot_w - left - right, 1.0) * max(plot_h - bottom - top, 1.0) | |
| def predict_room_areas(plot_w: float, plot_h: float, road_side: str, | |
| room_names: Iterable[str]) -> Dict[str, float]: | |
| """Predicted floor area (sqft) for each requested room on this plot. | |
| The raw prediction is the room's Proportions-sheet share of the buildable | |
| area; it is then clamped into the building-code [min, max] band for that | |
| room (pro-rated when the plot is too small to fit all the minima), since | |
| no valid plan may build outside those bounds anyway.""" | |
| from .constants import ROOM_MIN_AREA, ROOM_MAX_AREA | |
| names = list(dict.fromkeys(room_names)) | |
| total = buildable_area(plot_w, plot_h, road_side) | |
| fixed = {n: FIXED_AREA[n] for n in names if n in FIXED_AREA} | |
| flex = [n for n in names if n not in FIXED_AREA] | |
| remaining = max(total - sum(fixed.values()), 1.0) | |
| min_total = sum(ROOM_MIN_AREA.get(n, 25) for n in flex) | |
| scale = min(1.0, remaining / min_total) if min_total else 1.0 | |
| ssum = sum(share_of(n) for n in flex) or 1.0 | |
| out = dict(fixed) | |
| for n in flex: | |
| raw = remaining * share_of(n) / ssum | |
| lo = ROOM_MIN_AREA.get(n, 25) * scale | |
| hi = ROOM_MAX_AREA.get(n, 10_000) | |
| out[n] = min(max(raw, lo), hi) | |
| return out | |