Improving SBR Performance Alongside with Cost Reduction through Optimizing Biological Processes and Dissolved Oxygen Concentration Trajectory

Authors of this paper take under investigation the optimization of biological processes during the wastewater treatment in sequencing batch reactor (SBR) plant. A designed optimizing supervisory controller generates the dissolved oxygen (DO) trajectory for the lower level parts of the hierarchical control system. Proper adjustment of this element has an essential impact on the efficiency of the wastewater treatment process as well as on the costs generated by the plant, especially by the aeration system. The main goal of the presented solution is to reduce the plant energy consumption and to maintain the quality of effluent in compliance with the water-law permit. Since the optimization is nonlinear and includes variations of different types of variables, to solve the given problem the authors performed simulation tests and decided to implement a hybrid of two different optimization algorithms: artificial bee colony (ABC) and direct search algorithm (DSA). Simulation tests for the wastewater treatment plant case study are presented.


Introduction
Wastewater treatment plant (WWTP) is a complicated system in which processes of removing contaminants from municipal and/or industrial wastewater take place. Physical, biological and chemical processes are used to remove contaminants before their discharge to the receiver. The activated sludge treatment approach, which uses bacteria and other microorganisms to remove contaminants by assimilating them, has been widely adopted in most WWTPs.
Batch type WWTP, sequencing batch reactor (SBR), is a popular method of municipal wastewater treatment. SBRs are a special form of activated sludge treatment in which all processes take place in the reactor tank. SBR is used for small-scale wastewater treatment and also becomes useful as a decentralized wastewater treatment technology for on-site treatment and/or water reuse technologies related to the sustainable water system. A typical sequence for an SBR system is: filling, biological reactions (aerobic, anaerobic), sedimentation, decantation and idle state [1].
From the control point of view, a WWTP is a very complex, dynamic, nonlinear, multivariable, hybrid control system where interactions between the components are strong. In addition, only limited measurements are available during plant operation. Unfortunately, simple linear control systems are very often used there, which cannot provide good control results at different points of operation.
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.

Control Plant-Wastewater Treatment Plant and Aeration System
The Swarzewo WWTP consists of three parts of wastewater treatment: mechanical, biological and chemical. This paper concerns the second part and one SBR with the capacity of 6400 m 3 /day. Wastewater treatment is based on the activated sludge method. Figure 1 presents a single SBR cycle. It consists of the following phases: filling, biological reactions (aerobic, anaerobic), sedimentation, decantation and idle state. The excess sludge is removed and used as garden soil in the form of compost. The Baltic Sea is the effluent receiver [21].  Maximum acceptable pollutant concentrations of effluent, according to the water-law permit for Swarzewo WWTP, are: chemical oxygen demand (COD) = 125 g O 2 /m 3 , total nitrogen (N tot ) = 15 g N/m 3 , total phosphorus (P tot ) = 2 g P/m 3 .
The biological processes were modelled by applying ASM2d [22]. It is a popular mathematical description of biological processes at WWTPs. The overall model was calibrated according to the plant data records. The model was implemented in a simulation package, SIMBA [23], in order to obtain information data from the controlled plant. The verification of the modelling results was satisfactory they were used for control design [22].
As mentioned above, air is necessary for the monitoring of biological processes. It is supplied to the SBR by means of an aeration system. It consists of blowers, pipes and diffusers (see Figure 2). The aeration system supplies the SBR with oxygen by means of compressed air. From the control point of view, it is a complex, non-linear, dynamic and hybrid system. Maximum acceptable pollutant concentrations of effluent, according to the water-law permit for Swarzewo WWTP, are: chemical oxygen demand (COD) = 125 g O2/m 3 , total nitrogen (Ntot) = 15 g N/m 3 , total phosphorus (Ptot) = 2 g P/m 3 .
The biological processes were modelled by applying ASM2d [22]. It is a popular mathematical description of biological processes at WWTPs. The overall model was calibrated according to the plant data records. The model was implemented in a simulation package, SIMBA [23], in order to obtain information data from the controlled plant. The verification of the modelling results was satisfactory they were used for control design [22].
As mentioned above, air is necessary for the monitoring of biological processes. It is supplied to the SBR by means of an aeration system. It consists of blowers, pipes and diffusers (see Figure 2). The aeration system supplies the SBR with oxygen by means of compressed air. From the control point of view, it is a complex, non-linear, dynamic and hybrid system.  The paper [24] presents the general methodology of process modelling of the aeration system. This model was applied and adapted to the case study aeration system. It was described by several linear and nonlinear algebraic and differential equations [22]. The model of the aeration system was implemented in the Matlab environment and was verified based on real data records from Swarzewo WWTP. Since the verification of modelling results proved satisfactory, they were used for control design.

