File size: 1,567 Bytes
9ed58af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Runway models and operations."""
from enum import Enum
from typing import Optional

from pydantic import BaseModel


class RunwayStatus(str, Enum):
    OPEN = "OPEN"
    REDUCED = "REDUCED"
    CLOSED = "CLOSED"


class Runway(BaseModel):
    id: str
    status: RunwayStatus = RunwayStatus.OPEN
    next_available_step: int = 0
    current_occupant: Optional[str] = None

    @property
    def separation_steps(self) -> int:
        """Separation steps required between aircraft."""
        return 2 if self.status == RunwayStatus.OPEN else 4

    @property
    def is_available(self) -> bool:
        """Check if runway is available for new assignment."""
        return self.status != RunwayStatus.CLOSED

    def occupy(self, aircraft_id: str, current_step: int) -> None:
        """Assign aircraft to runway and set next available time."""
        self.current_occupant = aircraft_id
        self.next_available_step = current_step + self.separation_steps

    def tick(self, current_step: int) -> None:
        """Update runway availability based on current step."""
        if (
            self.current_occupant is not None
            and current_step >= self.next_available_step
        ):
            self.current_occupant = None

    def close(self) -> None:
        """Close the runway."""
        self.status = RunwayStatus.CLOSED
        self.current_occupant = None

    def reduce(self) -> None:
        """Reduce runway capacity (increase separation)."""
        if self.status == RunwayStatus.OPEN:
            self.status = RunwayStatus.REDUCED