Particle accelerators are complex systems with a large number of tuning parameters (several hundreds) and many operational constraints (equipment operating ranges, limited beam losses to avoid the production of radiations and activations…). In this field optimization codes are used for beam physics studies (resolution of systems of nonlinear differential equations…) and also during the design studies to find the best accelerator structure to reach the desired performances minimizing both construction and operation costs. Optimization codes are also used during the operation phase to find “optimal commands”, the code acting directly on the accelerator equipments (magnets, rf cavities…) to optimize the accelerator performance (high beam brightness, low beam losses…). These different uses will be discussed taking examples from the SPIRAL-2 superconducting linear accelerator presently in its commissioning phase.