President Trump’s trade war has hit agricultural and manufacturing hard, causing lower demand for companies that move freight. But railroad stocks soared in 2019 after rail executives embraced automation and cost cutting to remain profitable, doubling down on the idea that rail’s future entails longer, faster trains and fewer workers.