Hierarchical Control System
The choice of a proper control system structure depends on several factors. In the investigated case the system has two different tasks which have to be managed simultaneously. On one side there is the control of the DO concentration, in sewage which is problematic due to complex internal dynamics with different time scales as well as nonlinearities and changing working conditions. The second task to consider consists of the management of the SBR work cycle, which includes selection of quantity and length of each of the phases during one work cycle.

Structure and Its Main Parts
It was decided to implement a hierarchical control structure which allows to control variable parameters with mixed dynamics as well as the proper management of the SBR work cycle. The general structure of the proposed control system is shown in Figure 3. The paper [24] presents the general methodology of process modelling of the aeration system. This model was applied and adapted to the case study aeration system. It was described by several linear and nonlinear algebraic and differential equations [22]. The model of the aeration system was implemented in the Matlab environment and was verified based on real data records from Swarzewo WWTP. Since the verification of modelling results proved satisfactory, they were used for control design.

Hierarchical Control System
The choice of a proper control system structure depends on several factors. In the investigated case the system has two different tasks which have to be managed simultaneously. On one side there is the control of the DO concentration, in sewage which is problematic due to complex internal dynamics with different time scales as well as nonlinearities and changing working conditions. The second task to consider consists of the management of the SBR work cycle, which includes selection of quantity and length of each of the phases during one work cycle.

Structure and Its Main Parts
It was decided to implement a hierarchical control structure which allows to control variable parameters with mixed dynamics as well as the proper management of the SBR work cycle. The general structure of the proposed control system is shown in Figure 3. Appl. Sci. 2019, 9,  The air flow controller (lower level of the presented control system) is responsible for controlling fast-changing variables (seconds), while the adaptive DO controller manages the slowly changing ones.
Airflow is controlled through the internal model control (IMC) [25], which uses the inverted model of the aeration system to calculate the control signal for blowers. In order to create such signals, three different variables have to be monitored: reference and real airflow, as well as, the volume of wastewater in SBR. In general, two blowers are considered as independent equipment, which means that one is used as the main blower, and the other as an auxiliary. This action helps to control the usage of both blowers and extends the functionality of the presented air flow system [21].
Slower changing variables are managed through the controller with a reference model (direct model references adaptive control-DMRAC) [26]. In general, this solution allows the control system to adapt to the changing work conditions-complicated dynamics: nonlinearity and non-stationary plant and disturbance (respiration) by modifying the control law parameters. The implemented controller was modified because of the high level of complexity of the investigated plant to minimise the impact of constantly changing work conditions. Major changes affect the values of learning rates, anti-windup filter parameters and DMRAC starting points, which can be now adjusted during the optimization process to meet various conditions. In addition, the anti-windup filter reduces the impact of the control signal constraints, such as maximum rotational speed of blowers [27][28][29]. This part of the control system uses the control error eDO and Qair to calculate the Qair ref for the lower-level controller mentioned above.
Finally, the supervisory controller generates the DO reference trajectory to meet the trajectory as much as it is possible in various internal conditions during the work cycle. Details of this part of the control system are described in further sections of this paper.

