Qwen 2.5 72B
BuilderWeek 1, Day 3 • 12/15/2024, 11:15:00 AM
System Prompt
Model Response
TerrainAccessibilityScorer Implementation
Based on the research findings regarding ADA 502.4 requirements, I've implemented a terrain-aware accessibility scoring module.
Class Implementation
```pythonclass TerrainAccessibilityScorer:
"""
Scores parking spaces for ADA accessibility compliance
based on terrain slope and entrance proximity.
"""
ADA_MAX_SLOPE = 0.0208 # 1:48 ratio per ADA 502.4
def __init__(self, entrance_locations: List[Tuple[int, int]]):
self.entrances = entrance_locations
def calculate_slope(self, space: ParkingSpace, elevation_map: np.ndarray) -> float:
"""
Calculate the slope gradient for a parking space.
Returns the maximum slope across the space's footprint.
"""
x, y = space.location
width, height = space.dimensions
# Sample elevation points across the space
elevations = elevation_map[y:y+height, x:x+width]
# Calculate gradients in both directions
dx = np.gradient(elevations, axis=1)
dy = np.gradient(elevations, axis=0)
# Return maximum slope magnitude
return float(np.max(np.sqrt(dx**2 + dy**2)))
def distance_to_entrance(self, space: ParkingSpace) -> float:
"""
Calculate minimum distance to any accessible entrance.
"""
x, y = space.center
return min(
math.sqrt((x - ex)**2 + (y - ey)**2)
for ex, ey in self.entrances
)
def score_ada_compliance(
self,
space: ParkingSpace,
elevation_map: np.ndarray
) -> float:
"""
Score a parking space for ADA compliance.
Returns 0 for non-compliant spaces, 0-100 for compliant ones.
"""
slope = self.calculate_slope(space, elevation_map)
# Strict compliance check - slope must be <= 1:48
if slope > self.ADA_MAX_SLOPE:
return 0.0 # Non-compliant, cannot be used
# Calculate base score from slope (lower is better)
slope_score = (1 - slope / self.ADA_MAX_SLOPE) * 50
# Calculate proximity score (closer is better, max 50 points)
proximity = self.distance_to_entrance(space)
proximity_score = max(0, 50 - proximity * 0.5)
return slope_score + proximity_score
```Key Design Decisions
1. **Strict Compliance First**: Non-compliant spaces get a score of 0, preventing them from being designated as accessible.
2. **Dual Scoring**: The final score combines:
3. **Gradient Calculation**: Using numpy's gradient function for efficient slope calculation across the entire space footprint.
Integration Notes
This class is designed to work with the existing `ParkingLotOptimizer` by plugging into the space scoring pipeline:
```pythonoptimizer = ParkingLotOptimizer(config)
accessibility_scorer = TerrainAccessibilityScorer(entrances)
for space in optimizer.candidate_spaces:
space.accessibility_score = accessibility_scorer.score_ada_compliance(
space, elevation_map
)
```Testing Recommendations
The Tester should validate against:
1. Known compliant/non-compliant test cases
2. Edge cases at exactly 1:48 slope
3. Various entrance configurations
4. Performance on large parking lots (500+ spaces)