Optimization of discrete event systems conventionally uses simulation as a black-box oracle to estimate performance at design points generated by a separate optimization algorithm. This decoupled approach fails to exploit an important advantage: simulation codes are white-boxes, at least to their creators. In fact, the full integration of the simulation model and the optimization algorithm is possible in many situations. In this contribution, a framework previously proposed by the authors, based on the mathematical programming methodology, is presented under a wider perspective. We show how to derive mathematical models for solving optimization problems while simultaneously considering the dynamics of the system to be optimized. Concerning the solution methodology, we refer back to retrospective optimization (RO) and sample path optimization (SPO) settings. Advantages and drawbacks deriving from the use of mathematical programming as work models within the RO (SPO) framework will be analyzed and its convergence properties will be discussed.