General Work Cycle of the Implemented System
The general work cycle of the presented system consists of several steps (see Figure 1) which lead to complete treatment of effluent. A block diagram of the described work cycle is shown in Figure 4. The most important factor in the proposed solution is the step-feed strategy. This approach assumes the step-feed of sewage and the periodic aeration of the content of the SBR which allows to efficiently remove the nitrogen compounds without using any external source of carbon. The quantity of the refills during each cycle is determined through the asymmetric filling strategy alongside the changing number of biological (aerobic, anaerobic) phases during each refill. Each cycle is divided into a series of sequences depending on the intensity of wastewater inflow and the level of contamination. The capacity limit determines the specific volume of the last filling, regardless of the intensity of sewage inflow [29]. The air flow controller (lower level of the presented control system) is responsible for controlling fast-changing variables (seconds), while the adaptive DO controller manages the slowly changing ones.
Airflow is controlled through the internal model control (IMC) [25], which uses the inverted model of the aeration system to calculate the control signal for blowers. In order to create such signals, three different variables have to be monitored: reference and real airflow, as well as, the volume of wastewater in SBR. In general, two blowers are considered as independent equipment, which means that one is used as the main blower, and the other as an auxiliary. This action helps to control the usage of both blowers and extends the functionality of the presented air flow system [21].
Slower changing variables are managed through the controller with a reference model (direct model references adaptive control-DMRAC) [26]. In general, this solution allows the control system to adapt to the changing work conditions-complicated dynamics: nonlinearity and non-stationary plant and disturbance (respiration) by modifying the control law parameters. The implemented controller was modified because of the high level of complexity of the investigated plant to minimise the impact of constantly changing work conditions. Major changes affect the values of learning rates, anti-windup filter parameters and DMRAC starting points, which can be now adjusted during the optimization process to meet various conditions. In addition, the anti-windup filter reduces the impact of the control signal constraints, such as maximum rotational speed of blowers [27][28][29]. This part of the control system uses the control error e DO and Q air to calculate the Q air ref for the lower-level controller mentioned above. Finally, the supervisory controller generates the DO reference trajectory to meet the trajectory as much as it is possible in various internal conditions during the work cycle. Details of this part of the control system are described in further sections of this paper.

General Work Cycle of the Implemented System
The general work cycle of the presented system consists of several steps (see Figure 1) which lead to complete treatment of effluent. A block diagram of the described work cycle is shown in Figure 4. The most important factor in the proposed solution is the step-feed strategy. This approach assumes the step-feed of sewage and the periodic aeration of the content of the SBR which allows to efficiently remove the nitrogen compounds without using any external source of carbon. The quantity of the refills during each cycle is determined through the asymmetric filling strategy alongside the changing number of biological (aerobic, anaerobic) phases during each refill. Each cycle is divided into a series of sequences depending on the intensity of wastewater inflow and the level of contamination. The capacity limit determines the specific volume of the last filling, regardless of the intensity of sewage inflow [29]. Appl. Sci. 2019, 9, x FOR PEER REVIEW 6 of 15 Biological reactions phase is the key factor in the whole wastewater treatment process. It has the most significant impact on the quality of treated sewage as well as energy consumption over the cycle. The number and duration of sequences (aerobic plus anaerobic), as well as the order of single reactions (aerobic, anaerobic), are discussed in further sections of this paper.
The management of the sedimentation is dependent on the total suspended solids (TSS), which is monitored in the top and mid layer of the SBR as well as minimal sedimentation time. Setting the correct time of this stage is very important in terms of efficient wastewater treatment process. Too long sedimentation phase may lead to the return of discharge of phosphates and as a result leave the sewage partly untreated. The decantation stage can start after reaching the minimal sedimentation time and when two conditions are fulfilled: TSS in the top layer is below assumed value and it decreases in the middle layer. This stage ends each time the volume of wastewater and active sludge reaches its minimal level or a specific amount of solids is detected in the wastewater.

