I am glad it was not a multiple choice question. It is a first for me.
To answer the question then. To secure the trestle on 2 inch foam I would wire it down, and underneath with a scrap piece of wood (popsicle stick), twist away at the ends. A stiff base might be necessary. Do it after the track is all done.
Or screw it to a wood base and glue it to the foam. Some glues do not react well with foam. Maybe a wood or construction glue.