Feature engineering transforms raw state information into a compact representation a tabular learner can use. For a gas station, the state keeps current inventory, total pending fuel, and the soonest delivery time instead of recording every order separately. section 6.6
Listing 6.5 State representation with feature engineering\
@dataclass
class EnvironmentState:
"""State representation for the gas station environment."""
current_inventory: int #A
pending_orders: List[Tuple[int, int]] #B
def to_tuple(self) -> Tuple:
"""Convert state to tuple for Q-table indexing."""
inventory = self.current_inventory #C
pending_sum = sum(quantity for quantity, days_left
in self.pending_orders) #D
if self.pending_orders:
next_arrival_time = min(days_left for _, days_left
in self.pending_orders) #E
else:
next_arrival_time = 0 #F
return (inventory, pending_sum, next_arrival_time) #G
See how the gas station state is converted into a tuple for Q-table indexing. section 6.6