Optimization Process
The complexity of the presented plant and the number of various choices which have to be taken 'online' during the work cycle impose implementing more advanced control solutions in such systems. This is why the authors of this paper decided to implement a supervisory controller responsible for adjusting the control system settings during its work to increase the efficiency and to minimize the maintenance costs. Most of them (almost 60%) are generated by the aeration system which is the main part of the whole system taken under consideration in the optimization process in this paper. Designing such a controller, all the restrictions concerning the plant and water-law permit for Swarzewo WWTP have to be considered. To solve the optimization problem described in the further part of this paper, the authors decided to use the general approach, which combines deterministic and nondeterministic algorithms. As a result, the mentioned controller delivers proper information regarding Biological reactions phase is the key factor in the whole wastewater treatment process. It has the most significant impact on the quality of treated sewage as well as energy consumption over the cycle. The number and duration of sequences (aerobic plus anaerobic), as well as the order of single reactions (aerobic, anaerobic), are discussed in further sections of this paper.
The management of the sedimentation is dependent on the total suspended solids (TSS), which is monitored in the top and mid layer of the SBR as well as minimal sedimentation time. Setting the correct time of this stage is very important in terms of efficient wastewater treatment process. Too long sedimentation phase may lead to the return of discharge of phosphates and as a result leave the sewage partly untreated. The decantation stage can start after reaching the minimal sedimentation time and when two conditions are fulfilled: TSS in the top layer is below assumed value and it decreases in the middle layer. This stage ends each time the volume of wastewater and active sludge reaches its minimal level or a specific amount of solids is detected in the wastewater.

Optimization Process
The complexity of the presented plant and the number of various choices which have to be taken 'online' during the work cycle impose implementing more advanced control solutions in such systems. This is why the authors of this paper decided to implement a supervisory controller responsible for adjusting the control system settings during its work to increase the efficiency and to minimize the maintenance costs. Most of them (almost 60%) are generated by the aeration system which is the main part of the whole system taken under consideration in the optimization process in this paper. Designing such a controller, all the restrictions concerning the plant and water-law permit for Swarzewo WWTP have to be considered. To solve the optimization problem described in the further part of this paper, the authors decided to use the general approach, which combines deterministic and non-deterministic algorithms. As a result, the mentioned controller delivers proper information regarding the work cycle (quantity and length of aerobic/anaerobic phases) to the lower level parts of the control system for each refill of the SBR. Details of operating principles are described in further sections.

Optimization Details
A two-step optimization application ( Figure 5 explains operating principles) is proposed which determines the aeration trajectory for each refill of the SBR tank and adjusts the settings of the control system to meet the established goal, minimization of operational cost of the WWTP, with SBR. It means that whenever the SBR is being refilled (see Figure 4), the designed optimizer runs and calculates the solution of the problem. Figure 4 shows only the overall operational principles without a detailed explanation of how the optimizer calculates the specific values.
Appl. Sci. 2019, 9, x FOR PEER REVIEW 7 of 15 the work cycle (quantity and length of aerobic/anaerobic phases) to the lower level parts of the control system for each refill of the SBR. Details of operating principles are described in further sections.

Optimization Details
A two-step optimization application ( Figure 5 explains operating principles) is proposed which determines the aeration trajectory for each refill of the SBR tank and adjusts the settings of the control system to meet the established goal, minimization of operational cost of the WWTP, with SBR. It means that whenever the SBR is being refilled (see Figure 4), the designed optimizer runs and calculates the solution of the problem. Figure 4 shows only the overall operational principles without a detailed explanation of how the optimizer calculates the specific values. The principle of the optimizer's operation is based on two algorithms. In the first place, a nondeterministic algorithm ("Artificial Bee Colony Algorithm" block) is initiated after the filling phase. Inputs for this block are decision-making variables with random values in the range of given constraints. This block determines the best values of decision-making variables according to constraints in such a way that the value of the target function is as low as possible. Then calculated values of individual variables are sent to the deterministic algorithm ("Direct Search Algorithm" block), as starting conditions. Both algorithms use a simplified model of the SBR ("Simplified ASM2d model" block), which makes the calculation time shorter, but decreases the precision of the found solution. Next, the results of both of the algorithms are compared ("Better solution?" block), as a solution with the lower value of the objective function is sent to the control system with a more accurate SBR model ("SIMBA Model ASM2d" block) to simulate the work of the plant. Figure 6 shows the course of exemplary trajectory of DOref set by the optimizer described in this section. With each refill of the SBR tank, the designed supervisory controller with optimizer calculates the optimal solution of the objective function. The DOref trajectory is being adapted to the existing biological conditions, thus it may look different after each refill. The principle of the optimizer's operation is based on two algorithms. In the first place, a non-deterministic algorithm ("Artificial Bee Colony Algorithm" block) is initiated after the filling phase. Inputs for this block are decision-making variables with random values in the range of given constraints. This block determines the best values of decision-making variables according to constraints in such a way that the value of the target function is as low as possible. Then calculated values of individual variables are sent to the deterministic algorithm ("Direct Search Algorithm" block), as starting conditions. Both algorithms use a simplified model of the SBR ("Simplified ASM2d model" block), which makes the calculation time shorter, but decreases the precision of the found solution. Next, the results of both of the algorithms are compared ("Better solution?" block), as a solution with the lower value of the objective function is sent to the control system with a more accurate SBR model ("SIMBA Model ASM2d" block) to simulate the work of the plant. Figure 6 shows the course of exemplary trajectory of DO ref set by the optimizer described in this section. With each refill of the SBR tank, the designed supervisory controller with optimizer calculates

