Automatic train regulation (ATR) dominates the service quality, transport capacity, and energy usage of a metro-line operation. The train regulator aims to maximize the schedule/headway adherence while minimizing the energy consumption. This paper presents a traffic-energy model to characterize the complicated dynamics with regard to the traffic and the energy consumption of a metro line, and devises an adaptive-optimal-control (AOC) algorithm to optimize the train regulator through reinforcement learning. The updating rules for reinforcement learning are deduced from the discrete minimum principle. Testing with field traffic data, the AOC algorithm succeeds in the optimization of the train regulator; no matter the system is disturbed by passenger-flow fluctuations or by frequently minor delays. The results also show that better train regulation with less energy consumption is attainable through the running-time and dwell-time controls.