The compression of a cw into a periodic train of noninteracting solitons by a dispersion-decreasing fiber is investigated with a variational method. To model the evolution from the cw to the soliton train, an elliptic-function-based expression is used as the trial function in the averaged Lagrangian. Both a continuous dispersion variation and a step dispersion variation in the fiber are considered. By use of an optimization method based on the approximate variational equations, the optimal dispersion profile required for achieving maximum pulse compression in a fixed length of fiber is determined. The solutions of the approximate equations are compared with full numerical solutions of the governing nonlinear Schrodinger equation, and good agreement is found.