Decision-Making Variables
Proper control of an SBR plant is a difficult and demanding task from both economical and performance point of view. The most significant step in the decision-making process is to formulate the optimization problem. Due to the significant complexity of the SBR wastewater treatment plant model together with the aeration system model, it was decided to use the partial nitrification approach. It guarantees relatively easy implementation and the possibility of effective de-pollution. However, this approach necessitates the use of different types of decision-making variables. Finding proper decision-making variables is a very complicated process and demands extensive knowledge about the technology of SBR plants and biological processes inside the plant. The efficiency of wastewater treatment in the active sludge technology is dependent on several key factors: aeration profile, temperature, sludge age and the quality of wastewater and its concentration. Aeration is the factor that has the biggest impact on the economic aspects of wastewater treatment, due to generating the highest cost. The number of decision-making variables has a direct impact on the complexity of the whole optimization process.
The following decision-making variables occur in the optimization task: x1-the order of phases It has to be noted that variables x2 and x3 relate to the pair of anaerobic and aerobic phases. It means that if the given optimizing application computes the solution which consists of two anaerobic phases 0.2-day length each, the amount and length of the aerobic phases will be exactly the same. Considering the given information, the total length of the reaction phase will remain at 0.8 day. x3 = 1 means that the process consists of a single biological phase (aerobic and anaerobic). Another important issue is that x1 is an indirect variable, which means it is not considered in the objective function. However, it has a significant impact on the examined problem and has to be included in the decision-making process.
All the constraints for the decision-making variables were set and adjusted during the simulation tests. Phase order x1 is a binary variable (see (1)). The ones which are connected with the variables x2

