## 1 Introduction
The control mechanism within the operating point area was based on PI controllers with the Takagi-Sugeno-Kang method of defuzzification. The proposed control strategy was designed based on the real data records and was validated by simulation. Other control algorithms using predictive control to control the DO concentration were used [8; 9; 10]. In 2018, the optimal variable setpoint and a setpoint tracking control system for the DO concentration were designed [11]. A constrained nonlinear neural network predictive controller was applied. Simulations results showed an improvement in effluent quality and reduction in energy use. A DO control system using neural network-based adaptive PID algorithm was proposed [12]. The powerful learning and adaptive ability of the radial basic function neural network were applied for adaptive adjustment of the PID parameters. Simulation results were showed that the novel control algorithm effectively improved the control accuracy of DO concentration as opposed to the classical PID controller. In 2017, the online hybrid intelligent control system based on a genetic algorithm to control of DO was applied [13]. The proposed hybrid approach proved to be a robust and effective DO control tool, attaining adequate effluent quality and minimizing the demand for energy. DO control strategies using NH\({}_{4}\) and NO\({}_{3}\) measurements are designed. For example, two-level hierarchical control structure for DO and NH\({}_{4}\) control was applied [14]. A predictive controller with inlet flow rate feedforward control was proposed for the lower level. Affine function and fuzzy controller were designed for the higher level. The control goal was to improve effluent quality and to reduce operational costs. Other research works are based on the optimization of biological processes taking place in the SBR reactor. For this purpose, in addition to measuring DO, additional measurements are applied: pH, Oxidation Reduction Potential--ORP [15], Oxygen Uptake Rate--OUR [16], aeration time, phase sequence (anaerobic/aerobic), phase duration, number of phases [17; 18; 19]. The approach presented in this paper, unlike any other, combines several advanced control technologies, for example: a hierarchical structure, supervisory controller with the optimizer and a controller with reference model to fully bridle complex dynamics of the control system. Two-step optimization with deterministic and non-deterministic algorithms allows to search for a solution of the optimization problem in a much more efficient way. Finally, the whole system is designed to calculate the operating settings and update them with each refill of the SBR, which makes it very precise and able to respond to any changes in the composition of sewage, noise or disturbances. The paper presents a further development of the research works [20]. An optimization method of a difficult, nonlinear, nonconvex and hybrid (different decision-making variables) task has been proposed. The above features of the optimization task result from the properties of the control system (SBR with the aeration system). The paper considers the problem of optimizing the length and number of phases in SBR and determining the optimal DO reference trajectory. The aim was to minimize the electricity consumption associated with the pumping of air by the aeration system. At the same time, the limitations of the water-law permit for a sewage treatment plant operating in Northern Poland have been taken into account.