How can I get relief from constipation on long train ride?

Walk and drink water. The body often responds to less activity than usual with change in bowel habits, often constipation. When traveling, head this off by frequent walks (harder on planes, but easy on a train). Drink lots of water. Avoid constipating foods- buy or bring healthy snacks that are easily portable, like grapes and carrots.
Bowel training. Create a schedule for trying to have a bowel movement. Take advantage of the "gastrocolic reflex" by sitting on the toilet 20-30 min. After a meal even if you don't feel the urge to go. Load up on laxative foods-fruits, veggies, juices, and water. Remember, if you eat a lot of fiber, you need to drink more fluids. Consult with your doc/or a GI specialist if you need other options-meds.