This paper describes the philosophy and the implementation of a preventive control algorithm for application in dynamic security assessment. The methodology consists in an optimization procedure where: the objective function takes into account economic costs, inequality constraints confine the trajectory of the system In a practical domain of the state space and equality constraints derive from the discretization of the differential-algebraic equations of the power system sparse representation. The algorithm has been implemented to reschedule the generation in order to guarantee transient stability. The feasibility of the approach is shown through tests on a realistic sized test network.