Decision-Making Variables
Proper control of an SBR plant is a difficult and demanding task from both economical and performance point of view. The most significant step in the decision-making process is to formulate the optimization problem. Due to the significant complexity of the SBR wastewater treatment plant model together with the aeration system model, it was decided to use the partial nitrification approach. It guarantees relatively easy implementation and the possibility of effective de-pollution. However, this approach necessitates the use of different types of decision-making variables. Finding proper decision-making variables is a very complicated process and demands extensive knowledge about the technology of SBR plants and biological processes inside the plant. The efficiency of wastewater treatment in the active sludge technology is dependent on several key factors: aeration profile, temperature, sludge age and the quality of wastewater and its concentration. Aeration is the factor that has the biggest impact on the economic aspects of wastewater treatment, due to generating the highest cost. The number of decision-making variables has a direct impact on the complexity of the whole optimization process.
The following decision-making variables occur in the optimization task: It has to be noted that variables x 2 and x 3 relate to the pair of anaerobic and aerobic phases. It means that if the given optimizing application computes the solution which consists of two anaerobic phases 0.2-day length each, the amount and length of the aerobic phases will be exactly the same. Considering the given information, the total length of the reaction phase will remain at 0.8 day.
x 3 = 1 means that the process consists of a single biological phase (aerobic and anaerobic). Another important issue is that x 1 is an indirect variable, which means it is not considered in the objective function. However, it has a significant impact on the examined problem and has to be included in the decision-making process.
All the constraints for the decision-making variables were set and adjusted during the simulation tests. Phase order x 1 is a binary variable (see (1)). The ones which are connected with the variables x 2 and x 3 are the result of the real constraints of the aerating system in Swarzewo WWTP. The limitations for DO ref (x 4 ) arise from the basic knowledge about biological processes inside the SBR tank.
Formulation of the Optimization Task The second step, after finding decision-making variables, is to form a proper optimization task. As stated in the previous section, the partial nitrification approach has been used, leading to mixed integer nonlinear problem (MINLP), which cannot be effectively solved with the standard optimization methods. In Section 3.3.1, it is stated that the authors of this paper decided to implement the multi-step optimizing application in which the main problem, aeration trajectory, is computed by two algorithms working together to achieve the certain goal of energy consumed over the cycle as well as quality in the outlet of SBR.
Taking into account the information presented above, the main aspect that affects the quality of the optimization is the aeration profile. This factor is the main contributor to economic losses, and the appropriate aeration phases allow for effective treatment of wastewater. The formulation of the optimization problem (decision-making variables, optimization function, constraints) with this type of solution was proposed earlier [20]. It was decided to use this solution, and then improve and adapt it to the requirements presented in the paper.
The objective function is as follows: min J = min x 3 ·x 2 + 2·mod(x 3 , 1)·x 2 + 0.001·x 3 ·x 4 + f p f or mod(x 3 , 1) < 0.5 ( x 3 + 1)·x 2 + 0.001·x 3 ·x 4 + f p f or mod(x 3 , 1) ≥ 0.5 (5) where x 3 -floored decision-making variable x 3 [-], fp-penalty function [-]. The objective function is divided into two parts depending on the division result of x 3 (mod(x 3 ,1)). The first part is responsible for the case where the fractional part of the calculated length of the sequences is <0.5. For example, if x 3 = 2.2 then the fractional part = 0.2 which means that this small piece has to be taken under consideration in the objective function. This is why the mod(x 3 ,1) is multiplied by two and connected with the x 2 . If the fractional part of the computed solution (length of sequences) is ≥0.5 (for example if x 3 = 2.6 then the fractional part = 0.6) then the additional pair of anaerobic and aerobic phases are added to the objective function (second part of (5)).
Despite the obvious constraints which are the result of the functional principles of the presented system and the biological processes, the requirements for the quality of wastewater effluent should be considered as well. These are included in the external penalty function: f penalty = f penalty COD + f penalty N tot + f penalty P tot (6) f penalty COD = 0 for COD < 120 0.01·(COD − 120) 2 + 0.01 for COD ∈ < 120, 160 > 18 for COD > 160 18 for N tot < 0 0 for N tot ∈ < 0, 12 > 0.08·(N tot − 12) 2 + 0.01 for N tot ∈ (12, 20 > 18 for N tot > 20 18 for P tot < 0 0 for P tot ∈ < 0, 1.5 > 0.02·(P tot − 1) 2 + 0.01 for P tot ∈ (1.5, 5 > 18 for P tot > 5 The optimization task formulated above allowed to obtain promising results of the SBR reactor's work, which is presented in the further part of the paper.

Optimization Methods
The optimization task is nonlinear, nonconvex and hybrid (different forms of decision-making variables; two of them are real-type variables (x 3 , x 4 ), the third one is an integer (x 2 ), the last (x 1 ) is a binary variable. Initially, the previous optimization structure and algorithms were used [20]. During the research work, some other non-deterministic algorithms were found that could work better than the initially used method (evolutionary algorithm).
The artificial bee colony (ABC) algorithm (see Figure 5) can achieve better results than the differential evolution algorithm [30,31]. ABC algorithm is based on a simulation of a swarm of honey bees searching for sources feeds. This is a non-deterministic method and it uses both randomness and heuristic methods to find a global minimum of any function.
The second optimization method is the direct search algorithm (DSA) (see Figure 5). This is a deterministic method which means that it does not have a stochastic factor in it. In order to find an optimal value, DSA needs information about a set of points around the starting one and then it calculates which one has the lowest value of the goal function [32].

Control of Sludge Retention Time
The amount of excess sludge that is wasted during the idle phase has a crucial impact on overall SBR efficiency, as it determines the sludge retention time (SRT), which is the average period of time in which the activated sludge solids have remained in the system. This quantity affects the type of microorganisms in the biomass, the sludge mass and sludge load, respiration rate or sludge settling. In order to maintain the desired SRT, the proper volume of excess sludge has to be pumped out of the SBR. This amount depends on, among others, total suspended solids in the tank and outflow of treated wastewater [29].

Parameters of DO Controller
The use of a step-feed strategy has repercussions in the form of gradual changes in two important quantities-breathing rate and pressure in the aeration system-between successive phases of the biological reaction. The former is the disturbance of the DO control and the latter has a significant effect on the limitations and efficiency of the aeration system. The mechanism of gradual adaptation of DMRAC learning rate, AW filter yields and DMRAC initial parameters allow to improve the efficiency of the controller in the case of a step-by-step feeding strategy. The supervising controller counts the subsequent phases of the biological reaction and applies one of the predefined sets of parameters to DMRAC accordingly. The set is used during the entire biological reaction phase, regardless of the number of sequences [28].

Optimization Results and Discussion
The main goal of implementing the described control system with an optimizer is to improve the efficiency of WWTP and to minimize the incurred costs over one cycle at the same time. This leads to an overall enhancement of the whole system, including higher amount and quality of treated effluent alongside with the cost reduction.
The aeration system of the plant and the control system with an optimizer were designed and implemented in Matlab software with the additional SIMBA package, which allows to simulate the work of wastewater treatment plants. The reference control algorithm, with fixed time limits (like the one in Swarzewo WWTP), was prepared in order to compare the obtained results with the described system. Slight change-replacement of the existing PI controller (DO) for the cascade system-had to be done to provide the common basis for the comparison.
The optimization tests were conducted for two different scenarios with fixed inflow (5000 m 3 /d) and various contamination levels of effluent, which are: COD = 535 g O 2 /m 3 , N tot = 55 g N/m 3 and P tot = 7.38 g P/m 3 for the 1st one and COD = 1070 g O 2 /m 3 , N tot = 110 g N/m 3 and P tot = 14.75 g P/m 3 for the second one. The maximum acceptable pollutant concentrations of effluent, according to the water-law permit for Swarzewo WWTP, are listed in Section 2 of this paper. In the course of the conducted tests, three different types of control systems were compared: new control system with optimizer (symbol OP), reference control system mentioned above (symbol CU) and the heuristic system with supervisory controller [29] (symbol HE).
The amount of energy consumed by a single SBR operating cycle is as follows: (10) where The results obtained for each of the control systems are compared one to another in the further part of this section. Formula (12) is used to calculate the level (percentage) of improvement: where: Z-the value of calculated comparison criteria [%], x-base data/point and y-compared data/point. Table 1 presents the values of important pollution indexes (COD, N tot , P tot ) as well as the efficiency and energy cost indexes which are the main reasons to optimize the work of the SBR plant. Taking into account the contamination rates of the SBR plant production, the best results have a structure with a heuristic control system, and the worst is the reference system from Swarzewo. As shown in Table 1, the original SBR plant control system works well with nitrogen purification but does not work at all in terms of phosphorus use. A control system with a heuristic controller achieving the best result in almost all cases failed to reduce phosphorus in the output wastewater for Scenario II, which shows that a system with an optimizer can be a little more consistent in terms of compliance with the limit values for pollution indicators. The objective function that has been used in the optimizer focuses mainly on reducing energy costs for wastewater treatment. For this reason, the output wastewater pollution indicators are not so important and are maintained only at the limits. A hierarchical control system with an optimizer works slightly worse in terms of numerical values than a system with a heuristic controller, but if one looks at binary results (1-maintained limit values, 0-no), there is only one structure that performs all the tasks.
Another significant aspect in evaluating the operation of a control system with an optimizer is the amount of energy required to treat wastewater during the full cycle of the SBR plant. Table 2 shows three important indicators: efficiency (E f ), energy cost (E c ) and energy to perform a single work cycle (E). As can be seen in Table 2, the main objective of the optimizer application has been met. Energy cost is the lowest for both scenarios, as is the energy needed to perform one full cycle work. The worst results in each of the presented indicators are shown by the control system in Swarzewo. This is due to the fact that a simple timer-based control system has been used in the actual treatment plant. A positive aspect of this solution is the guarantee of always treating the same amount of wastewater at a constant known time. The heuristic controller has the best efficiency ratio and, compared to Swarzewo, significantly reduces the amount of energy required for wastewater treatment. This performance efficiency is guaranteed by assumptions of this structure, which included at least two full work cycles in one day. This assumption did not occur in the process of creating an optimizer for the SBR plant. Therefore, the performance in a structure with an optimizer is the most varied. Other factors, such as energy and energy costs in one work cycle, are minimized even more than with the heuristic method. The optimization of these two parameters was the main objective of the proposed optimizer and the implementation of this assumption looks very optimistic.
DO are illustrated in Figures 7 and 8. These apply to Scenario II, which usually occurs in Swarzewo WWTP. Figure 7 shows three complete cycles of SBR installations. As it can be seen, the DO values and the number of aerobic phases for each additional portion of wastewater vary significantly. This is because the optimizer initially randomly searches for the best solution, so one can find many combinations of DO, number of sequences and phase lengths that can be optimal for each case. This diversity of optimal solutions is also the result of changes in the biological environment inside the reactor. Figure 8 shows the magnification of the DO and it is, therefore, easier to compare DO with DO ref . The SBR is a very complex plant and does not allow real DO capacity to deal with the DO ref perfectly. Therefore, some overshootings and other imperfections of the DO are acceptable. However, the serious problem of the optimizer is that sometimes it can find solutions that are almost impossible to apply in the simulation and can cause problems in keeping contaminant parameters within their limits. This can be particularly the case if the input wastewater is heavily polluted.

Conclusions
In a time of growing awareness of the negative impact of pollution on the environment, SBR plants have become more and more popular in the business over the last years. The main advantage of this type of system is its flexibility, which allows to adjust the work parameters to the various conditions. On the other hand, such a plant is very complex and requires great knowledge of the biochemical aspects as well as the advanced control system to conduct the treatment process in the most efficient way. The lack of both advanced solutions and a basic control system in Swarzewo WWTP, as well as the growing need of environmental protection, were the main reasons why the authors decided to design and test the described control system with an optimizer.
The conducted simulation tests of the designed system show that it works in a much more efficient way than the reference one implemented in Swarzewo WWTP. The cost results are also better than the one obtained in paper [29]. One difference, in the outcomes obtained with the designed system and the

Conclusions
In a time of growing awareness of the negative impact of pollution on the environment, SBR plants have become more and more popular in the business over the last years. The main advantage of this type of system is its flexibility, which allows to adjust the work parameters to the various conditions. On the other hand, such a plant is very complex and requires great knowledge of the biochemical aspects as well as the advanced control system to conduct the treatment process in the most efficient way. The lack of both advanced solutions and a basic control system in Swarzewo WWTP, as well as the growing need of environmental protection, were the main reasons why the authors decided to design and test the described control system with an optimizer.
The conducted simulation tests of the designed system show that it works in a much more efficient way than the reference one implemented in Swarzewo WWTP. The cost results are also better than the one obtained in paper [29]. One difference, in the outcomes obtained with the designed system and the

Conclusions
In a time of growing awareness of the negative impact of pollution on the environment, SBR plants have become more and more popular in the business over the last years. The main advantage of this type of system is its flexibility, which allows to adjust the work parameters to the various conditions. On the other hand, such a plant is very complex and requires great knowledge of the biochemical aspects as well as the advanced control system to conduct the treatment process in the most efficient way. The lack of both advanced solutions and a basic control system in Swarzewo WWTP, as well as the growing need of environmental protection, were the main reasons why the authors decided to design and test the described control system with an optimizer.
The conducted simulation tests of the designed system show that it works in a much more efficient way than the reference one implemented in Swarzewo WWTP. The cost results are also better than the one obtained in paper [29]. One difference, in the outcomes obtained with the designed system and