This report summarizes the work carried out during the internship on the development of Model Predictive Control (MPC) methods for district heating systems under uncertainty. The study progresses from linear time-invariant models to bilinear and stochastic formulations, including chance constraints, state-input analysis, and Kalman filtering. These components are then combined in a stochastic bilinear MPC framework and applied to a single-pipe district heating system. Both open-loop and closed-loop implementations are evaluated using Monte Carlo simulations. The final framework considers uncertainty, state estimation, probabilistic constraints, and nonlinear optimization within a unified control approach.
Acknowledgements
I would like to express my sincere gratitude to Assoc. Prof. Tobias K. S. Ritschel for his guidance, support, and encouragement throughout my research at the Technical University of Denmark. His valuable insights, constructive feedback, and thoughtful discussions have greatly contributed to my understanding of model predictive control and helped me develop as a researcher. I am especially thankful for the opportunity to work under his supervision and for the trust and independence he has given me throughout this work.
1Introduction
District heating systems require effective control strategies to maintain desired temperature levels while dealing with nonlinear dynamics, disturbances, and uncertainty. Model Predictive Control provides a suitable framework for this purpose by predicting future system behavior and optimizing control actions over a finite horizon. The aim of this report was to progressively develop an MPC framework, starting from deterministic linear models and extending it to bilinear and stochastic systems with chance constraints. State estimation using Kalman filtering was also investigated. Finally, the developed methods were applied to a district heating pipe model to study their behavior in a more realistic control problem.
2Linear Time-Invariant Model
2.1LTI System
A discrete-time Linear Time-Invariant (LTI) system can be represented in state-space form as
xk+1yk=Axk+Buk,=Cxk,(2.1)(2.2)
where xk∈Rn denotes the state vector, uk∈Rm denotes the input vector, and yk∈Rr denotes the output vector at time step k. The matrices A, B, and C are the state, input, and output matrices, respectively.
For model predictive control, the future behavior of the system is predicted from the current state x0 and a sequence of future control inputs
u0,u1,…,uN−1,(2.3)
where N denotes the prediction horizon.
2.1.1State and Output Prediction
Starting from the initial state x0, the state after one time step is obtained from Equation (2.1) as
Following the same recursion, the state at an arbitrary prediction step k can be written as
xk=Akx0+i=0∑k−1Ak−1−iBui(2.10)
Equation Equation (2.10) separates the future state into two contributions. The first term represents the evolution of the initial state in the absence of future inputs, whereas the summation represents the contribution of the input sequence.
Using the output relation in Equation (2.2), the corresponding output at prediction step k is
Thus, each predicted output is expressed as a function of the current state and all control inputs applied before that prediction step.
2.1.2Stacked Prediction Formulation
For optimization over a prediction horizon N, the predicted outputs and future inputs can be collected into stacked vectors. The output vector is defined as
Y=y1y2⋮yN∈RNr,(2.14)
and the corresponding input vector is
U=u0u1⋮uN−1∈RNm(2.15)
The first two predicted outputs can be written explicitly as
the stacked prediction equation can be written compactly as
Y=Φx0+ΓU(2.22)
The term
Yfree=Φx0(2.23)
describes the free response of the system, i.e. the predicted output evolution due only to the current state. The term
Yforced=ΓU(2.24)
describes the forced response resulting from the future input sequence. Consequently,
Y=Yfree+Yforced=Φx0+ΓU(2.25)
2.2Optimal Control Problem
After deriving the stacked prediction model, the next step is to determine the sequence of control inputs that minimizes a desired performance criterion over the prediction horizon.
For a prediction horizon of length N, the quadratic cost function is defined as
where yˉk denotes the desired reference output, while Qk⪰0 and Rk≻0 are weighting matrices penalizing the output tracking error and the control effort, respectively.
Using the stacked output and input vectors, the cost function can be written as
ϕ=(Y−Yˉ)TQ(Y−Yˉ)+UTRU(2.27)
From the stacked prediction equation
Y=Φx0+ΓU,(2.28)
the cost function becomes
ϕ=(Φx0+ΓU−Yˉ)TQ(Φx0+ΓU−Yˉ)+UTRU(2.29)
Defining
e=Φx0−Yˉ,(2.30)
the cost function can be written as
ϕ=(e+ΓU)TQ(e+ΓU)+UTRU(2.31)
Expanding the quadratic term gives
ϕ=eTQe+eTQΓU+UTΓTQe+UTΓTQΓU+UTRU(2.32)
Since the cross terms are scalar and Q=QT,
eTQΓU=UTΓTQe(2.33)
Therefore,
ϕ=eTQe+2UTΓTQe+UT(ΓTQΓ+R)U(2.34)
To obtain the optimal control sequence, the cost function is differentiated with respect to U:
∂U∂ϕ=2ΓTQe+2(ΓTQΓ+R)U(2.35)
At the optimum,
∂U∂ϕ=0(2.36)
Hence,
ΓTQ(Φx0−Yˉ)+(ΓTQΓ+R)U=0(2.37)
Solving for U gives the optimal control sequence
U∗=−(ΓTQΓ+R)−1ΓTQ(Φx0−Yˉ)(2.38)
Equivalently,
U∗=(ΓTQΓ+R)−1ΓTQ(Yˉ−Φx0)(2.39)
2.3Open-Loop Implementation
After deriving the optimal control sequence for the LTI system, the controller was first implemented in an open-loop setting. In this approach, the complete optimal input sequence is computed once using the initial state and the desired reference trajectory. The resulting inputs are then applied sequentially to the system without recalculating the optimization problem using updated state information.
The implementation procedure can be summarized in the following steps.
2.3.1Implementation Procedure
First, the prediction horizon N, the reference trajectory Yˉ, the weighting matrices Q and R, and the initial state x0 are specified. The weighting matrices satisfy
Q⪰0,R≻0(2.40)
The stacked prediction matrices Φ and Γ are then constructed according to
Y=Φx0+ΓU,(2.41)
where
Φ=CACA2⋮CAN,(2.42)
and
Γ=CBCAB⋮CAN−1B0CB⋮CAN−2B⋯⋯⋱⋯00⋮CB(2.43)
Using these matrices, the quadratic cost function is written as
ϕ(U)=(Φx0+ΓU−Yˉ)TQ(Φx0+ΓU−Yˉ)+UTRU(2.44)
As derived in the previous section, minimizing this cost function with respect to U gives the optimal input sequence
U∗=−(ΓTQΓ+R)−1ΓTQ(Φx0−Yˉ)(2.45)
In the open-loop implementation, Equation (2.45) is evaluated only once. The resulting control sequence
U∗=[u0∗u1∗⋯uN−1∗]T(2.46)
is subsequently applied to the system according to
xk+1yk=Axk+Buk∗,=Cxk(2.47)(2.48)
Therefore, no new optimization problem is solved after the simulation begins. This distinguishes the open-loop implementation from a receding-horizon or Model Predictive Control implementation, in which the optimization problem is repeatedly solved using updated state information.
The complete procedure can therefore be summarized as
Select N, Yˉ, Q, R, and x0.
Construct the prediction matrices Φ and Γ.
Construct the quadratic cost function ϕ(U).
Calculate the optimal input sequence U∗.
Apply the components of U∗ sequentially to the system.
Compare the resulting output trajectory with the reference trajectory.
To quantify the tracking performance, the tracking error is defined as
E=Y−Yref(2.49)
The Root Mean Square Error (RMSE) can additionally be used as a scalar measure of the tracking accuracy. For a system with r outputs, it is given by
RMSE=Nr1k=1∑Nj=1∑r(Yk,j−Yref,k,j)2(2.50)
2.3.2Results
The open-loop controller was evaluated using the following discrete-time LTI system:
A=[1011],B=[01],C=[10](2.51)
The desired output reference was changed every ten simulation steps. Three reference levels were considered:
yˉ=[1.03.05.0](2.52)
To investigate the effect of the input penalty on the controller behavior, three different values of R were tested while keeping the remaining controller parameters unchanged:
R=0.1,R=0.5,R=5(2.53)
Case 1: R=0.1
Figure 2.1: Open-loop tracking performance for R=0.1, Left-side is when N=5 with the averaged RMSE 0.450392, right-side is the case when N=40 with the averaged RMSE 0.172099
Case 2: R=0.5
Figure 2.2: Open-loop tracking performance for R=0.5, Left-side is when N=5 with the averaged RMSE 0.469931, right-side is the case when N=40 with the averaged RMSE 0.220377
Case 3: R=5.0
Figure 2.3: Open-loop tracking performance for R=5.0, Left-side is when N=5 with the averaged RMSE 0.571764, right-side is the case when N=40 with the averaged RMSE 0.344596
Comparison
The results demonstrate the trade-off between reference tracking performance and control effort introduced by the weighting matrix R. As the value of R increases, the contribution of the term UTRU to the objective function becomes more significant. Consequently, the optimizer increasingly penalizes large control inputs and attempts to reduce the magnitude of U.
For a small value such as R=0.1, the controller is willing to use relatively large control actions in order to achieve accurate reference tracking. As R is increased to 0.5 and subsequently to 5, the control actions become less aggressive. The system therefore has increasing difficulty following changes in the reference trajectory, resulting in larger tracking errors.
Hence, increasing R improves the economy of the control action at the expense of tracking performance. The selection of R therefore represents a compromise between minimizing the control effort and maintaining accurate reference tracking.
2.4Closed-Loop Implementation
The open-loop implementation computes the optimal control sequence only once from the initial state and applies the complete sequence without further optimization. In contrast, the closed-loop implementation repeatedly solves the optimal control problem using the most recent state information.
This approach follows the receding-horizon principle. At each time step, a new optimal input sequence is calculated, but only its first control action is applied to the system. At the following time step, the state is updated and the optimization problem is solved again.
2.4.1Implementation Procedure
The prediction horizon N, control horizon Nc, total simulation length Nend, reference trajectory, weighting matrices Q and R, and initial state x0 are first specified.
The prediction and control horizons satisfy
Nc≤N(2.54)
The stacked prediction model derived previously is
Y=Φxk+ΓUfull,(2.55)
where
Φ=CACA2⋮CAN(2.56)
and
Γ=CBCAB⋮CAN−1B0CB⋮CAN−2B⋯⋯⋱⋯00⋮CB(2.57)
When a control horizon Nc shorter than the prediction horizon is used, the independent control variables are collected in
Uc=u0u1⋮uNc−1(2.58)
The complete input sequence over the prediction horizon is then generated as
Ufull=TUc,(2.59)
where T is a control-horizon mapping matrix. This matrix maps the Nc independent control variables to the full prediction horizon.
Substituting Equation (2.59) into the prediction model gives
Y=Φxk+ΓTUc(2.60)
At each time step k, the reference trajectory corresponding to the current prediction window is denoted by Yˉk. The quadratic cost function is therefore written as
The optimization problem is solved again at every sampling instant. Following the same derivation as in the previous section, the optimal control sequence becomes
Uc∗=−[(ΓT)TQ(ΓT)+R]−1(ΓT)TQ(Φxk−Yˉk)(2.62)
Unlike the open-loop implementation, the complete optimal sequence is not applied to the system. Instead, only the first control input is selected.
A selection matrix Π can be defined such that
uk=ΠUc∗(2.63)
For a scalar-input system,
Π=[10⋯0](2.64)
The selected input is then applied to the system:
xk+1yk=Axk+Buk,=Cxk(2.65)(2.66)
After obtaining the new state xk+1, the prediction window is shifted forward by one time step. The reference trajectory is updated accordingly, and the optimization problem is solved again.
This procedure is repeated until
k=Nend−1(2.67)
Therefore, the closed-loop algorithm can be summarized as follows:
Select N, Nc, Nend, Q, R, the reference trajectory, and x0.
Construct the prediction matrices Φ and Γ, together with the control-horizon mapping matrix T.
At time step k, construct the reference vector Yˉk over the current prediction horizon.
Compute the optimal control sequence Uc∗.
Apply only the first control action,
uk=ΠUc∗
Update the system state and output.
Shift the prediction horizon and repeat the optimization for k+1.
2.4.2Results
The closed-loop controller was evaluated using the same LTI system considered in the open-loop implementation:
A=[1011],B=[01],C=[10](2.68)
The reference output was chosen as
yˉ=[1.03.05.0],(2.69)
where the reference value changes every 10 simulation steps.
For this experiment, the control-input weighting was selected as
R=0.1(2.70)
Also, in our example, the prediction horizon is chosen to be the same as the control horizon. So,
T=I,Ufull=Uc(2.71)
Figure 2.4: Closed-loop tracking performance for R=5.0, Left-side is when N=2 with the averaged RMSE 0.238485, right-side is the case when N=5 with the averaged RMSE 0.242733
3Bilinear Model
3.1Bilinear System
In the bilinear formulation considered in this work, the system matrices depend on a time-varying variable vk. The discrete-time state-space model is written as
xk+1yk=A(vk)xk+B(vk)uk=Cxk(3.1)(3.2)
For compactness, the time-varying system matrices are denoted by
Ak=A(vk),Bk=B(vk)(3.3)
The state equation can therefore be written as
xk+1=Akxk+Bkuk(3.4)
Unlike the LTI case, where A and B remain constant over the prediction horizon, the matrices Ak and Bk may change at every prediction step according to the corresponding value of vk.
3.1.1State and Output Prediction
Starting from the initial state x0, the first predicted state is
For the bilinear system, both the control sequence U and the scheduling-variable sequence V are treated as optimization variables. The decision vector is therefore defined as
z=[UV](3.24)
Using the bilinear stacked prediction model,
Ypred=Φ(V)x0+Γ(V)U(3.25)
the tracking error is defined as
e=Ypred−Yˉ(3.26)
The quadratic objective function is then written as
ϕ(z)=eTQe+UTRUU+VTRVV,(3.27)
where Q⪰0 penalizes the output tracking error, while RU≻0 and RV≻0 penalize the magnitudes of the control and scheduling-variable sequences, respectively.
Substituting the prediction model into the cost function gives
The optimal control and scheduling sequences are therefore obtained from
(U∗,V∗)=argU,Vminϕ(U,V)(3.29)
In the LTI case, the prediction matrices Φ and Γ are constant. As a result, the cost function is quadratic in U, and the optimal solution can be obtained analytically by setting the gradient equal to zero.
For the bilinear system, however, both Φ(V) and Γ(V) depend on the optimization variable V. Consequently, the predicted output depends nonlinearly on the joint decision vector z=[UTVT]T. The resulting optimization problem is therefore generally nonlinear and does not admit the same closed-form solution used for the LTI system.
3.2.1Numerical Solution Using SLSQP
The nonlinear optimization problem in Equation (3.29) is solved numerically using Sequential Least Squares Programming (SLSQP).
SLSQP is a gradient-based constrained optimization method that solves a sequence of local quadratic approximations of the original nonlinear problem. At each iteration, the algorithm updates the decision variables while attempting to reduce the objective function and satisfy the imposed constraints.
The optimization variable is
z=[UV](3.30)
with an initial guess
z(0)=[U(0)V(0)](3.31)
At each SLSQP iteration, the current sequence V is used to construct the time-varying matrices
Ak=A(vk),Bk=B(vk)(3.32)
and consequently the prediction matrices
Φ(V),Γ(V)(3.33)
The predicted output is then evaluated as
Ypred=Φ(V)x0+Γ(V)U(3.34)
and the objective function ϕ(U,V) is computed.
The optimizer repeatedly updates U and V until a convergence criterion is satisfied, resulting in the numerical solution
z∗=[U∗V∗](3.35)
3.3Open-Loop Implementation
The open-loop implementation of the bilinear controller follows the same general structure as the open-loop implementation introduced for the LTI system. However, the optimal control problem is solved numerically for both U and V, rather than analytically for U alone.
The implementation procedure can therefore be summarized as follows:
Select the prediction horizon N, reference trajectory Yˉ, weighting matrices Q, RU, RV, and the initial state x0.
Define the bounds and initial guesses for the optimization variables U and V.
For a candidate sequence V, construct the time-varying matrices
Ak=A(vk),Bk=B(vk)
Construct the prediction matrices Φ(V) and Γ(V).
Construct the nonlinear objective function ϕ(U,V).
Solve the optimization problem numerically using SLSQP to obtain U∗ and V∗.
Apply the components of U∗ and V∗ sequentially to the bilinear system.
Compare the resulting output trajectory with the reference trajectory.
At each simulation step, the optimized values are applied according to
Since the controller operates in open loop, the optimization is not updated after the simulation begins. Therefore, the sequences U∗ and V∗ are determined entirely from the initial state and the prescribed reference trajectory.
3.3.1Results
The bilinear open-loop controller was evaluated using the system
xk+1=A(vk)xk+B(vk)uk,yk=Cxk(3.38)
with
A(v)=[0.90.0v0.5](3.39)
B(v)=[01],C=[1.00.0](3.40)
The initial state was selected as
x0=[1.00.0](3.41)
The optimization bounds were chosen as
−5.0−10.0≤uk≤5.0≤vk≤10.0(3.42)(3.43)
The control penalties were selected as
RU=0.1,RV=0.1(3.44)
Figure 3.1: Open-loop output tracking performance of the bilinear system, left-side is the case when N=5, and right-side is the case when N=10
3.4Closed-Loop Implementation
The closed-loop implementation of the bilinear controller follows the same receding-horizon principle introduced for the LTI system. However, in the bilinear case, both the control sequence U and the scheduling-variable sequence V are optimized at every sampling instant.
At time step k, the current state xk is used together with the reference trajectory over the prediction horizon. The nonlinear optimization problem is then solved numerically using SLSQP. Only the first elements of the optimal sequences are applied to the system. At the next time step, the state is updated and the complete optimization problem is solved again.
Only the first control values are applied to the system. Using the selection matrix Π,
ukvk=ΠUc∗=ΠVc∗(3.45)(3.46)
After the state is updated, the prediction horizon is shifted forward by one step and the optimization problem is solved again using the new state xk+1.
The closed-loop bilinear control procedure can therefore be summarized as follows:
Select N, Nc, Nend, Q, RU, RV, the reference trajectory, and x0.
Define the bounds and initial guesses for the optimization variables Uc and Vc, and construct the control-horizon mapping matrix T.
At time step k, construct the reference vector Yˉk over the current prediction horizon.
For the current candidate sequence Vc, construct Vfull=TVc and the corresponding time-varying system matrices Ai=A(vi),Bi=B(vi).
Construct the prediction matrices Φ(Vfull)andΓ(Vfull).
Solve the nonlinear optimization problem using SLSQP to obtain Uc∗andVc∗.
Apply only the first elements of the optimal sequences: uk=ΠUc∗,vk=ΠVc∗.
Update the system state and output: xk+1=A(vk)xk+B(vk)uk,yk=Cxk.
Shift the prediction horizon and repeat the optimization for k+1 until k=Nend−1.
3.4.1Results
The closed-loop bilinear controller was evaluated using the same system and parameter settings as in the open-loop implementation.
However, the sequences U∗ and V∗ are not computed only once. Instead, a new nonlinear optimization problem is solved at every sampling instant using the current state of the system.
Figure 3.2: Closed-loop output tracking performance of the bilinear system, left-side is the case when N=2, and right-side is the case when N=10
4Stochastic Model
4.1Stochastic System
A stochastic discrete-time linear system can be written as
xk+1yk=Axk+Buk+wk=Cxk+vk(4.1)(4.2)
where wk represents the process noise and vk represents the measurement noise. The noise terms are assumed to be zero-mean Gaussian random variables,
wkvk∼N(0,Rw)∼N(0,Rv)(4.3)(4.4)
and the initial state is assumed to be Gaussian distributed as
x0∼N(μ0,P0)(4.5)
Under these assumptions, the state distribution at time step k is characterized by its mean and covariance:
xk∼N(μk,Pk)(4.6)
4.1.1State Mean
The mean of the state is defined as
μk=E[xk](4.7)
Taking the expectation of the state equation gives
μk+1=E[xk+1]=E[Axk+Buk+wk](4.8)(4.9)
Using the linearity of expectation,
μk+1=AE[xk]+BE[uk]+E[wk](4.10)
Assuming that the control input uk is deterministic and using
E[wk]=0(4.11)
the state mean evolves according to
μk+1=Aμk+Buk(4.12)
Therefore, the control input shifts the mean of the state distribution.
In stochastic systems, the output cannot in general be guaranteed to remain inside deterministic bounds at every time step because of the presence of uncertainty. Instead, the constraints can be imposed probabilistically using chance constraints.
For each prediction step k, the output is required to satisfy
P(ymin≤yk≤ymax)≥1−α,k=1,…,N(4.44)
where α denotes the allowed probability of constraint violation.
The total violation probability is divided between the upper and lower bounds according to
αupper+αlower=α(4.45)
The two-sided chance constraint can therefore be handled through separate upper and lower probabilistic constraints.
Upper Chance Constraint
The upper output constraint is
P(yk≤ymax)≥1−αupper(4.46)
Since
yk∼N(μy,k,σy,k2)(4.47)
the output can be standardized as
Z=σy,kyk−μy,k,Z∼N(0,1)(4.48)
Therefore,
P(yk≤ymax)=P(Z≤σy,kymax−μy,k)(4.49)
Using the cumulative distribution function Φ(⋅) of the standard normal distribution,
Φ(σy,kymax−μy,k)≥1−αupper(4.50)
Applying the inverse standard normal cumulative distribution function yields
σy,kymax−μy,k≥Φ−1(1−αupper)(4.51)
Rearranging gives
μy,k≤ymax−Φ−1(1−αupper)σy,k(4.52)
Lower Chance Constraint
Similarly, the lower output constraint is
P(yk≥ymin)≥1−αlower(4.53)
Following the same standardization procedure gives
μy,k≥ymin+Φ−1(1−αlower)σy,k(4.54)
Reformulation
From the stochastic output model,
μy,k=Cμk(4.55)
and
Py,k=CPkCT+Rv(4.56)
For a scalar output, the standard deviation is therefore
σy,k=CPkCT+Rv(4.57)
Substituting these expressions into the deterministic chance constraints gives
Cμk≤ymax−Φ−1(1−αupper)CPkCT+Rv(4.58)
and
Cμk≥ymin+Φ−1(1−αlower)CPkCT+Rv(4.59)
The resulting deterministic limits are referred to as the tight bounds. They are defined as
y~min,k=ymin+Φ−1(1−αlower)σy,k(4.60)
and
y~max,k=ymax−Φ−1(1−αupper)σy,k(4.61)
Hence, the original probabilistic constraint can be enforced through the deterministic condition
y~min,k≤Cμk≤y~max,k(4.62)
The tight bounds shrink the original feasible output interval in order to account for stochastic uncertainty. The amount of tightening depends on the output standard deviation σy,k and on the selected violation probabilities.
A larger uncertainty results in a larger distance between the original bounds and the tight bounds. Similarly, selecting a smaller violation probability increases that difference.
4.3Stacked Forms Derivation
For optimization over a finite prediction horizon, the state means, output means, and control inputs are collected into stacked vectors. This allows the stochastic control problem to be expressed in a compact matrix form.
4.3.1Stacked Prediction Matrices
The mean-state dynamics are given by
μk+1=Aμk+Buk(4.63)
Starting from the initial mean μ0, the first predicted mean is
The open-loop implementation follows the same general structure as the deterministic LTI open-loop case. The optimal input sequence is computed once at the beginning of the simulation and is not updated afterwards.
For the stochastic system, however, the resulting controller performance is evaluated using Monte Carlo simulation. A single optimal control sequence U∗ is first obtained from the stochastic optimization problem. The same sequence is then applied to a large number of independently generated monte carlo trajectories.
A single optimal open-loop input sequence U∗ was obtained by solving the stacked stochastic optimization problem. This same sequence was then applied to all Monte Carlo trajectories.
Figure 4.1: Monte Carlo output trajectories for the stochastic open-loop implementation together with the reference trajectory, original output constraints, and tight bounds
4.5Closed-Loop Implementation
The closed-loop stochastic implementation follows the same receding-horizon structure used in the LTI closed-loop Case. The main difference is that the controller is evaluated using Monte Carlo simulation, and each stochastic realization solves its own optimization problem using its own current state.
For each Monte Carlo trajectory j, the initial state is sampled independently as
x0(j)∼N(μ0,P0)(4.129)
Since the realizations start from different initial conditions and are affected by independent process and measurement noise, the state of each trajectory evolves differently.
At every time step k, each trajectory therefore constructs and solves its own model predictive control problem.
The stochastic closed-loop implementation can therefore be summarized as follows:
Select N, Nc, Nend, Q, R, Rw, Rv, the reference trajectory, and the chance-constraint parameters.
Generate nMC independent initial states
x0(j)∼N(μ0,P0)
For each Monte Carlo trajectory j, use its current state xk(j) as the initial condition of the MPC prediction.
Construct the reference vector Yˉk over the current prediction horizon.
Construct the corresponding tight bounds
Y~min,k,Y~max,k
Solve a separate constrained MPC problem for each Monte Carlo realization to obtain
Uk∗,(j)
Apply only the first control action
uk(j)=uk∣k∗,(j)
Sample the process and measurement noise and update each stochastic trajectory independently.
Shift the prediction horizon and repeat the optimization for every realization at the next time step.
Continue until k=Nend−1.
4.5.1Results
The closed-loop stochastic controller was evaluated using the same system, noise levels, output constraints, reference trajectory, and weighting matrices used in the open-loop experiment.
Figure 4.2: Monte Carlo output trajectories for the stochastic closed-loop implementation together with the reference trajectory, original output constraints, and tight bounds
5Stochastic Bilinear Model with Chance Constraints
5.1Stochastic Bilinear System
A stochastic bilinear system is considered in the form
The decision vector can equivalently be written as
z=[UV](5.64)
5.5Open-Loop Implementation
The stochastic bilinear open-loop implementation is evaluated using Monte Carlo simulation. A single pair of optimal sequences U∗ and V∗ is first obtained by solving the nonlinear optimization problem using SLSQP.
The optimization is performed only once:
(U∗,V∗)=argU,Vminϕ(U,V)(5.65)
subject to the chance constraints and the bounds on U and V.
After the optimal sequences have been obtained, the same U∗ and V∗ are applied to every Monte Carlo realization.
For realization j,
x0(j)∼N(μ0,P0)(5.66)
and independent stochastic disturbances are sampled as
wk(j)ηk(j)∼N(0,Rw)∼N(0,Rη)(5.67)(5.68)
All trajectories use
uk(j)=uk∗,vk(j)=vk∗(5.69)
The stochastic dynamics are then simulated according to
xk+1(j)=A(vk∗)xk(j)+B(vk∗)uk∗+wk(j)(5.70)
and
yk(j)=Cxk(j)+ηk(j)(5.71)
Thus, the optimizer determines one common open-loop pair (U∗,V∗), while the Monte Carlo trajectories differ because of their independently sampled initial conditions and stochastic disturbances.
Define N, μ0, P0, Q, RU, RV, Rw, Rη, the reference trajectory, chance-constraint parameters, and bounds on U and V.
Initialize candidate sequences U and V.
For each candidate V, construct Ak, Bk, Φ(V), Γ(V), and propagate Pk(V).
Construct the V-dependent tight bounds.
Evaluate the cost function ϕ(U,V).
Solve the constrained nonlinear problem using SLSQP to obtain U∗ and V∗.
Generate the Monte Carlo realizations.
Apply the same U∗ and V∗ to every realization.
Evaluate the output trajectories and empirical constraint satisfaction.
5.5.1Results
The stochastic bilinear open-loop controller was evaluated over a horizon
N=30.(5.72)
The bilinear state-transition matrix was defined as
A(v)=Abase+vAv(5.73)
where
Abase=[0.90000.50],Av=[0010](5.74)
Hence,
A(v)=[0.900v0.50](5.75)
The input matrix was
B(v)=[01](5.76)
and both states were directly observed,
C=I2(5.77)
The weighting matrices were
Q=I2,RU=0.1,RV=0.1(5.78)
The process and measurement noise covariance matrices were
Figure 5.1: Monte Carlo output trajectories for the stochastic bilinear open-loop implementation together with the reference trajectory, original constraints, and tight bounds
5.6Closed-Loop Implementation
The stochastic bilinear closed-loop controller is implemented using a receding-horizon Monte Carlo structure similar to the stochastic closed-loop model. But this time for finding optimal U* V* SLSQP solver used.
Generate independent initial conditions for all Monte Carlo realizations.
At time k, use the current state of each realization as the initial condition for its prediction problem.
Construct the current reference trajectory over the prediction horizon.
For each candidate V, propagate the bilinear covariance and construct the corresponding tight bounds.
Solve the nonlinear constrained optimization problem using SLSQP independently for each realization.
Obtain Uk∗,(j) and Vk∗,(j).
Apply only the first pair
uk(j)=uk∣k∗,(j),vk(j)=vk∣k∗,(j)
Sample the stochastic disturbances and update the system.
Shift the horizon and repeat the optimization at k+1.
5.6.1Results
The closed-loop experiment used the same stochastic bilinear system with the open-loop case.
Figure 5.2: Monte Carlo output trajectories for the stochastic bilinear closed-loop implementation
6State Input Analysis
6.1Analysing Objective
The purpose of the state-input analysis is to investigate how the optimal decision variables change as a function of the system state.
For a two-state system, the initial state is written as
x0=[x1x2](6.1)
A rectangular grid is constructed over the (x1,x2) state plane. At each grid point, the corresponding optimization problem is solved using that state as the initial condition.
For the linear case, the analysis records the first optimal control input,
u0∗=f(x1,x2)(6.2)
For the bilinear case, both the first optimal control input and the first optimal bilinear parameter are recorded,
u0∗v0∗=f(x1,x2)=g(x1,x2)(6.3)(6.4)
Only the first optimized values are considered because they represent the immediate control decision associated with a particular state.
The state space is sampled over predefined intervals,
x1∈[x1,min,x1,max],x2∈[x2,min,x2,max](6.5)
and the optimization problem is solved independently for every point in this grid.
The resulting values form surfaces over the state plane:
(x1,x2)⟶u0∗(6.6)
and, for the bilinear system,
(x1,x2)⟶v0∗(6.7)
These mappings provide a direct visualization of how the optimal decision changes depending on the location of the system in the state space.
The surfaces are represented using both three-dimensional surface plots and two-dimensional contour plots. The main objective of this analysis is therefore not to study a particular trajectory, but to characterize the state-dependent structure of the optimization problem. In particular, the plots make it possible to identify regions in the state space where the optimal input changes gradually, changes rapidly, approaches its bounds, or exhibits nonlinear behavior.
For the bilinear system, separate plots are produced for u0∗ and v0∗. This allows the influence of the state on the two optimization variables to be examined independently.
6.2Results
The state-input relation was evaluated using the stochastic bilinear system
A(v)=Abase+vAv(6.8)
with
Abase=[0.90000.50](6.9)
and
Av=[0010](6.10)
Therefore,
A(v)=[0.900v0.50](6.11)
The input and output matrices were
B=[01],C=[10](6.12)
The prediction horizon was selected as
N=15(6.13)
with weighting matrices
Q=1,RU=0.1,RV=0.1(6.14)
The state-input relation was evaluated over
−10≤x1≤10,−10≤x2≤10(6.15)
using a 50×50 grid.
6.2.1Optimal Control Input Relation
For every point in the (x1,x2) grid, the nonlinear optimization problem was solved and the first optimal control input u0∗ was recorded.
The resulting surface represents
u0∗=f(x1,x2)(6.16)
Figure 6.1: First optimal control input u0∗ as a function of the initial state (x1,x2)
Figure 6.2: Contour representation of u0∗ over the initial-state plane
The same relation is shown as a contour plot in Figure 6.2. The contour representation provides a two-dimensional view of regions in the state space associated with similar optimal control actions.
6.2.2Optimal Bilinear Parameter Relation
The same state-space sweep was also used to evaluate the first optimal bilinear parameter. For each initial state, the optimization therefore provides
v0∗=g(x1,x2)(6.17)
Figure 6.3: First optimal bilinear parameter v0∗ as a function of the initial state (x1,x2)
Figure 6.4: Contour representation of v0∗ over the initial-state plane
The u0∗ surface shows how the immediate control action selected by the optimizer depends on the initial values of x1 and x2. Similarly, the v0∗ surface illustrates how the bilinear parameter is adjusted depending on the state.
7Kalman Filtering
7.1Theory Derivation
The Kalman filter is used to estimate the internal state of a stochastic system from noisy measurements. The system considered in this work is
xt+1yt=Axt+But+wt=Cxt+vt(7.1)(7.2)
where
wt∼N(0,Rw),vt∼N(0,Rv)(7.3)
Let
Yt={y0,…,yt}(7.4)
denote all measurements available up to time t. Before receiving the measurement yt, the state distribution conditioned on the previous measurements is represented by
xt∣Yt−1∼N(x^t∣t−1,Pt∣t−1)(7.5)
Thus, before yt is observed, the best available state estimate is x^t∣t−1, with uncertainty represented by Pt∣t−1.
To incorporate the new measurement, the joint distribution of the state and measurement is considered. Since the system and noise distributions are Gaussian, the variables xt and yt, conditioned on the previous measurements, are jointly Gaussian.
The required moments are first derived. The conditional mean of the state is
The projection theorem therefore provides the conditional mean and covariance of the state after the measurement has been observed. Applying it to the joint distribution of xt and yt gives the measurement-update equations
After the measurement update, the state estimate is propagated to the next time step. From the system dynamics,
xt+1=Axt+But+wt,(7.21)
the predicted state estimate becomes
x^t+1∣t=Ax^t∣t+But(7.22)
The corresponding covariance is
Pt+1∣t=Cov(Axt+But+wt∣Yt),(7.23)
which gives
Pt+1∣t=APt∣tAT+Rw(7.24)
The predicted quantities at time t+1 then become the prior quantities for the next iteration, and the procedure is repeated when the next measurement is received.
7.1.1Overview
The Kalman filter therefore consists of two main stages: the measurement update and the time update.
Starting with the prior state estimate
x^k∣k−1,Pk∣k−1(7.25)
the current measurement yk is first used to obtain the posterior state estimate
The resulting posterior state estimate is then propagated forward through the system model according to
x^k+1∣k=Ax^k∣k+Buk(7.28)
and
Pk+1∣k=APk∣kAT+Rw(7.29)
This corresponds to the time update. The predicted state x^k+1∣k then becomes the prior estimate for the next measurement step x^k∣k−1, and the same procedure is repeated.
7.2Results
The Kalman filter was evaluated using the stochastic bilinear system employed in the previous chapter. The system matrices were
A(v)=[0.900.00v0.50],B(v)=[01](7.30)
with
C=[10](7.31)
The process and measurement noise covariance matrices were selected as
Rw=[0.05000.05],Rv=[0.005](7.32)
The initial state distribution was defined using
μ0=[00],P0=[0.01000.01](7.33)
The controller weighting matrices were selected as
Q=1,RU=0.1,RV=0.1(7.34)
and the optimization variables were constrained by
−5≤uk≤5,−5≤vk≤5(7.35)
The reference levels were 3.1 and −1.3, with the reference changing after 15 time steps.
7.2.1Open-Loop
For the open-loop evaluation, the stochastic bilinear system was simulated over a horizon of 30 steps using 100 Monte Carlo realizations. The same optimized U and V sequences were used for all Monte Carlo realizations. The Kalman filter was then applied to the resulting noisy measurements.
7.2.1.1Single Trajectory
A single Monte Carlo realization was first selected to illustrate the estimation behavior of the Kalman filter. The estimated states were compared directly with the corresponding true states.
The uncertainty associated with the state estimate is also shown using the ±2σ interval obtained from the posterior covariance matrix. This provides a visual indication of the uncertainty represented by the filter.
Figure 7.1: Kalman-filter state estimate for a single stochastic bilinear open-loop trajectory
7.2.1.2Monte Carlo Result
The Kalman filter was then applied to all Monte Carlo trajectories. The true state trajectories and their corresponding Kalman-filter estimates are shown together in order to examine the estimation behavior over repeated stochastic realizations.
The empirical mean of the true trajectories and the empirical mean of the estimated trajectories are also displayed. In addition, the corresponding ±2σ regions show the spread of the Monte Carlo trajectories.
Figure 7.2: Monte Carlo true-state trajectories and Kalman-filter estimates for the stochastic bilinear open-loop simulation
7.2.1.3Performance Evaluation
The performance of the Kalman filter was further evaluated by examining the difference between the estimated and true states over all Monte Carlo realizations.
The mean estimation error is shown together with the empirical ±2σ spread of the estimation error. This is compared with the uncertainty predicted by the Kalman covariance matrix.
This comparison provides an indication of whether the covariance calculated by the Kalman filter appropriately represents the observed estimation uncertainty over the Monte Carlo simulations.
Figure 7.3: Mean estimation error and comparison between the empirical and Kalman-filter uncertainty for the stochastic bilinear open-loop simulation
7.2.2Closed-Loop
The Kalman filter was also evaluated using the stochastic bilinear closed-loop simulations. The same system and stochastic parameters were used.
In this case, the input sequences U and V can differ between Monte Carlo realizations. Consequently, the corresponding time-varying system matrices used in the Kalman-filter prediction step also depend on the individual realization.
7.2.2.1Single Trajectory
A single closed-loop Monte Carlo realization was first selected. The Kalman-filter estimate was obtained using the U and V sequences corresponding to that particular trajectory.
The true states, estimated states, and the corresponding ±2σ uncertainty interval are shown in Figure 7.4.
Figure 7.4: Kalman-filter state estimate for a single stochastic bilinear closed-loop trajectory
7.2.2.2Monte Carlo Result
The filter was subsequently applied to every closed-loop Monte Carlo trajectory. Since the optimized V-sequence can differ between realizations, the corresponding covariance propagation is also evaluated separately for each trajectory.
The true and estimated state trajectories are shown together with their empirical means and spreads.
Figure 7.5: Monte Carlo true-state trajectories and Kalman-filter estimates for the stochastic bilinear closed-loop simulation
7.2.2.3Performance Evaluation
Finally, the estimation errors from all closed-loop Monte Carlo trajectories were analyzed.
The mean estimation error and its empirical spread are compared with the uncertainty obtained from the Kalman covariance matrices. Since each trajectory may have a different V-sequence, the covariance evolution can also differ between simulations.
The comparison therefore provides a statistical evaluation of the state estimator under the stochastic bilinear closed-loop simulations.
Figure 7.6: Mean estimation error and comparison between the empirical and Kalman-filter uncertainty for the stochastic bilinear closed-loop simulation
8District Heating System
8.1Derivation of T˙i Equation
The district heating pipes are assumed to transport incompressible water with constant specific heat capacity. The flow velocity is assumed to be constant throughout each pipe, and only temperature variations in the axial direction are considered.
For a pipe with axial coordinate z, the energy balance is written as
∂tu(t,z)=−∂zNh(t,z)+q(t,z),z∈[z0,zf](8.1)
where u(t,z) denotes the internal energy per unit volume, Nh(t,z) denotes the enthalpy flux, and q(t,z) represents the heat loss per unit volume.
The enthalpy flux is expressed as
Nh(t,z)=H(T(t,z),p,N(t))(8.2)
where T(t,z) is the water temperature, p is the pressure, and N(t) is the molar flux. The molar flux is given by
N(t)=ρv(t)(8.3)
where ρ denotes the constant density and v(t) denotes the flow velocity.
The heat loss to the surroundings is modeled as
q(t,z)=−k(T(t,z)−Ta(t))(8.4)
where k is the conductance and Ta(t) is the ambient temperature.
Applying the chain rule to the enthalpy flux gives
∂TH(T(t,z),p,N(t))∂zT(t,z)=∂zNh(t,z)(8.5)
Using the specific heat capacity cp, this becomes
N(t)cp∂zT(t,z)=∂zNh(t,z)(8.6)
The pipe is then segmented into M finite volumes. For the i-th segment,
Ωi=[zi,zi+1](8.7)
and the energy balance is integrated over the segment:
where the states x(t) correspond to the average temperatures Tˉi(t), u(t) represents the supply temperature Ts, d(t) represents the ambient temperature Ta, and y(t) contains the temperatures measured at the selected pipe nodes.
8.2Change of Variable
From the temperature equation derived in the previous section,
T˙i=−Δzv(Ti−Ti−1)−ρcpk(Ti−Ta)(8.20)
To simplify the notation, define
α(v)=Δzv(8.21)
and
β=ρcpk(8.22)
The temperature dynamics can then be written as
T˙i=−α(v)(Ti−Ti−1)−β(Ti−Ta)(8.23)
A change of variables is introduced by defining the state relative to the ambient temperature as
xi=Ti−Ta(8.24)
Similarly, the input is defined as the supply temperature relative to the ambient temperature,
and the disturbance matrix associated with the change in ambient temperature is
Ec=−1−1⋮−1(8.38)
8.3Controller and Hidden Plant Approach
After introducing the change of variable
xi=Ti−Ta(8.39)
the continuous-time district heating model was obtained as
x˙=Ac(v)x+Bc(v)u+EcT˙a(8.40)
The change of variable therefore introduces the derivative of the ambient temperature into the state dynamics. In the implementation, the model used by the controller and the model used to simulate the physical plant are treated separately.
8.3.1Controller Approach
On the controller side, the ambient temperature is assumed to remain constant within each sampling interval. Thus,
Ta(t)=Ta,k,t∈[tk,tk+1)(8.41)
and consequently
T˙a(t)=0,t∈(tk,tk+1)(8.42)
Therefore,
EcT˙a=0(8.43)
and the continuous-time model used by the controller reduces to
x˙=Ac(v)x+Bc(v)u(8.44)
This model is discretized using a Zero-Order Hold assumption. During each sampling interval, the matrices and the input are kept constant. The resulting state at the end of the sampling interval is
Thus, the controller uses the discrete-time model generated from the continuous dynamics under the assumption that the ambient temperature does not change inside the sampling interval.
8.3.2Hidden Plant Approach
The hidden plant represents the system used to generate the simulated measurements. In contrast to the controller model, the hidden plant is affected by the actual ambient-temperature values.
Because the transformed state is defined relative to the ambient temperature, a change in Ta between two sampling instants changes the state coordinates. After the continuous evolution over one sampling interval,
xk+1=xk+1−+(Ta,k−Ta,k+1)1(8.47)
The ambient-temperature contribution is therefore defined as
dk=(Ta,k−Ta,k+1)1(8.48)
The hidden plant simulation consequently uses
xk+1=Akxk+Bkuk+dk+wk(8.49)
where
wk∼N(0,Rw)(8.50)
The output represents the outlet temperature relative to the current ambient temperature,
yk=Tout,k−Ta,k(8.51)
The measured output is modeled as
yk=Cxk+νk(8.52)
with
νk∼N(0,Rv)(8.53)
The hidden plant is used only to simulate the underlying system behavior. Its internal state is not assumed to be directly available to the controller. Instead, the controller receives the noisy output measurements, and the Kalman filter is applied to these measurements in order to estimate the internal state.
Therefore, the controller performs its prediction using the model in which the ambient temperature is assumed constant over each sampling interval, whereas the hidden plant evolves according to the actual ambient-temperature sequence through the additional term dk. This separation allows the effect of changing ambient conditions to be included in the simulation while maintaining the controller formulation based on the ZOH-discretized model.
8.3.3Change on Kalman Filter
The change of variable
xi=Ti−Ta(8.54)
also introduces a modification to the Kalman-filter procedure. Since the state is defined relative to the ambient temperature, a change in the ambient temperature between two consecutive sampling instants changes the state coordinates.
As derived previously,
xk+1=xk+1−+(Ta,k−Ta,k+1)1(8.55)
Defining
dk=(Ta,k−Ta,k+1)1(8.56)
the same correction must also be applied to the predicted state estimate of the Kalman filter.
The measurement-update equations remain unchanged. Starting from the prior estimate x^k∣k−1, the measurement yk is used to obtain
The time update is then first performed using the controller model,
x^k+1∣k−=Akx^k∣k+Bkuk(8.59)
At this stage, the predicted state is based on the assumption used by the controller that the ambient temperature remains constant over the sampling interval.
When the next ambient-temperature value Ta,k+1 becomes available, the change in ambient temperature is calculated through
dk=(Ta,k−Ta,k+1)1(8.60)
The predicted state estimate is then corrected as
x^k+1∣k=x^k+1∣k−+dk(8.61)
Therefore, the complete prediction step can be written as
x^k+1∣k=Akx^k∣k+Bkuk+dk(8.62)
After this correction, the time index is advanced,
k←k+1(8.63)
and the corrected prediction becomes the prior estimate used in the next measurement update.
Thus, the main modification to the Kalman-filter structure is the additional state correction introduced when the new ambient-temperature value becomes available. This allows the state estimate to remain consistent with the definition xi=Ti−Ta while the actual ambient temperature changes over time.
8.4Updates on Implementation
Two modifications were introduced in the implementation of the optimization problem. First, the changes in the control input U and flow velocity V were included in the cost function. Second, the numerical optimization method was changed from SLSQP to IPOPT due to the increase in computational time.
8.4.1Penalizing Changes in U and V
Previously, the objective function penalized the tracking error together with the magnitudes of the control input U and the flow velocity V. However, minimizing only these quantities does not explicitly discourage large changes between consecutive control actions.
Therefore, additional terms were introduced to penalize the changes in U and V. For consecutive prediction steps, these changes are defined as
Thus, R and S penalize the magnitude of the control variables, whereas Qchange and Schange penalize how rapidly these variables change from one time step to the next.
For k>0,
ΔukΔvk=uk−uk−1,=vk−vk−1(8.69)(8.70)
In the receding-horizon implementation, the first elements of the newly optimized sequences are compared with the values that were actually applied at the previous sampling instant. Therefore,
Δu0Δv0=u0−uprev,=v0−vprev(8.71)(8.72)
When no previous control value exists, such as at the beginning of the simulation, this first change term is not penalized.
Including these additional terms encourages smoother control-input and flow-velocity sequences and avoids unnecessarily large changes between consecutive optimization steps.
8.4.2Numerical Solver Change
The numerical solver used for the nonlinear optimization problem was also changed during the implementation.
The earlier stochastic bilinear models were solved using Sequential Least Squares Programming (SLSQP). As the district heating model was extended, the optimization problem became more computationally demanding. In particular, the larger state dimension, propagation of the stochastic covariance, chance constraints, bilinear dependence on V, and the additional penalties on the changes in U and V increased the computation time.
For this reason, the implementation was changed from SLSQP to IPOPT. The optimization problem is constructed using CasADi.
8.5Results
The developed controller was evaluated on the single-pipe district heating example. The pipe was divided into M=6 finite volumes over a total length of 6km, and the sampling time was selected as Δt=0.5h. The heat-loss coefficient was
β=7.66×10−3h−1(8.73)
Two temperatures were considered as measured outputs: the temperature at the pipe outlet and the temperature at the third finite volume. The initial temperature of the pipe was 65∘C, while the initial ambient temperature was 0∘C.
The physical output constraints were selected as
65∘C≤Tout≤90∘C(8.74)
for both measured locations. The supply-temperature and flow-velocity bounds were
50∘C≤Ts≤110∘C(8.75)
and
0.05≤v≤7.0km/h(8.76)
The reference temperatures were changed during the simulation according to
Each reference level was held for 48 sampling instants, corresponding to 24h. The ambient temperature was initially 0∘C and was changed to 10∘C at t=36h.
The weighting matrices used in the optimization were
Q=1011I,RU=0,RV=0(8.78)
together with the move-suppression weights
RΔU=10,RΔV=20(8.79)
The stochastic behavior was evaluated using 200 Monte Carlo realizations.
8.5.1Open-Loop
In the open-loop simulation, the optimization problem was solved once over the complete simulation horizon. The complete future ambient-temperature profile was provided to the controller before the optimization. Therefore, the calculated sequences U∗ and V∗ already account for the scheduled change in ambient temperature.
The same optimized input and velocity sequences were subsequently applied to all Monte Carlo realizations.
8.5.2Closed-Loop
For the closed-loop simulation, a prediction horizon of
N=12(8.80)
was used, corresponding to 6h. In contrast to the open-loop case, the controller does not receive the future ambient-temperature trajectory. At each sampling instant, only the currently available ambient temperature is used and is assumed to remain constant over the prediction horizon.
A separate MPC optimization is performed for every Monte Carlo realization. Consequently, each trajectory obtains its own optimal U∗ and V∗ sequences according to its current state estimate. Only the first elements of these sequences are applied, after which a new measurement is received and the optimization is repeated.
When a new ambient-temperature value becomes available, the Kalman-filter state prediction is corrected using the ambient-temperature re-basing term. The corrected state estimate is then used by the subsequent MPC problem. This allows the controller to respond to the actual ambient-temperature change without assuming its future value beforehand.
9Conclusion
During this internship, a complete MPC framework was developed step by step from linear deterministic systems to stochastic bilinear systems with chance constraints. The work also incorporated state-input analysis and Kalman filtering for state estimation under noisy measurements. The resulting controller was applied to a district heating system and evaluated in both open-loop and closed-loop settings using Monte Carlo simulations. The final implementation combines nonlinear optimization, uncertainty handling, probabilistic constraints, and state estimation, providing a basis for further development of stochastic MPC methods for district heating applications