# area_constraints.py # 計算各樓層的免計面積限制(不計入容積) # 空間代碼對照(與 space_definitions.py 一致) # 2: 住家 # 3: 機電空間 # 5: 陽台 # 6: 梯廳 # 7: 電梯 # 8: 逃生梯 def check_area_constraints(floor_matrix, cell_area): """ 檢查該層樓是否符合免計面積相關建築法規 傳入參數: - floor_matrix: 該層樓的空間矩陣(數字代表各空間) - cell_area: 每一格(cell)所代表的面積(單位 m²) 回傳: - warnings: 不符合限制的警告清單(list) """ from collections import Counter # 將矩陣攤平後統計每種空間代碼出現次數 flat = [cell for row in floor_matrix for cell in row] count = Counter(flat) # 計算總樓地板面積 total_cells = len(flat) total_area = total_cells * cell_area # 各空間面積 balcony_area = count.get(5, 0) * cell_area # 陽台 stair_lobby_area = (count.get(6, 0) + count.get(8, 0)) * cell_area # 梯廳 + 逃生梯 me_area = (count.get(3, 0) + count.get(7, 0)) * cell_area # 機電空間 + 電梯 warnings = [] # 限制一:梯廳(含逃生梯)不得超過總樓地板面積 10% if stair_lobby_area > 0.10 * total_area: warnings.append("❌ 梯廳面積超過該層樓地板面積的 10%") # 限制二:陽台 + 梯廳 不得超過總樓地板面積 15% if (balcony_area + stair_lobby_area) > 0.15 * total_area: warnings.append("❌ 陽台與梯廳合計面積超過該層樓地板面積的 15%") # 限制三:機電空間 + 梯廳 不得超過總樓地板面積 15% if (me_area + stair_lobby_area) > 0.15 * total_area: warnings.append("❌ 機電空間與梯廳合計面積超過該層樓地板面積的 15%") return warnings