The Shu”t Veya’an Yosef (Yoreh Deah 144, ois 1) was asked about men traveling on a busy train when it’s very squashy and bumpy and it leads to: חציפות וטומאה אשר אין להעלות על הכתב אשר על ידי כך באים לידי נסיונות גדולות של אביזרייהו דגילוי עריות רחמנא ליצלן – “Obscenity and impurity that cannot be written down, and leads to terrible tests related to giluy aroyas, may G-d have mercy on us”.
He quotes the Shach (Yoreh Deah 195:20) who says that there is no de’O’raisa if it is not being done derech teivah vechibah, however, he writes: “Who knows if chas vesholam he is not included in this, perhaps he is one who is, אש בנעורת וכו' - fire in flax (see Sotah 48a), therefore, it’s obvious that if one can avoid this, and can go to work on a train which travels earlier on in the morning, he should do so, and one is even obligated to do so.
If traveling earlier (or later) is not possible, then at least every single time before setting out to travel one should rethink that if chas vesholam he accidentally bumps into a woman etc. he will be very upset about it and have lots of agmas nefesh. He should already feel bad about it before he does it: כדי שלא יפול לשאול תחתית של עבירה שהוא ביהרג ואל יעבור – “so that he does not fall into the bottomless pit of a sin which one must be prepared to give up his life for”.
He writes that this should be publicized, so that people understand the danger involved: והשם יתברך יציל עמו בית ישראל מכל פגעים רעים ומרעין בישין וימציא פרנסם בהיתר ובנחת – “And Hashem Yisborach, will save the Klal Yisroel from all evil harm and from the root of shame, and will provide for their livelihood in peace and comfort.”