Use of a dimmer pack could kill you - even if voltage never went above 18 VAC.
Use of a dimmer pack could kill your train as if something is able to output 120 VAC but is "limited" to 18 VAC then Murphy has ways of arranging a burst of "more than enough" VAC for "more than long enough" mS to produce magic (train) smoke
There are a number of ways to get 18 VAC or 9 VAC - and it may also be worh finding out why the train com=ntroler needs AC, as it MAY be possible to use DC. It is like that the AC is converted to + DC and - DC supplies by the controller so, while there are ways of feeding + and - DC to the correct points in the controller, if you do not wish to venture into its insides with cutters and soldering iron then using AC will be easier.
You are shown as being in the US.
There are many sources of low cost transformers that would produce 18 VAC from 120 VAC and it would be a really good idea to acquire one. I don't know what Wattage or amperage (W = V x I) you need for your layout, but it is likely that you can acquire a transformer at low to no cost if you are keen enough.
Once you have 18 VAC control of voltage by computer is "relatively easy." The two methods most likely to be attractive are:
As we have covered the question material well enough I won't launch into model control. Let's make sure your needs are met in this area and we can then move to computer control. Note that the hobby community has been active for a very very long time with such things and much will be available on the web.
For 120 VAc: 18 VAC you can use -
2 x 9V secondary
12 + 6V secondary
3 x 6V secondary
Any of these MAY be available on an off the shelf transformer.
Digikey in stock 18 VAC
0.13 A $4.55 111 :-(
2A for $17.39 ~~~
Jameco 18 VAC
$9.95 each AC-to-AC ADAPTER
18V @ 2200mA, BLACK, STRAIGHT 2.1mm FEMALE PLUG Part no. 2076631
Manufacturer AULT INC. Manufacturer no. T57-182200
Basic data sheet
Aha - Ohio.
Cheaper than China :-)
US$2.48 18 VAC 1.1 A. !