% JuliaCon proceedings template
\documentclass{juliacon}

\usepackage{amsmath}
\usepackage{float}

\usepackage[super]{nth}

\setcounter{page}{1}

\begin{document}

\input{header}

\maketitle

\begin{abstract}

\textit{HydroPowerModels.jl} is a Julia package for solving multistage, steady-state, hydro-dominated, power network optimization problems with stochastic dual dynamic programming (SDDP). Our state-of-the-art open source tool is flexible enough for practitioners in the electrical sector to test new ideas in an efficient way. This tool was made possible by the Julia language and the surrounding ecosystem of packages. We use \textit{JuMP}, a package for mathematical programming modeling; \textit{PowerModels.jl}, a JuMP-extension for power network optimization; and \textit{SDDP.jl}, another extension that implements the SDDP algorithm.

\end{abstract}

\section{Introduction}

The hydrothermal dispatch problem is important for the planning and operation of hydro-dominated electrical systems such as the Brazilian national grid. The objective is to coordinate generation, energy distribution, and hydro-storage management in order to minimize the cost of operation. In this context, the hydrothermal dispatch problem is a medium-term planning problem where uncertainties related to the hydrology (i.e., rainfall and other inflows) of the hydroelectric plants and consumer-demand have fundamental importance. Generation takes two main forms: i) hydro-generation with a low marginal cost, and ii) thermal-generation, with a high marginal cost. However, in hydro-dominated systems such as Brazil, there is often insufficient capacity of thermal generation to meet demand. Thus, the system-operator faces a trade-off between using water for cheap generation in the present, against conserving water for future periods of drought. Because of this trade-off, the hydrothermal dispatch problem is often modeled as a multistage stochastic problem \cite{pereira1991multi,maceiral2018twenty,terlaky_marginal_2017}.
 %\vskip 6pt

Solving multistage stochastic programs, however, is a challenging numerical problem. The solution of the problem is intractable and common approximations such as stochastic dynamic programming \cite{bellman1966dynamic} \cite{bertsekas1995dynamic} can suffer from high dimensionality (frequently referred as the curse of dimensionality). One method that partially overcomes the curse of dimensionality is the stochastic dual dynamic programming algorithm of ~\cite{pereira1991multi}.

A number of programs implementing SDDP are in-use around the world, ranging from unpublished implementations in academic institutions to professional software such as the product developed by PSR, a software and consulting company, also called \textit{SDDP}\footnote{Note that the ``SDDP'' acronym is used to denote a software product, the original algorithm of \cite{pereira1991multi}, and a more general class of algorithms inspired by the original SDDP algorithm.} \cite{psr_software_2019}. However, until recently, there was no fast, reliable, and open-source implementation of the SDDP algorithm. Without such a tool, researchers and practitioners have not had a common ground for the discussion and analysis of different hydrothermal dispatch formulations and their solutions.

The objective of this work is to build an open source tool, called \href{https://github.com/andrewrosemberg/HydroPowerModels.jl}{\textit{HydroPowerModels.jl}}, that can be this common ground. \textit{HydroPowerModels.jl} can be used to assess the impact of modeling choices during the planning of a hydrothermal power system. These choices include the usage of different network formulations, the consideration of different risk measures, and the planning horizons for uncertain future costs. Addressing these issues provides the research community and the energy industry with a powerful tool for the efficient design of hydrothermal power systems.

To develop a tool that can be used by both researchers and industry professionals, we take advantage of the Julia language~\cite{bezanson2017julia} and two main packages: \href{https://github.com/lanl-ansi/PowerModels.jl}{\textit{PowerModels.jl} ~\cite{8442948}, which implements power flow models for electrical dispatch, \href{https://github.com/odow/SDDP.jl}{\textit{SDDP.jl}} ~\cite{dowson_sddp.jl}, which implements the stochastic dual dynamic programming algorithm}. Both \textit{PowerModels.jl} and \textit{SDDP.jl} handle their respective optimization models through \href{https://github.com/JuliaOpt/JuMP.jl}{\textit{JuMP.jl}} \cite{DunningHuchetteLubin2017}, a Julia package for mathematical optimization. \textit{JuMP.jl} makes it simple to write complex optimization problems and solve them with numerous solvers. \textit{HydroPowerModels.jl} takes advantage from the fact that \textit{PowerModels.jl} and \textit{SDDP.jl} were not only developed in Julia, but also deeply rely on \textit{JuMP.jl} to build and solve mathematical optimization problems. \textit{SDDP.jl} is used to specify the hydro storage dynamics and stochastics of inflows, renewables and loads. \textit{PowerModels.jl} is used to provide multiple network dispatch formulations as a starting point for the \textit{HydroPowerModels.jl} formulation that couples the electrical constraints with hydro constraints and uncertainty.

The next sections are organized as follows: 1) A brief understanding of multistage stochastic problems and decisions under uncertainty; 2) A presentation of the modeling formulation and problem specification; 3) Different simplifications of the model; 4) An explanation of the solution method (SDDP); 5) A comparison of existing alternative solution implementations and listing of the proposed package functionalities; 6) A case study to clarify usage.

\section{Multistage Stochastic Optimization}
\label{sec:multistochopt}

Stochastic Programming (SP) \cite{shapiro2009lectures} is a branch of optimization under uncertainty, where the realization of some random variables ($\omega$) influence the conditions of the problem and consequently the optimal decisions. Uncertainty relates to the probability distributions of parameters and may be incorporated to the problem in various manners.

One class of simple stochastic programs is known as a two-stage problem with recourse. It can be formulated as follows:

\begin{equation*}
\nth{1} \text{ Stage} \left\{
\begin{aligned}
& \underset{x}{\text{min}}
& & c^T x + \overbrace{\rho[Q(x, \omega)]}^{\mathcal{Q}(x)} \\
& \text{s.t.}
& & x \in \mathcal{X}
\end{aligned}
\right.
\end{equation*}

\begin{equation*}
\nth{2} \text{ Stage} \left\{
\mathcal{Q}(x, \omega) = \left\{
\begin{aligned}
& \underset{u}{\text{min}}
& & g^T u \\
& \text{s.t.}
& & A u = b(\omega)- E x \\
& & & u \in \mathcal{U}
\end{aligned}
\right. \right\}.
\end{equation*}

The objective of the first stage is composed of an \textit{immediate cost} term $c^T x$ and a \textit{cost-to-go function} $\mathcal{Q}(x)$. $\mathcal{Q}$ is a function of some decision variables of the first stage $x$ that fix the state of the second stage (its feasible region). These variables are called \textit{state variables}. First stage decisions are made under uncertainty, while the decision variables of the second stage $u$ are chosen after the realization of the variable $\omega$ (under a deterministic scope) and are so called \textit{recourse variables}. The function $\rho$ is known as a \textit{risk measure} \cite{artzner1999coherent} and is commonly assumed to be the expectation operator $\mathbb{E}$.

The goal of this problem is to find an optimal stage decision $x$ and an optimal second-stage decision $u$ for each realization of $\omega$ conditioned on $x$. Collectively, this set of decisions is known as a \textit{policy}.

The two-stage problem discussed above naturally extends to a \textit{multistage} problem via recursion. A multistage stochastic program with $T$ stages can be formulated as follows:

 \begin{equation*}
    \begin{aligned}[t]
        \underset{x_1 \in \mathcal{X}_1}{\text{min}}
        & f_1(x_1) + \\
        & \qquad \rho[ \underset{x_2 \in \mathcal{X}_2(x_1,\omega_{2})}{\text{inf}} f_2(x_2,\omega_{2}) + \\
        & \qquad \qquad \rho[... + \rho[\underset{x_T \in \mathcal{X}_T(x_{T-1},\omega_{T})}{\text{inf}} f_T(x_T,\omega_{T})]...]] \\
    \end{aligned}
\end{equation*}

Assuming the problem is linear, we have:

 \begin{equation*}
    \begin{aligned}
        & \mathcal{X}_{t}(x_{t-1},\omega) = \big\{ x_t \geq 0 : A_t x_t = b_t(\omega)- E_t x_{t-1} \big\} \\
        & f_t(x_t,\omega) = c_t^T x_t
    \end{aligned}
\end{equation*}

In this setting, the uncertain data $\omega_1 , ..., \omega_T$ is revealed gradually over time. The sequence $\omega_t \in \mathbb{R}^{d_t}$ of data vectors is viewed as a stochastic process, i.e., as a sequence of random variables with a specified probability distribution.

Just like in the two stage problem, there are state variables at every stage that partially impact the objective through the risk measure of the subsequent stages optimal values. The policy optimized by this problem is a mapping from the realized stochastic process to the decisions for each stage.

Using dynamic programming \cite{bellman1966dynamic}, the nested formulation of a multistage stochastic program may be represented by the following Bellman recursion for each stage:

 \begin{equation*}
    Q_t(x_{t-1}, \omega_{t}) = \left\{
    \begin{aligned}
    & \underset{x_t}{\text{min}}
    & & c_t^T x_{t} + \rho_{t+1}[Q_{t+1}(x_{t}, \omega_{t+1})]  \\
    & \text{s.t.} \notag
    & & A_t x_t = b_t(\omega_{t})- E_t x_{t-1} \qquad [\pi_t(\omega_{t})]\\
    & & & x_t \geq 0 \\
    \end{aligned}
    \right\}
\end{equation*}

For the purpose of simplicity, we assume that $\mathcal{Q}_{T+1}(\cdot, \cdot) = 0$.

In these equations, the optimal value at stage $t$ depends on previous decision $x_{t-1}$ and the realization of the data process $\omega_t$. Finally, the optimal value of the first stage problem gives the optimal value of the corresponding multistage problem.

\section{The Hydrothermal Dispatch Problem}
\label{sec:problemformulation}
%
The hydrothermal dispatch problem is a multistage stochastic optimization problem that comprises an optimal power flow (OPF) problem and the hydro storage management for multiple periods and scenarios.

Introduced by \cite{carpentier1962contribution}, the OPF problem extends the economic dispatch problem, where the goal is to plan the operation of an electrical power system by determining the contribution of available energy sources in supplying demands, to include constraints representing the power flow equations, resulting in a more realistic model of the dispatch.

Since its introduction, the OPF problem has received additional constraints to better represent power systems. The adopted version of the \textit{PowerModels.jl} package, is a AC Optimal Power Flow (AC-OPF) problem. The AC Power Flow constraints implement voltage bounds, generation bounds, nodal conservation of power, power flow on lines and thermal limit of the lines (power flow limit) for an alternating current system. Different from original OPF formulations, support was also added for multiple load and shunt components on each bus together with a line charging that supports conductance and asymmetrical values.

Besides the modifications from \textit{PowerModels.jl}, deficit variables to work as slack to the attendance of each load have frequently been used by the electrical sector and will be incorporated in our package. This variables allow a more detailed evaluation of the cost of not attending some demands.

The optimal dispatch tries to find the most economic use of system resources and is the objective function of an OPF. However, in a hydrothermal power system, where water is a main resource and its inflow is uncertain, risk averse planning is an important task to ensure the lowest cost operation. The necessary hydro storage management to attend demand during periods of scarcity adds an extra layer of decisions and constraints.

Reservoir operation is a problem composed by the balance of incoming and outgoing flow of water as well as its usage to generate power. Since many storage facilities are linked through rivers, this problem may be simply viewed as a directed flow graph where each node in the graph represents a storage reservoir. A constraint binds the power generation of generators using water as fuel to the outflow of the respective storage. Operation is also restricted by the limits of reservoir volume and outflow.

The solution of this problem returns an operation policy representing the optimal generation and hydro management possible given the horizon studied and the scenarios considered.

As it is common for multistage problems, we will define the underlying sub-problem (i.e., $\mathcal{Q}$) that unifies the OPF problem with the hydro-thermal dispatch problem.

\subsection{The Mathematical Model}
\label{subsub:mathmodel}

Following the notation chosen by the \textit{PowerModels.jl} package, the sets and parameters used to define the sub-problem are listed with the addition of those created for the hydro storage management and the data for the state of the sub-problem:

\subsubsection*{Sets}
\begin{align*}
%
% \mbox{sets:} & \nonumber \\
& N \mbox{ - buses}\nonumber \\
& R \mbox{ - reference buses}\nonumber \\
& E, E^R \mbox{ - branches, forward and reverse orientation} \nonumber \\
& G, G_i \mbox{ - generators and generators at bus $i \in N$} \nonumber \\
& L, L_i \mbox{ - loads and loads at bus $i \in N$} \nonumber \\
& S, S_i \mbox{ - shunts and shunts at bus $i \in N$} \nonumber \\
& H, H^G \mbox{ - reservoirs and reservoirs with power generation}\nonumber \\
& H^U_h, H^{\mathfrak{S}}_h \mbox{ - upstream reservoirs out-flowing and spilling to $h\in H$ }\nonumber \\
& G^H_h \mbox{ - generator at reservoir $h\in H$}\nonumber \\
%
\end{align*}

\subsubsection*{Data}
\begin{align*}
%
% \mbox{data:} & \nonumber \\
& S^{gl}_k, S^{gu}_k \;\; \forall k \in G \nonumber \mbox{ - generator complex power bounds}\\
& c_{2k}, c_{1k}, c_{0k} \;\; \forall k \in G \nonumber  \mbox{ - generator cost components}\\
& v^l_i, v^u_i \;\; \forall i \in N \nonumber \mbox{ - voltage bounds}\\
& S^d_k \;\; \forall k \in L \nonumber \mbox{ - load complex power consumption}\\
& Y^s_{k} \;\; \forall k \in S \nonumber \mbox{ - bus shunt admittance}\\
& Y_{ij}, Y^c_{ij} \;\; \forall (i,j) \in E \nonumber \mbox{ - branch pi-section parameters}\\
& {T}_{ij} \;\; \forall (i,j) \in E \nonumber \mbox{ - branch complex transformation ratio}\\
& s^u_{ij}  \;\; \forall (i,j) \in E \nonumber \mbox{ - branch apparent power limit}\\
& i^u_{ij}  \;\; \forall (i,j) \in E \nonumber \mbox{ - branch current limit}\\
& \theta^{\Delta l}_{ij}, \theta^{\Delta u}_{ij} \;\; \forall (i,j) \in E \nonumber \mbox{ - branch voltage angle difference bounds}\\
& \overline{\nu}_h  \;\; \forall h \in H \nonumber \mbox{ - reservoir volume limit}\\
& \overline{u}_h  \;\; \forall h \in H \nonumber \mbox{ - reservoir outflow limit}\\
& p_h  \;\; \forall h \in H^G \nonumber \mbox{ - hydro generation production factor}\\
& c_{d} \nonumber \mbox{ - deficit cost}\\
& c_{s} \nonumber \mbox{ - spillage cost}\\
%
\end{align*}

\vspace{5mm}

\subsubsection*{Operators}
\begin{align*}
%
& \Re \nonumber \mbox{ - real part of a complex number}\\
& \angle \nonumber \mbox{ - angle of the polar representation of a complex number}\\
& (\cdot)^{*} \nonumber \mbox{ - complex conjugate}\\
& |\cdot| \nonumber \mbox{ - absolute value}\\
%
\end{align*}

\subsubsection*{States}
\begin{align*}
%
% \mbox{state:} & \nonumber \\
& \nu_{h,t-1}  \;\; \forall h \in H \nonumber \mbox{ - incoming reservoir volume}\\
& a_{h}  \;\; \forall h \in H \nonumber \mbox{ - reservoir inflow}\\
%
\end{align*}

For simplicity the stage index $t$ of the sub-problem is omitted from every data and variable with exception of the incoming reservoir volume $\nu_{h,t-1}$ (in order to differentiate it from the outgoing reservoir volume $\nu_{h}$).

Notice that, as usual, alternating components (i.e. voltage, power generation, power demand and power flow) are modeled using complex numbers to fully represent the process.

Bellow, the decision variables of our problem:

\subsubsection*{Variables}

\begin{align*}
%
& S^g_k \;\; \forall k\in G \mbox{ - generator complex power dispatch} \\
& V_i \;\; \forall i\in N \mbox{ - bus complex voltage}\\
& S_{ij} \;\; \forall (i,j) \in E \cup E^R \mbox{ - branch complex power flow}\\
& U_h \;\; \forall h \in H \mbox{ - reservoir outflow}\\
& \mathfrak{S}_h \;\; \forall h \in H \mbox{ - reservoir spillage}\\
& \nu_h \;\; \forall h \in H \mbox{ - reservoir volume}\\
& D_i \;\; \forall i\in N \mbox{ - bus complex deficit}\\
%
\end{align*}

A complete mathematical model of the sub-problem is as follows,
\begin{subequations} \label{AC_OPF}
\begin{align}
%
& \mathcal{Q}_t(\nu_{t-1},\omega_t) = \nonumber \\
%
\mbox{minimize: } & \sum_{k \in G} c_{2k} (\Re(S^g_k))^2 + c_{1k}\Re(S^g_k) + c_{0k} + \nonumber\\
& \qquad \sum_{i \in N} c_{d} \Re(D_i) +  \sum_{h \in H} c_{s} \mathfrak{S}_h + \rho_{t+1}[\mathcal{Q}_{t+1}(\nu_{t}, \omega_{t+1})] \label{eq_objective}\\
%
\mbox{subject to: } & \nonumber \\
& \angle V_{r} = 0  \;\; \forall r \in R \label{eq_ref_bus}\\
& D_i+ \sum_{\substack{k \in G_i}} S^g_k - \sum_{\substack{k \in L_i}} S^d_k - \sum_{\substack{k \in S_i}} Y^s_k |V_i|^2 \nonumber \\
& \qquad = \sum_{\substack{(i,j)\in E_i \cup E_i^R}} S_{ij} \;\; \forall i\in N \label{eq_kcl_shunt} \\
& S_{ij} = \left( Y_{ij} + Y^c_{ij}\right)^* \frac{|V_i|^2}{|{T}_{ij}|^2} - Y^*_{ij} \frac{V_i V^*_j}{{T}_{ij}} \;\; \forall (i,j)\in E \label{eq_power_from}\\
& S_{ji} = \left( Y_{ij} + Y^c_{ji} \right)^* |V_j|^2 - Y^*_{ij} \frac{V^*_i V_j}{{T}^*_{ij}} \;\; \forall (i,j)\in E \label{eq_power_to}\\
& |S_{ij}| \leq s^u_{ij} \;\; \forall (i,j) \in E \cup E^R \label{eq_thermal_limit}\\
& \theta^{\Delta l}_{ij} \leq \angle (V_i V^*_j) \leq \theta^{\Delta u}_{ij} \;\; \forall (i,j) \in E \label{eq_angle_difference}  \\
& \nu_h + U_h + \mathfrak{S}_h = \nu_{h,t-1} + a_h(\omega_t) + \nonumber \\
& \qquad  \sum_{\substack{k \in H^U_h}} U_k + \sum_{\substack{k \in H^{\mathfrak{S}}_h}} \mathfrak{S}_k \;\; \forall h \in H \label{eq_hydro_balance} \\
& U_h p_h = \Re(S^g_{G^H_h}) \;\; \forall h \in H^G \label{eq_hydro_generation} \\
& S^{gl}_k \leq S^g_k \leq S^{gu}_k \;\; \forall k \in G  \label{eq_gen_bounds}\\
& v^l_i \leq |V_i| \leq v^u_i \;\; \forall i \in N \label{eq_voltage_bounds}\\
& 0 \leq \nu_h \leq \overline{\nu}_h \;\; \forall h \in H \label{eq_volume_limit}\\
& 0 \leq U_h \leq \overline{u}_h \;\; \forall h \in H \label{eq_outflow_limit}
%
\end{align}
\end{subequations}
\footnote{Note that the elements of E are pairs of elements of N, so, in equations (\ref{eq_power_from}) and (\ref{eq_power_to}), variables defined over N are indexed by elements of E.}

The objective of the sub-problem (\ref{eq_objective}) is to minimize the costs of real power generation, cost of deficit from the real energy supply, cost of spillage (in order to try and avoid degenerate solutions) and the cost-to-go function $\mathcal{Q}$.

Constraint (\ref{eq_ref_bus}) fixes reference buses complex voltage angles to zero, as the remaining angles will be defined accordingly.

Constraint (\ref{eq_gen_bounds}) bounds the complex power generation, representing the physical limitation of generators and fuel source availability.

The magnitude of the complex voltage is bounded in constraint (\ref{eq_voltage_bounds}) by restricting the absolute square of its value. The upper limit alone defines a circular feasible region for each voltage, while the lower limit reshapes the region as a ring, bringing a non-convexity to the problem.

The Branch complex power flow is formulated in (\ref{eq_power_from}) and (\ref{eq_power_to}), dependent on the voltage at each end and implementing elements of line charging and the effects of transformers.
The power flow is bounded in (\ref{eq_thermal_limit}) through its absolute value. These power limits of the lines represent thermal limits and stability limits.

Constraint (\ref{eq_kcl_shunt}) implements Kirchhoff’s Current law (KCL), which refers to power preservation at each node, balancing generation, demand, flow and shunt. Although, deficit variables have been added in order to guarantee feasibility in case of lack of power availability.

Angle difference between buses are bounded in (\ref{eq_angle_difference}). The reason for the limits is to approximate the transient stability constraints of power flowing in branches. These restrictions refer to the synchronism among machines at each end of a line. The limits depend on the equipment installed and the system configuration.

An important variable in an economic dispatch problem is the marginal cost of energy at each bus, which, in optimality, is determined by the dual value of (\ref{eq_kcl_shunt}). This value is also referred to as a shadow price, local marginal price (LMP), or nodal price. Regardless, this value represents the cost of an extra unit of energy in a bus.

The conservation of water equation is implemented in (\ref{eq_hydro_balance}), where the water stored at a reservoir should equal the water previously stored plus the incoming flow (precipitation and water from upstream reservoirs), minus the portion used to generate energy and the one spilled away.

The binding of the hydro real power generation and water used is done in (\ref{eq_hydro_generation}), which depends on the efficiency of the generator modeled through a production factor.

Constraints (\ref{eq_volume_limit}) and (\ref{eq_outflow_limit}) bound respectively the volume of water stored and the amount of water used in generation. These limits are defined by the capacity limit of storage facility and the equipment installed.

Note that problem (\ref{AC_OPF}) is a nonlinear, non-convex optimization problem. This will have important implications for our solution approach.

\section{Network Formulations}
\label{sec:powermodels}

The AC Optimal Power Flow problem, defined in (\ref{AC_OPF}), captures the nonlinear and complex nature of the power flow. However, solving a nonlinear problem (NLP) is hard. Guaranteeing global optimality often involves an extensive number of comparisons and, thus, it is not done. Local optimums are used instead, providing inconsistent solutions. Along with the scarcity of efficient NLP solvers and the numerical issues created by large problem instances, the depth of research using AC-OPF is reduced. Besides, the requirement of convexity frequently needed for applications limit its usage.
Hence, many approximations and relaxations have been developed for the AC-OPF \cite{molzahn2019survey}. In general these are simplifications and are easier to solve, but they ignore some parts of the problem. As a result, it is imperative to understand and weigh the advantages and compromises of each formulation when choosing one to use in a model.

The \textit{Linear DC approximation} is a linear formulation which partially represents power voltage. This formulation makes some assumptions for linearization purposes: voltage magnitudes are sufficiently near nominal value (one), angle differences are close to zero, and there are practically no power losses. In all effects, a purely active power system linear model. Still it is important to notice that, while this model seeks to approximate the feasible region of the AC power flow, it may not include the entire feasible region, including the global optimum.

Instead of approximating parts of the power system, it is possible to relax some of the nonlinear power flow constraints. The resulting \textit{relaxations}, when solved to optimality, provide lower bounds to the original problem because their feasible sets include all the solutions of the original problem. Different convex relaxations were proposed for the optimal power flow problem, here we highlight some of the most important ones. Convex relaxations are specially useful because their solution can be proved to be optimal.

The \textit{Copper Plate} is the simplest linear relaxation and models the system by a centralized energy pool, relaxing transmission lines limits and the Kirchhoff’s laws. Easily implementable and solvable, this is the most simplified linear formulation, neglecting the entire grid of the problem. However, because of the simplifications of this model it produces only one shadow price, i.e. the marginal price of energy in each node of the network are equal. This may send a distorted signal to the agents responsible for the system, and may return the most unfeasible solution across all formulations.

Another linear relaxation, the \textit{Transportation model}, or tube model, extends Copper Plate by adding line limits. Locational restrictions are better represented and the value of transmission lines are clearer. Although, by completely ignoring the power voltage, network design becomes less relevant and incorrect system analysis is possible.

The \textit{SOC relaxation} is a non-linear convex relaxation that is tighter than the linear versions, i.e., its feasible region is strictly contained inside them. This formulation relaxes the non-convex constraints of the problem, composed by the bilinear product of the voltage variables, by neglecting the phases of the voltages and saving only their branch wise difference and magnitudes. The resulting problem may be specified as a second order cone formulation, hence its name.

The \textit{SDP relaxation} deals with the non-convex constraints of the problem by using the fact that they define a positive semi-definite matrix with rank 1. The relaxation comes from removing the rank 1 restriction. The feasible region of this formulation is contained within the feasible region of the SOC relaxation, providing a better bound to the original problem.

The \textit{QC relaxation} exploits the polar form of the non-convex constraints and uses known convex envelopes to relax each non-convex term present. These envelopes retain stricter links between the voltage variables, producing a tighter relaxation than the SOC formulation.

These, and other relaxations, provide a good alternative to solve the original problem. Besides bounding the optimal value of the original problem, they have sufficiently good solutions for real world applications.
In fact, by being convex, these relaxations are suitable to be used in many solution methods for multistage problems, for instance SDDP for which convergence is guaranteed if subproblem are convex.

The \textit{PowerModels.jl} package, a framework for steady-state power network optimization, is able to construct these and other mathematical programming formulations of the OPF problem. Since \textit{PowerModels.jl} uses \textit{JuMP.jl} to construct these formulations, they can be passed to a variety of solvers. This allows the user to easily choose an approximation or relaxation, solve it, and then discuss and compare the impacts of using different relaxations and approximations in the planning and operation of the economic dispatch problem.

\section{Solution method}
\label{sec:sddp}

As we have seen, the hydrothermal dispatch is a complicated problem with different network formulations. The OPF problem, is only a part of a sub-problem composing a multistage stochastic program. As discussed previously, solving a multistage stochastic program has its own difficulties, and requires specific and efficient algorithms.

In a multistage stochastic program, we are faced with a cost-to-go function: $\rho_{t+1}[Q_{t+1}(x_{t}, \omega_{t+1})]$. The issue is that $\rho_{t+1}[Q_{t+1}(x_{t}, \omega_{t+1})]$ also depends on a cost-to-go $\rho_{t+2}[Q_{t+2}(x_{t+1}, \omega_{t+2})]$, and the evaluation of those functions can be expensive.

The crucial step that facilitates the solution of these problems is to construct approximations of the cost-to-go functions, recursively, going backward in time. Thus, the optimal value of the first stage problem approximates the optimal value of the corresponding multistage problem.

For the construction of this approximation a widely used method is dynamic programming, which evaluates the function in a range of discrete values of the state variable for further interpolation. However, this method becomes intractable with the growth of the state dimension (commonly referred as the \textit{curse of dimensionality} of dynamic programming). A solution for this was proposed by \cite{pereira1991multi} with a method called stochastic dual dynamic programming (SDDP).

The methodology, simply posed, approximates the cost-to-go function by the maximum of a set of linear hyper-planes called \textit{cuts}.

SDDP is based on an interactive construction of the cost-to-go function approximations. The procedure may be divided in sub-sequential forward and backward passes, where the first chooses points in which the second will update the current approximation of the functions. For a detailed discussion of the SDDP algorithm, see \cite{pereira1991multi,dowson_sddp.jl}.

Other solution algorithms have been proposed to solve multistage problems, such as progressive hedging and nested Benders. However, for most large instances, none has proven to be viable and efficient alternatives. SDDP has been extensively used to solve and plan hydrothermal dispatch operations since its original publication.

On the other hand, this method is a complex and difficult to implement algorithm. Moreover, to make it flexible enough for different applications while not compromising performance is a main issue. Hence, the historical scarcity of reliable and open software versions has limited development and discussions of its contributions. Yet, new and efficient implementations have risen with the advance of open-source languages as the Julia language.

One such implementation is \textit{SDDP.jl}, a Julia/JuMP package for solving large multistage convex stochastic optimization problems using SDDP. It provides a practical and efficient way to find the solution to the hydrothermal dispatch problem. With this package it was possible to define the dynamics and random variables of our problem and solve the instantiated model with the SDDP algorithm.

\section{HydroPowerModels.jl}
\label{sec:hydropowermodels}

\textit{HydroPowerModels.jl} uses the \textit{PowerModels.jl} and \textit{SDDP.jl} packages to implement and solve different hydrothermal dispatch formulations. It provides an interface to easily solve and simulate hydrothermal dispatch models and allows the creation of a collection of hydrothermal problems described in input files for the package (following the \textit{PowerModels.jl} standard), thereby helping the discussion of methodology and the resulting policies for specific case instances.

In contrast to the previously available official software for hydrothermal dispatch models, the proposed package is part of an academic open-source effort. This helps to promote the continuous improvement of models and solution algorithms for the research community.

Other academic implementations of SDDP have being developed and may be applied to the hydrothermal dispatch problem. However, the advances of the Julia Language and \textit{JuMP.jl} are a much more adequate framework than those of MATLAB \cite{FATS} or Python \cite{raso2016optimist,Lingquan2019}.  Moreover, a free and open-source tool can be of great help for the research community alternatively to commercial solvers as \cite{lohndorf2018quasar} and the renowned version from \href{https://www.psr-inc.com/softwares-en/}{\textit{PSR Inc}}.

Additional implementations of SDDP are also available in Julia \cite{leclerestochdynamicprogramming} \cite{StructDualDynProg}, but \textit{SDDP.jl} \cite{dowson_sddp.jl} has proven an easy to learn, efficient version of SDDP that is flexible enough for the purposes of the \textit{HydroPowerModels.jl} package.

\textit{HydroPowerModels.jl} is composed of different and useful functionalities, from compact case sharing to dispatch solution results visualizations. A work-flow of a simple usage of the package helps to give a basic overview:

\begin{itemize}
    \item Load case data from input files describing: Power network data; Reservoir facilities details and water network data; Inflow scenarios.
    \item Receive case parameters: Power network formulation; Number of stages; Number of hours in Stage and optimizer to solve the sub-problems.
    \item Build the multistage, hydrothermal steady-state power network optimization problem.
    \item Run SDDP method to approximate the cost-to-go functions.
    \item Simulate the policy.
\end{itemize}

A code example is presented in the next subsections to help clarify the usage of the package. Although, for a more extensive tutorial of the package, a detailed documentation is made available in \url{https://andrewrosemberg.github.io/HydroPowerModels.jl/latest/}.

\subsection{Usage}
\label{subsub:usagehpm}
The usage of \textit{HydroPowerModels.jl} follow the paradigms of the Julia language and the structure of the dependent packages.

In order to access the available functionalities, first import \textit{HydroPowerModels.jl} and an adequate solver:

\begin{lstlisting}[language = Julia]
using HydroPowerModels
using GLPK
\end{lstlisting}

Load a case by passing the folder containing the input files (\texttt{PowerModels.json}, \texttt{hydro.json}, and \texttt{inflows.csv}):

\begin{lstlisting}[language = Julia]
data = HydroPowerModels.parse_folder(
    "case3_folderpath")
\end{lstlisting}

Use \texttt{create\_param} to create a set of problem parameters. For example, a 12-stage problem using the DC approximation can be specified as follows:
\begin{lstlisting}[language = Julia]
params = create_param(
 stages      = 12,
 stage_hours = 168.0,
 model_constructor_grid = DCPPowerModel,
 optimizer   = with_optimizer(GLPK.Optimizer))
\end{lstlisting}

Then, build the Model and execute the SDDP \texttt{train} method:

\begin{lstlisting}[language = Julia]
m = hydrothermaloperation(data, params);

HydroPowerModels.train(m)
\end{lstlisting}

Finally, simulate the performance of the policy with 1000 Monte Carlo scenarios:

\begin{lstlisting}[language = Julia]
# Simulate 1000 instances
results = HydroPowerModels.simulate(m, 1000);
\end{lstlisting}
\begin{lstlisting}[language = Julia]
 Dict{Any,Any} with 5 entries:
"simulations" => Dict[Dict{Any,Any}(Pair{Any,...
"data"        => Dict{Any,Any}[Dict{Any,Any}(...
"params"      => Dict{Any,Any}(Pair{Any,Any}(...
"machine"     => Dict("cpu"=>"Intel(R) Xeon(R)...
"solve_time"  => 205.31247
\end{lstlisting}

\section{Case Study}
\label{sec:case}

For a case study, consider a the hydrothermal dispatch of a realistic system with the following specifications:

\begin{itemize}
    \item Number of buses: 166
    \item Number of loads: 286
    \item Number of generators: 145
    \item Number of branches: 235
\end{itemize}

In order for a qualitative view of the system, the package disposes a graph illustration plot:

\begin{lstlisting}[language = Julia]
plot_grid(data, node_label=false)
\end{lstlisting}

\begin{figure}[htb]
\centerline{\includegraphics[width=1.4\linewidth]{fig/graph_grid.png}}
\caption{Network Grid graph}
\label{fig:graph_grid}
\end{figure}

Figure \ref{fig:graph_grid} shows the installed power available in the network (grouped by bus) using a logarithmic scale. The red nodes represent the thermal generators, the blue represent the hydro generators. For comparison purposes, orange nodes have been added that are equivalent to average real power demands.

As we can see from the plot of the grid \ref{fig:graph_grid}, this appears to be a well balanced case, with similar installed hydro and thermal power capacity and with a reasonable average demand. In addition, it is a well distributed network, without any evident critical sections susceptible to impacting power flow problems. Those facts are indications of a significant hydro-generation optimal dispatch without large complications.

For this study, a 52 stage horizon planning and simulation have been executed using the following case parameters:

\begin{itemize}
    \item Number of stages: 52
    \item Number of hours in stage: 168
    \item Network Formulation: Transportation model relaxation
\end{itemize}

\subsection{Results} %\label{subsub:results}

The simulate command returns a detailed dictionary of the execution. In order to plot those results returned by the simulate function, you may choose from a variety of methods, including the function \texttt{plot\_aggregate\_results()}. This function receives the dictionary results and generates the most common aggregated variable plots, which best summarize simulations of a hydrothermal dispatch:

\begin{lstlisting}[language = Julia]
plot_aggregated_results(results)
\end{lstlisting}

% Figures \ref{fig:plot_agg_result_thermal} to
Figures 2 to \ref{fig:plot_agg_result_inflow} show the output from the above command. As mentioned, the plots are of aggregated quantities, but the methods used to aggregate were chosen in order to help analysis. For example: the final nodal price is an average of nodal prices weighted by the contribution of local loads to the total demand; reservoir volume was grouped weighted by the amount of energy that could be produced by the stored water (as was the inflow of water).

As expected the optimal dispatch of the simulations uses more hydro-generators, however it needs thermal-generators to met all demands without deficit. On this hydro-dominated system, the uncertain inflow is a driving factor of optimal dispatch. As we can see in Figure \ref{fig:plot_agg_result_inflow}, the inflow has a strong seasonality component, resulting the significant seasonality trait observable in the variables of the policy simulations.
%\ref{fig:plot_agg_result_thermal}
2-\ref{fig:plot_agg_result_load}, \ref{fig:plot_agg_result_hydrogen}-\ref{fig:plot_agg_result_vol}.

Similar studies are possible for any case and formulation chosen, helping to analyze existing realistic cases and assess impacts of future system changes. For example, we reran the study using a SOC relaxation to compare results. Most quantities analyzed, as those presented in the aggregated results, are similar, but operation costs differ as it is observable in figures \ref{fig:hist_cost_tube},\ref{fig:hist_cost_soc}. This is expected, since the SOC relaxation is a more realistic representation of reality.

Moreover, it is important to point out this extra cost would be even bigger if we used the policy of the transportation model to operate the SOC model in the simulations. In other words, there is a hidden cost when planning a dispatch associated with the fact we are not evaluating costs on the actual system we want to operate.

Therefore, measuring the impacts of possible simplifications is a needed step in discussing hydrothermal economic dispatch. \textit{HydroPowerModels.jl} intends to provide a common ground for discussions and analysis and a easy to use tool for research and applications.

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_thermal.png}}
\label{fig:plot_agg_result_thermal}
\caption{Thermal Generation}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_load.png}}
\caption{Load Weighted Average Nodal Price}
\label{fig:plot_agg_result_load}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_def.png}}
\caption{Deficit}
\label{fig:plot_agg_result_def}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_hydrogen.png}}
\caption{Hydro Generation}
\label{fig:plot_agg_result_hydrogen}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_hydroturn.png}}
\caption{Reservoir Outflow}
\label{fig:plot_agg_result_hydroturn}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_hydrospill.png}}
\caption{Reservoir Spillage}
\label{fig:plot_agg_result_hydrospill}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_vol.png}}
\caption{Volume Reservoir}
\label{fig:plot_agg_result_vol}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.7\linewidth]{fig/plot_agg_result_inflow.png}}
\caption{Inflow}
\label{fig:plot_agg_result_inflow}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.9\linewidth]{fig/hist_cost_tube.png}}
\caption{Simulation Costs Transportation}
\label{fig:hist_cost_tube}
\end{figure}

\begin{figure}[H]
\centerline{\includegraphics[width=0.9\linewidth]{fig/hist_cost_soc.png}}
\caption{Simulation Costs SOC}
\label{fig:hist_cost_soc}
\end{figure}

\input{bib.tex}

\end{document}

% Inspired by the International Journal of Computer Applications template


\subsection{Harmonizer}

Harmonizer is structure which detunes input signal slightly to get different "players" play
slightly out of tune as in the real orchestra section. Transpose of the harmonizer is always sharp
because Dudas\cite{dudas} claimed that sharp notes are percieved less out of tune than flat ones.
The block diagram of the harmonizer is shown in figure \ref{fig:harm}

In harmonizer structure there are four channels which are windowed with four sinusoidal windows
that are 90 degrees more out of phase than previous. To decrease the beating effect that is present
in the current chorus there is added some random variance to the detuning of the sound. That means
that each window is slightly differently out of tune. That is as well related to the real world as the players
usually do not play whole music piece in same detuning. \cite{dudas}
\begin{figure}[ht]
\centering
\includegraphics[width = 8cm]{harmonizer.png}
\caption{Chorus Harmonizer Block Diagram. \cite{dudas}}
\label{fig:harm}
\end{figure}

The detuning is made with multi-tap delay-line which is modulated with phasor signal which is basic sawtooth
wave form. After that each channel is windowed by using Hanning window and after that it is allpass filtered.
The windows are triggered with phasor signal and it as well triggers the randomization for each window.
After allpass fitering all the channels are summed together. \cite{dudas}


\chapter{Filterization of pointfree funcoids}

Let $(\mathfrak{A},\mathfrak{Z}_0)$ and $(\mathfrak{B},\mathfrak{Z}_1)$ be primary filtrators over boolean lattices.
By corollary~\bookref{filt-is-complete} we have that $\mathfrak{A}$ and~$\mathfrak{B}$ are complete lattices.

Let $f$ be a pointfree funcoid $\mathfrak{Z}_0\rightarrow\mathfrak{Z}_1$. Define pointfree funcoid~$\uparrow f$ (\emph{filterization} of~$f$)
by the formulas
\[
\supfun{\uparrow f} \mathcal{X} = \bigsqcap^{\mathfrak{B}}_{X\in\up\mathcal{X}} \supfun{f}X \quad\text{and}\quad
\supfun{\uparrow f^{-1}} \mathcal{Y} = \bigsqcap^{\mathfrak{A}}_{Y\in\up\mathcal{Y}} \supfun{f^{-1}}Y.
\]

\begin{prop}
$\uparrow f$ is a pointfree funcoid.
\end{prop}

\begin{proof}
~
\begin{multline*}
\mathcal{Y} \nasymp \supfun{\uparrow f} \mathcal{X} \Leftrightarrow
\mathcal{Y} \nasymp \bigsqcap^{\mathfrak{B}}_{X\in\up\mathcal{X}} \supfun{f}X \Leftrightarrow \\
\bigsqcap^{\mathfrak{B}}_{X\in\up\mathcal{X}} (\mathcal{Y} \sqcap^{\mathfrak{B}} \supfun{f}X) \ne \bot \Leftrightarrow \text{ (corollary~\bookref{genbase-corr}*)} \\
\forall X\in\up\mathcal{X}: \mathcal{Y} \sqcap^{\mathfrak{B}} \supfun{f}X \ne \bot \Leftrightarrow \text{ (theorem \bookref{when-sep-core})} \\
\forall X\in\up\mathcal{X}, Y\in\up\mathcal{Y}: Y \sqcap^{\mathfrak{B}} \supfun{f}X \ne \bot \Leftrightarrow \text{ (corollary \bookref{f-meet-closed})} \\
\forall X\in\up\mathcal{X}, Y\in\up\mathcal{Y}: Y \sqcap^{\mathfrak{Z}_1} \supfun{f}X \ne \bot \Leftrightarrow \\
\forall X\in\up\mathcal{X}, Y\in\up\mathcal{Y}: X\suprel{f}Y.
\end{multline*}

* To apply corollary~\bookref{genbase-corr} we need to show that
$\setcond{\mathcal{Y} \sqcap^{\mathfrak{B}} \supfun{f}X}{X\in\up\mathcal{X}}$ is a generalized filter base.
To show it is enough to show that $\setcond{\supfun{f}X}{X\in\up\mathcal{X}}$ is a generalized filter base.
But this easily follows from proposition~\bookref{pfcd-mono} and~\bookref{filt-is-sep}.

Similarly $\mathcal{X} \nasymp \supfun{\uparrow f^{-1}} \mathcal{Y} \Leftrightarrow
\forall X\in\up\mathcal{X}, Y\in\up\mathcal{Y}: X\suprel{f}Y$.
Thus $\mathcal{Y} \nasymp \supfun{\uparrow f} \mathcal{X} \Leftrightarrow \mathcal{X} \nasymp \supfun{\uparrow f^{-1}} \mathcal{Y}$.
\end{proof}

\begin{prop}
The above defined~$\uparrow$ is an injection.
\end{prop}

\begin{proof}
$\supfun{\uparrow f} X = \bigsqcap^{\mathfrak{B}}_{X'\in\up X} \supfun{f}X' = \min_{X'\in\up X} \supfun{f}X' = \supfun{f}X$.
So $\supfun{f}$ is determined by $\supfun{\uparrow f}$. Likewise $\supfun{f^{-1}}$ is determined by $\supfun{\uparrow f^{-1}}$.
\end{proof}

\begin{conjecture}
(Non generalizing of theorem~\bookref{pf-rel})
Pointfree funcoids~$f$ between some: a. atomistic but non-complete; b. complete but non-atomistic boolean lattices~$\mathfrak{Z}_0$ and~$\mathfrak{Z}_1$
do not bijectively correspond to morphisms~$p\in\mathbf{Rel}(\atoms\mathfrak{Z}_0,\atoms\mathfrak{Z}_1)$ by the formulas:
\begin{gather*}
\supfun{f}X = \bigsqcup\rsupfun{p}\atoms X, \quad
\supfun{f^{-1}}Y = \bigsqcup\rsupfun{p^{-1}}\atoms Y; \\
(x,y)\in\GR p \Leftrightarrow y\in\atoms\supfun{f}x \Leftrightarrow x\in\atoms\supfun{f^{-1}}y.
\end{gather*}
\end{conjecture}


The homomorphic circuit for $\LT_{\F_\fieldcard}(x,y)$ is presented in Algorithm~\ref{alg:basic_less_than_circuit}.
Unlike the prior works (\todo{cite}) that evaluate this circuit as a multivariate polynomial, we exploit its representation in~(\ref{eq:less_than_function}) to parallelize computations in the SIMD manner.
\begin{algorithm}[t]
  \KwIn{
  $\ct_x$ -- a ciphertext encrypting $x \in \F_\fieldcard$ in the first SIMD slot and $0$ in other slots,
  $\ct_y$ -- a ciphertext encrypting $y \in \F_\fieldcard$ in the first SIMD slot and $0$ in other slots,
  $\S = \{a_0,a_1,\dots,a_{\fieldcard-1}\}$ -- a complete set of representatives of $\F_\fieldcard$.
  }
  \KwOut{$\ct$ -- a ciphertext encrypting $1$ in the first SIMD slot if $x < y$, otherwise $0$. Other slots contain $0$.}
  $\ct_1 \leftarrow \Replicate(\ct_x, \fieldcard - 1)$//\todo{Define replicate}\\
  $\ct_2 \leftarrow \Replicate(\ct_y, \fieldcard - 1)$\\
  $\pt_1 \leftarrow \pt(a_0, a_1, \dots, a_{\fieldcard-2})$//\todo{define this operation}\\
  $\pt_2 \leftarrow \pt(a_1, a_2, \dots, a_{\fieldcard-1})$\\
  $\ct_1 \leftarrow \ct_1 - \pt_1$//\todo{define operations between ciphertexts and plaintexts}\\
  $\ct_2 \leftarrow \ct_2 - \pt_2$\\
  $\ct_1 \leftarrow \ct_1^{\fieldcard-1}$//$\princhar_\fieldcard(x-a)$, \todo{define this operation}\\
  $\ct_2 \leftarrow \ct_2^{\fieldcard-1}$//$\princhar_\fieldcard(y-b)$\\
  $\ct_1 \leftarrow 1 - \ct_1$// define operations between constants and ciphertexts\\
  $\ct_2 \leftarrow 1 - \ct_2$\\
  $k \leftarrow 1$// compute all running sums $\sum_{b \in \S, a < b} (1-\princhar_\fieldcard(x - b))$ \\
  \While{$k < \fieldcard-1$}{
    $\ct_{tmp} \leftarrow \Shift(\ct_2, k)$//\todo{define shift}\\
    $\ct_2 \leftarrow \ct_2 + \ct_{tmp}$\\
    $k \leftarrow 2k$\\
  }
  $\ct \leftarrow \ct_1 \cdot \ct_2$\\
  $k \leftarrow 1$\\
  \While{$k < \fieldcard-1$}{
    $\ct_{tmp} \leftarrow \Shift(\ct, k)$\\
    $\ct \leftarrow \ct + \ct_{tmp}$\\
    $k \leftarrow 2k$\\
  }
  $\ct \leftarrow \Select(\ct, \{1\})$//\todo{define select}\\
  \textbf{Return} $\ct$.
  \caption{Homomorphic circuit of $\LT_{\F_\fieldcard}$.}\label{alg:basic_less_than_circuit}
\end{algorithm}
\todo{Make a separate algorithm for running sums (while circuit above)}
\todo{Write down the complexity of Algorithm~\ref{alg:basic_less_than_circuit}, compare with prior works}

Here are potential cyclotomic polynomials to use for a failure probability smaller $\varepsilon < 2^{-32}$.

\begin{table}
  \setlength{\tabcolsep}{1em}
  \centering
  \begin{tabular}{||ccc||cccccc||}
    \hline
    $~m~$ & $~n~$ & $~\delta_\mathcal{R}~$ & $~p~$ & $~d~$ & depth & $~\ell~$ & $~s~$ & $~\varepsilon~$ \\
    \hline
    $22,383$ & $14,904$ & $5n$ & $5$  & $18$ & $8$ & $828$  & $1$ &  $2^{-41.7}$ \\
    $25,623$ & $15,552$ & $118n$ & $2$ & $36$ & $7$ & $432$ & $2$ & $2^{-36.0}$ \\
    $31,132$ & $15,120$ & $85n$ & $7$ & $12$ & $8$ & $1,260$ & $2$ & $2^{-33.6}$ \\
    $31,726$ & $15,288$ & $57n$ & $3$ & $28$ & $7$ & $546$ & $1$ & $2^{-44.3}$ \\
    $35,552$ & $16,000$ & $21n$ & $17$ & $10$ & $9$ & $1,600$ & $3$ & $2^{-40.8}$ \\
    \hline
    $31,697$ & $30,576$ & $57n$ & $3$ & $28$ & $7$ & $1,092$ & $1$ & $2^{-44.3}$ \\
    $48,771$ & $32,508$ & $5n$ & $2$ & $42$ & $7$ & $774$ & $1$ & $2^{-42.0}$ \\
    $57,368$ & $28,000$ & $141n$ & $17$ & $10$ & $9$ & $2,800$ & $3$ & $2^{-40.8}$ \\
    $72,400$ & $28,800$ & $9n$ & $7$ & $12$ & $8$ & $2,400$ & $3$ & $2^{-33.6}$ \\
    $93,006$ & $30,996$ & $5n$ & $5$ & $18$ & $8$ & $1,722$ & $1$ & $2^{-41.7}$ \\
    \hline

  \end{tabular}
  \caption{Potential parameters}
  \label{tab:params}
\end{table}

\begin{itemize}
\item $m$: cyclotomic order;
\item $n$: degree of the cyclotomic;
\item $\delta_\mathcal{R}$: expansion factor (upper-bound);
\item $p$: plaintext modulus;
\item $d$: degree of the factors of $\phi_m$ modulo $p$;
\item depth: $\lceil \log_2(p-1) \rceil + \lceil \log_2(d)\rceil + 1$;
\item $\ell$: number of factors of of $\phi_m$ modulo $p$;
\item $s$: number of generators for $(\Z/m\Z)^\times/<p>$;
\item $\varepsilon$: approximative probability of failure for one equality check.
\end{itemize}

\remove{
\subsection{Min/Max function on vectors}

  \begin{align*}
    \min_\S(\vx,\vy) = \vx \cdot \LT_\S(\vx,\vy) + \vy \cdot (1 - \LT_\S(\vx,\vy)).
  \end{align*}

  \begin{align*}
    \LT_{\F_\fieldcard}(\vx, \vy) = \sum_{i=0}^{\ell-2} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j}) + \LT_{\F_\fieldcard}(x_{\ell-1}, y_{\ell-1}).
  \end{align*}

  \begin{align*}
    (x-y) \cdot \EQ_{\F_p}(x,y) = 0
  \end{align*}

  \begin{align*}
    \min_\S(\vx,\vy)_k &= x_k \cdot \LT_\S(\vx,\vy) + y_k \cdot (1 - \LT_\S(\vx,\vy)) \\
    &= y_k + (x_k - y_k) \cdot \LT_\S(\vx,\vy)) \\
    &= y_k + (x_k - y_k) \cdot \left(\sum_{i=0}^{\ell-1} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j})\right) \\
    &= y_k + (x_k - y_k) \cdot \left(\sum_{i=0}^{k-1} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j})\right) \\
    &+ (x_k - y_k) \cdot \left(\sum_{i=k}^{\ell-1} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j})\right) \\
    &= y_k + (x_k - y_k) \cdot \left(\sum_{i=k}^{\ell-1} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j})\right)
  \end{align*}
  }


\chapter{Minimum Constraints} \label{ch:MinCon}

When running the toolkit in network mode, the positions of receivers and satellites may both be estimated simultaneously. This presents a complication in that the absolute positions of all elements may be unconstrained - the model of the system would be completely consistent if every element of the network (receivers and satellites) were on the opposite side of the planet! For the results of such processing to be of value, the system needs to be referenced to a standard reference frame.

One method of ensuring the system is referenced to a suitable reference frame is to constrain receiver positions to their nominal position in the reference frame. Constraining 3 receivers is sufficient to ensure the system is well defined, but this gives select receivers precedence over all others - a movement of one of these receivers will instead show up as a movement of every other reciever on the planet.

An alternative method may be to weakly constrain all receivers to their nominal positions. This removes the priority effect of choosing 3 receivers, but will also apply a small restoring bias to the estimated position of the receivers.

Minimum constrains is a method of referring a system of estimates to a standard reference frame without unduly prioritising any receiver, or biasing the measurements.

\section{Computation}

To compute a minimally constrained system, the deviations of all receivers from their nominal positions are used as pseudo-observations in a filter to estimate a transformation between reference frames.

The filter estimates a rigid transformation comprising of 3d rotation and translation components, which when applied produces a least-squares solution of the errors of all desired receivers.

The estimated transformation is then applied to the network solution, transforming both the estimated position states, as well as the covariances associated with them.

\section{Usage} \label{MinConConfig}

\begin{lstlisting}[language=yaml,caption=Minimum Constraints Configuration]
minimum_constraints:

    estimate:
        translation:    true
        rotation:       true
        #scale:          false   #not yet implemented

    station_default_noise: -1        #constrain none by default (negative numbers are not constrained)
    #station_default_noise: +1       #constrain all by default

    #station_noise:
    #    ALIC: 0.001     #constrain strongly
    #    AGGO: 1
    #    BOAV: 100       #constrain weakly
\end{lstlisting}

If minumum constraints is enabled, the transformation will be applied after the completion of all forward processing, and configured according to the yaml file.

\subsection*{estimate:}

Booleans to enable the modelling of the transformation operations.

\subsection*{station\_noise, station\_default\_noise:}

These parameters allow the different stations in the solution to be weighted according to their priority.

The station default noise is applied to all stations unless they are specifically overridden using a station\_noise entry.

High noise values indicate that the station should only be weakly constrained to its a-priori position, while low values indicate they should be weighted more strongly. Only the relative weighting between stations is important.

Stations may have zero weighting applied by assiging a negative value to the station\_noise override for that station.


\section{Data Structures}
  \subsection{Fenwick Tree}
    \code{data-structures/fenwick.cpp}
  \subsection{Leq Counter}
    \subsubsection{Leq Counter Array}
      \code{data-structures/leq_counter_ar.cpp}
    \subsubsection{Leq Counter Map}
      \code{data-structures/leq_counter_map.cpp}
  \subsection{Misof Tree}
    A simple tree data structure for inserting, erasing, and querying the nth largest element.
    \code{data-structures/misof_tree.cpp}
  \subsection{Mo's Algorithm}
    \code{data-structures/mo.cpp}
  \subsection{Ordered Statistics Tree}
    \code{data-structures/ordered_statistics_tree.cpp}
  \subsection{Segment Tree}
    \subsubsectionBlack{Recursive, Point-update Segment Tree}
    \subsubsection{Iterative, Point-update Segment Tree}
      \code{data-structures/segtree_iter_PU_RQ.cpp}
    \subsubsection{Pointer-based, Range-update Segment Tree}
      \code{data-structures/segtree_rec_RU_RQ.cpp}
    \subsubsection{Array-based, Range-update Segment Tree -}
      \code{data-structures/segtree_array_lazy.cpp}
    \subsubsection{2D Segment Tree}
      \code{data-structures/segtree_2d.cpp}
    \subsubsection{Persistent Segment Tree}
      \code{data-structures/segtree_persistent_rec.cpp}
  \subsection{Sparse Table}
    \subsubsection{1D Sparse table}
      \code{data-structures/sparse.cpp}
    \subsubsectionRed{2D Sparse Table}
      \code{data-structures/sparse_2d.cpp}
  \subsection{Splay Tree}
    \code{data-structures/splay.cpp}
  \subsection{Treap}
    \subsubsection{Implicit Treap}
      \code{data-structures/treap_implicit.cpp}
    \subsubsectionBlack{Persistent Treap}
  \subsection{Union Find}
    \code{data-structures/union_find.cpp}
  \subsection{Unique Counter}
    \code{data-structures/unique_counter.cpp}


\chapter{Linear transformations in \texorpdfstring{$\R^n$}{Rn}}
\label{cha:linear-transformation}


\section{Introduction}

Correlation clustering~\cite{Bansal-2002} also known as the multicut problem~\cite{chopra_1993_mp}
is a basic primitive in computer vision~\cite{andres_2011_iccv,kroeger_2012_eccv,yarkony_2012_eccv,alush_2013_simbad} and data mining~\cite{Chierichetti-2014,Arasu-2009,Sadikov-2010,Chen-2012}. Its value is, firstly, that it accommodates both positive / attractive \emph{and} negative / repulsive edge weights. Importantly, this allows doing justice to evidence in the data that two nodes or pixels do \emph{not} wish to end up in the same cluster or segment. This is in contrast to the submodular potentials so popularized by the graph cut algorithm, which only allow two nodes to be attracted to each other, or at most be agnostic about membership in the same cluster. Secondly, the algorithm does not require a specification of the number of clusters. This is in contrast to methods such as normalized cut \cite{} that can only accommodate attractive interactions and hence need the number of clusters to be specified.

\paragraph{Contribution.} The evident usefulness of correlation clustering and its clean and compact formulation in terms of an optimization problem, together with its unfortunate NP-hardness, are an invitation to develop fast approximate solvers. The basic idea of the move making algorithm proposed here is to maintain, at all times, a best current partitioning; and to iteratively improve it (as we show, monotonously) by considering diverse and cheaply generated proposal partitionings. Any two nodes that are in one cluster in both the current and the proposal partitioning are contracted. Edges to contracted nodes are equally combined and reweighted, and the correlation clustering problem is then solved on this reduced graph. We offer a polyhedral characterization of this strategy, and evaluate it in conjunction with two versatile proposal generators.   We conduct experiments on a broad range of data sets ranging from 2D and 3D segmentation problems to clustering in signed social networks. The results suggest that this simple move making algorithm is the fastest technique known today, reaching close to globally optimal solutions in a tenth or a hundredth of the time required by the most efficient exact solvers.

\paragraph{Related Work.}
A natural approach is to solve the integer linear programming problem directly. To this end, efficient separation procedures have been found \cite{} that allow to iteratively augment the set of constraints until a valid partitioning is found.
Alternatively, it is possible to relax the integrality constraints of the integer linear programming formulation. Such an outer relaxation can be iteratively tightened. However, intermediate solutions are fractional and so rounding is required to obtain a valid partitioning. The latter approach works best on planar \cite{yarkony_2012_eccv} or almost planar \cite{yarkony-andres-2013} graphs.

Another line of work maintains valid partitionings throughout, either by using a cluster representation in terms of labels \cite{bagon_2011_arxiv} or in terms of cut edges \cite{kroeger_2014_cvpr}. The former suffers \cite{beier} from the degeneracy of a label presentation \cite{kappes}, while the latter is highly efficient only for planar graphs. Working on contracted nodes has previously been explored in \cite{kroeger_2013_miccai}.

Finally, there are heuristic methods such as ...

\section{Notation and Problem Formulation}\label{sec:problem_formulation}
Let $G=(V,E, w)$ be a weighted graph of nodes $V$ and edges $E$.
%
The function $w : E \rightarrow \mathbb{R}$ assigns a weight to each edge.
A positive weight expresses the desire that two adjacent nodes should
be merged, whereas a negative weight indicates
that these nodes should be separated into two different regions.
%
A \emph{subgraph} $G_A = \{A, E_A, w\}$ consists
of nodes $A \subseteq V$ and edges $E_A := E\cap (A\times A)$.
%
A segmentation of the graph $G$ can by either given by an
node labeling $l \in \mathbb{N}^{|V|}$
or an edge labeling $y \in\{0,1\}^{|E|}$.
An edge labeling is only consistent if it contains no dangling edges~\cite{kappes_2013_arxiv}.
We denote the set of all consistent edge labelings by $P(G)\subset\{0,1\}^{|E|}$.
The convex hull of this set is known as the \emph{multicut polytope} $MC(G) = \textrm{conv}(P(G))$.

%$\rho_y : P(G) \to P(G_y)$
%$\rho_y^{-1} : P(G_y) \to P(G)$

% \begin{itemize}
%   \item Multicut in computer vision, applications, sparse segmentation -> IMPORTANT PROBLEM
%   \item Problem: Existing Methods does not scale, even CGC. - Large scale 3d problems
%   \item Contribution: Fast scalable method using novel fusion moves for correlation clustering
% \end{itemize}

% Def: Graph, weighted graph, cut, multicut

Given a weighted graph $G=(V,E,w)$ we consider the problem of segmenting $G$ such that the costs
of the edges between distinct segments is minimized. This can be formulated in the node domain
by assigning each node $v$ a label $l_v \in \mathbb{N}$
\begin{align}
  l^* &= \argmin_{L \in \mathbb{N}^{|V|}} \sum_{ (i,j) \in E } w_{ij} \cdot [l_{i} \neq l_{j}], \label{eq:nodeproblem}
\end{align}  % y_{ij}^* &=& [l_{u} \neq l_{v}]
or in the edge domain, by label each edge $e$ as cut $y_e=1$ or uncut $y_e=0$
\begin{align}
  y^* &= \argmin_{y \in P(G)} \sum_{ (i,j) \in E } w_{ij} \cdot y_{ij} \label{eq:edgeproblem}.%\\
\end{align}
As shown in~\cite{kappes_2013_arxiv} both problems are equivalent, but formulation \ref{eq:nodeproblem}
suffers from ambiguities in the formulation~\cite{kappes_2011_emmcvpr}.

% The exist an surjective mapping from a node-label $l$ to edge-labeling $y$ and
% a bijective mapping from a partitioning of $V$ to vertices of the multicut polytope $MC$.
% Consequently,
% (i) problems \ref{eq:nodeproblem} and \ref{eq:edgeproblem} are equivalent
% and (ii) the node-labeling is not unique for a given partitioning and introduce some
% ambiguities.

% \subsubsection{Multicut Objective}

% The multicut / correlation clustering objective
% can be formulated in different ways.

% \paragraph{Edge Indicator Variables:}
% \begin{center}
%     \begin{eqnarray}
%         y^* &=& \argmin_{y} \sum_{ e_{ij} \in E } w_{ij} \cdot y_{ij} \\
%         s.t.:& & y \in \textit{Multicut Polytope} \nonumber
%     \end{eqnarray}
% \end{center}

% \paragraph{Fully Connected Graph:}
% \begin{center}
%     \begin{eqnarray}
%         y^*   & = & \argmin_{y} \sum_{ i<j \in V } w_{ij} \cdot y_{ij} \\
%         s.t.: &  & y_{ij} + y_{jk} < y_{i,k} \quad \forall i, j, k   \nonumber
%     \end{eqnarray}
% \end{center}

% \paragraph{Node Coloring:}
% \begin{center}
%     \begin{eqnarray}
%         l^* &=& \argmin_{L} \sum_{ e_{ij} \in E } w_{ij} \cdot [l_{u} \neq l_{v}] \\
%         y_{ij}^* &=& [l_{u} \neq l_{v}]
%     \end{eqnarray}
% \end{center}

\input{inputs/fig_notation.tex}


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

%\usepackage{cite}
%\usepackage{wrapfig}
%\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\newcommand{\e}{\epsilon}
\newcommand{\dl}{\delta}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\vect}[1]{\underline{#1}}
\newcommand{\uvect}[1]{\hat{#1}}
\newcommand{\1}{\vect{1}}
\newcommand{\grad}{\nabla}

%By changing \underline to \bold or \hat, the vector notation can be changed accordingly

\title{Lecture 10: Hydrostatics}
\author{}
\begin{document}
\maketitle

\section*{Overview}
The key objectives are to use the hydrostatic balance equation $\rho \vect F = \grad p$ to obtain the equilibrium shape of the free surface under a given body force $\vect F$ and describe the buoyant force on a submerged body.

\section{Potential}
We know that total body force on a small volume of fluid can be written as $\int\rho \vect F dV$ and the total surface force (in hydrostatic equilibrium) is $-\int p \vect n dA$. This surface integral can be transformed to volume integral using divergence theorem for a scalar field. It gives $-\int p \vect n dA = -\int \grad p dV$. Balancing the two terms gives
\begin{align*}
\int&(\rho \vect F - \grad p) dV =0\\
\Rightarrow& \rho \vect F = \grad p
\end{align*}
which is the governing equation for hydrostatics. Moreover, if the body forces are conservative, then the force $\vect F$ can be written as the gradient of a scalar potential as $\vect F= -\grad \Psi$. Therefore, the equation becomes:
\begin{align*}
\rho -\grad \Psi &= \grad p \\
\end{align*}
Taking curl of this equation gives
\begin{align*}
\grad \rho \wedge \grad \Psi &= 0
\end{align*}
which implies that, for hydrostatic balance, the constant pressure surfaces must be parallel to the constant potential surfaces. This is a necessary and sufficient condition for hydrostatic equilibrium. For further analysis, we need to know how $\rho$ varies with $\vect x$. But if the density is constant, the solution of $\rho \grad \Psi = \grad p$ is simply $p=p_0 - \rho \Psi$

As an example of equipotential surfaces, we can consider a vessel rotating with $\Omega$. The fluid in the vessel is rotating at the same rate and we observe the system in the rotating frame. Then force per unit mass $F$ is given by
\begin{align*}
F &= \vect g - \Omega^2 (x^2+y^2)^{1/2}\\
\Rightarrow \Psi &= gz - \frac{1}{2}\Omega^2(x^2+y^2)
\end{align*}
If the radius of the beaker is $R$, then we can scale the coordinates with $R$ and non-dimensionalize the above equations as
\begin{align*}
\Psi &= z - \frac{\Omega^2 R}{2g}(x^2+y^2)
\end{align*}

For a fixed value of $\Psi$ we get different paraboloids. All parallel to each other. These are the equipotential surfaces and hence also give us the shape of the free surface because the free surface has a constant pressure and hence a constant potential everywhere on it.

\section{Force on a submerged particle}

Let a particle of volume $V_p$ be submerged completely in a fluid of constant density $\rho_0$. If gravity is the only force, then $\vect F = \vect g$. Under these assumptions then, we have

\begin{align*}
F_B &= -\int_{V_p} p \vect n dA \\
&= -\int \grad p dV \\
&= -\int \rho \vect F dV \\
&= -\rho_0 \int -\vect g dV \\
&= \rho_0 \vect g V_p
\end{align*}
And so the force of buoyancy is equal to the weight of the liquid displaced. Note that we started this derivation with an integration of forces on the solid particle but in the third step we switched to an equivalent fluid blob, thus bringing in the density of fluid instead of the density of the object. The second step required us to integrate the pressure gradient over the volume of the particle. Therefore, we replaced the particle with ambient fluid and integrated the pressure gradient over the required volume.

\section{Continuous density stratification}

If density of the fluid varies over the length of the submerged body, then the density at the centroid of the body gives us required the buoyant force on the body. To show this, consider a fluid with density variation as
\begin{align*}
\rho(\vect x) = \rho(\vect x_0) + D\rho \uvect{g} \cdot (\vect x - \vect x_0)
\end{align*}

Here $D\rho$ ($> 0$) is the density gradient. It must be in the direction of pressure gradient (which is gravity here, denoted by the unit vector $\uvect g$), otherwise there will be a flow due to the baroclinic source of vorticity ($\grad p \wedge \grad \rho$ must be zero).

\begin{align*}
F_B &= -\int_{V_p}\rho \vect{F}dV \\
&= -\int_{V_p}\rho(\vect{x}) \vect{g} dV \\
&= -\vect{g}\int_{V_p}\rho(\vect x_0) + D\rho \uvect{g} \cdot (\vect x - \vect x_0) dV \\
&= -\vect{g}(V_p\rho(\vect x_0) + D\rho \uvect{g} (\int_{V_p}\vect x - \vect x_0V_p) \\
&= -\vect{g}(V_p\rho(\vect x_0) + D\rho \uvect{g}V_p (\big(\frac{1}{V_p}\int_{V_p}\vect x dV\big) - \vect x_0) \\
&= -\vect{g}(V_p\rho(\vect x_0) + D\rho \uvect{g}V_p (\vect x_c - \vect x_0) \\
&= -\vect{g}V_p(\rho(\vect x_0) + D\rho \uvect{g} (\vect x_c - \vect x_0) \\
&= -\vect{g}V_p \rho(\vect x_c) \\
\end{align*}
And so only the density at the centroid needs to be used while evaluating the buoyant force on a body submerged in a linearly stratified medium.

\section{Centrifugal buoyancy}
Under the action of centrifugal forces, the heavier fluids get pushed outwards and the lighter fluids get pulled towards the axis of rotation. This can be seen from the final expression for force due to centrifugal buoyancy
\begin{align*}
F_B = \Omega^2 V_p (\rho_p - \rho_0)r
\end{align*}

If density of the particle $\rho_p$ is greater than the medium density $\rho_0$, then it is centrifuged out, otherwise it gets pulled inwards. This can be used in experiments to visualize vortices.

\section{Dynamics of approach to equilibrium}

Let there be a fluid parcel of mass $m$ and density $\rho_1$ in a medium of density $\rho_2$ and a damping coefficient of $C$. Then force balance can be written as
\begin{align*}
& m\frac{d^2 \vect x_c}{t^2} = v_p \rho_1(\vect x_c)g - v_p \rho_2(\vect x_c)g - C\frac{d \vect x_c}{dt}
\end{align*}
If we consider only vertical motions, then after some rearrangement, this can be written as
\begin{align*}
V_p\rho_1\frac{d^2 z^*}{dt^2} + C\frac{d z^*}{dt} + g V_p D\rho_2 z^* &= 0
\end{align*}
where $z^*= z - z_c$ and $D\rho_2$ is the density gradient in the fluid medium. Comparing it with the standard equation for damped oscillations, $m\ddot{x} + c\dot{x} + \omega^2 x = 0$, we get the natural frequency of oscillations of fluid parcel as $\omega = (\frac{gD\rho_2}{\rho_1})^{1/2}$. The approach can be defined as underdamped or overdamped if the sign of $C^2-4(gV_pD\rho_2)(v_p\rho_1)$ is negative or positive respectively (this can be seen by assuming an exponential solution $e^{mz}$ and substituting in the differential equation - the condition for real roots translates to condition for overdamped oscillations).

If the system is overdamped with a large damping coefficient $C\to\infty$, then we neglect the second order term in the equation and just consider the equation
\begin{align*}
C\frac{d z^*}{dt} + g V_p D\rho_2 z^* &= 0
\end{align*}

which has an exponentially decaying solution $z^* \propto e^{-t/\tau}$ where $\tau = \frac{g v_p D\rho_2}{C}$. Therefore, we get the overdamped solution with the appropriate time-scale.

\section{Appendix}

\subsection{Derivation for centrifugal buoyancy}

\end{document}


\chapter{Conclusion}
\label{chap:90conclusion}

\noindent
Finally, we conclude the thesis by summarizing its results
and by giving an outlook on possible future work.
In particular, we highlight key contributions of the thesis to research,
give recommendations for future applications of the presented method, and
state possible downsides and limitations.

\vspace*{-0.5em}

\paragraph{Summary of the thesis}

The contribution of this thesis consisted of two major parts.
In the first part,
hierarchical B-splines on sparse grids were comprehensively presented
and embedded in a sparse grid framework with general
tensor product basis functions.
The advantage of this approach was that the framework could be reused
for different hierarchical bases
(as for the various spline bases derived in this thesis)
and that it clarified which properties only held for the
classical piecewise linear bases and not for other tensor product bases.
We saw that standard hierarchical B-splines suffer from
approximation issues near the boundary, and
we resolved these issues by incorporating not-a-knot boundary conditions
into the hierarchical B-spline basis.
In the further course of the thesis,
the focus was put on the algorithmic implications of the novel bases,
taking the hierarchization problem as an example.
We looked at requirements that had to be satisfied by grids and bases
to enable efficient hierarchization algorithms
such as breadth-first search and unidirectional principle,
for which we gave clear formulations and formal correctness proofs.
As a result, a whole ``zoo'' of hierarchical (B-)spline functions
has been derived in this thesis.
The main types were
standard hierarchical B-splines,
modified hierarchical B-splines,
hierarchical not-a-knot B-splines,
hierarchical fundamental splines, and
hierarchical weakly fundamental splines
(where the first two are not novel).
Modified, not-a-knot, and (weakly) fundamental splines could be combined
almost arbitrarily to tailor the ansatz functions to suit one's specific needs.

\pagebreak

The second, more practical part of the thesis was dedicated to transferring
the newly gained theoretical knowledge to
academic and real-life application test cases.
We verified that only with the new hierarchical not-a-knot conditions,
one is able to obtain the best possible order of convergence
$\landauO{\ms{n}^{p+1}}$ for interpolation
(B-spline degree $p$, fixed dimensionality $d$).
Using the Novak--Ritter criterion,
which was specifically designed for optimization,
we were able to achieve optimization gaps
that were for some test functions up to six orders of magnitude smaller
for cubic B-splines than for standard piecewise linear functions.
We transferred the Novak--Ritter criterion to uncertainty quantification
and obtained similarly strong results for the
propagation of fuzzy uncertainties with the fuzzy extension principle.
Furthermore, we successfully showed the suitability of hierarchical B-splines
for three real-world applications,
which are summarized in \cref{tbl:applicationSummary}.
\begin{table}
  \setnumberoftableheaderrows{1}%
  \begin{tabular}{%
    >{\kern\tabcolsep}=l<{\kern5mm}+l+l+l<{\kern\tabcolsep}%
  }
    \toprulec
    \headerrow
    Category&                   Topology opt.&      Biomechanics&      Finance\\
    \midrulec
    Interpolated quantities&    Elasticity tensors& Muscle forces&     Value functions\\
    SG dimensionality&          5&                  2&                 5\\
    \#Optimization variables&   \num{40000}&        2&                 11\\
    Time per evaluation&        \SI{30}{\second}&   \SI{30}{\minute}&  ---\\
    \#Eval. per opt. iteration& \num{8000}&         4&                 150\\
    Objective function type&    Non-linear&         Linear/non-linear& Non-linear\\
    Constraint function type&   Non-linear&         Non-linear/---&    Linear\\
    Optimization method&        SQP&                Augm. Lagrangian&  SQP\\
    \bottomrulec
  \end{tabular}
  \caption[%
    Summary of characteristics of the applications%
  ]{%
    Summary of characteristics of the applications presented in this thesis.
    The given values are rough example values that
    represent possible application test cases.%
  }%
  \label{tbl:applicationSummary}%
\end{table}%
First, by interpolating Cholesky factors of elasticity tensors,
we accomplished to efficiently solve
topology optimization problems in three spatial dimensions
with complex micro-cell structures.
Second, in the biomechanical application,
we dramatically reduced the computational time to solve
test scenarios by up to \SI{99}{\percent} by using
sparse grid surrogates with B-splines instead of the
exact continuum-mechanical model.
Third, we were able to solve dynamic portfolio choice problems
with five state variables and eleven policy variables
with unprecedented precision, as one could only speculate
how the solution looked like with state-of-the-art methods.
In all of these applications, the advantages of B-splines were made clear
by comparing the results to the classical piecewise linear basis.
The implementation of hierarchical B-splines of sparse grids is
publicly available as part of the sparse grid toolbox \sgpp
under a free and open-source license.%
\footnote{%
  \url{http://sgpp.sparsegrids.org/}%
}

\vspace*{\fill}
\pagebreak

\paragraph{Recommendations (advantages and disadvantages)}

Despite its broad applicability,
the presented method of B-splines on sparse grids is of course
not suited for all possible scenarios.
One must be able to sample the objective function at arbitrary
locations in some hyper-rectangle in order to use sparse grids;
a prescribed point cloud of scattered data does not suffice.
Moreover, the problem should not have more than ten dimensions,
since convergence notably slows down as the dimensionality grows,
although spatially adaptive approaches might still be feasible for
higher dimensionalities \cite{Pflueger10Spatially}.
In addition, the objective function should be ``as smooth as possible''
in order to benefit from higher-order B-splines.
This means ``continuous'' at the very least,
but twice continuous differentiability is more desirable.
The general rule is that the objective function should be
at least as smooth as the employed basis functions in order to obtain
optimal convergence results.
The concrete choice of basis (general type and degree) depends
on the application:
Not-a-knot B-splines are well-suited for objective functions with
dominating near-polynomial parts.
Fundamental splines may be used to accelerate the process of
hierarchization by enabling breadth-first search in quadratic time.
With weakly fundamental splines, this can be further reduced to
linear time using the unidirectional principle.
However, the additional grid points that have to be inserted
have to be taken into account as well.
The rule of thumb is that the more spatially adaptive a sparse grid is
(i.e., only few high-level grid points),
the more points have to be inserted.
In general, it does not hurt to try the different available
B-spline types and degrees,
since most function values can simply be reused
once the objective function has been sampled.

\vspace*{\fill}

\paragraph{Outlook and future work}

Finally, we briefly give suggestions for possible future work.
A major topic of interest is that of refinement criteria and adaptivity.
Besides the Novak--Ritter criterion,
there are other refinement criteria that are tailored to optimization
such as simultaneous optimistic optimization \cite{Wang14Bayesian}.
In addition, nested methods for hierarchical optimization could
use multiple interpolants with different resolutions
on different grids \cite{Delbos14Global}.
Criteria that directly incorporate constraints would improve
results in constrained optimization settings.
With respect to adaptivity,
there is also much work left to do.
This thesis focused on spatial adaptivity for its applications,
but there are interesting applications
that greatly benefit from dimensional adaptivity,
for example plasma physics \cite{Pflueger14EXAHD}.
Another key task would be the introduction of
$h$-$p$-adaptivity to B-splines on sparse grids,
which would greatly enhance the applicability of B-splines in
non-smooth scenarios.
As a simple special case,
one could investigate different B-spline degrees in different dimensions.
However, true $h$-$p$-adaptivity would allow to locally choose
both the spatial resolution $h$ and the B-spline degree $p$,
adapting them according to the local smoothness of the function.

\pagebreak

With regard to the application side, there are also quite a few
possibilities for future work.
The sparse grids in the biomechanical application
we considered in this thesis were only two-dimensional.
This is not in the range of dimensions in which sparse grids
demonstrate their full strength,
although the two-dimensional surrogates were already able to drastically
reduce the required computation time compared to full grids.
Currently, an extended model with five muscles and therefore
five-dimensional sparse grids is being considered
(see \cref{fig:upperLimb5D}).
\begin{SCfigure}
  \begin{tikzpicture}
    \node[anchor=south west] at (0mm,0mm) {%
      \includegraphics[height=80mm]{upperLimb5D}%
    };
    \node[anchor=west] (humerus)    at (0mm,75mm)  {\small{}Humerus};
    \node[anchor=west] (radius)     at (0mm,20mm)  {\small{}Radius};
    \node[anchor=east] (ulna)       at (40mm,10mm) {\small{}Ulna};
    \node[anchor=east] (triceps)    at (73mm,52mm) {\small{}Triceps};
    \node[anchor=west] (biceps)     at (0mm,52mm)  {\small{}Biceps};
    \node[anchor=west] (brachialis) at (0mm,44mm)  {\small{}Brachialis};
    \node[anchor=west] (brachioradialis) at (0mm,36mm) {%
      \small{}Brachioradialis%
    };
    \node[anchor=east] (anonceus)   at (73mm,20mm) {\small{}Anonceus};
    \draw (humerus)         -- (39mm,75mm);
    \draw (radius)          -- ($(0mm,10mm)!(radius)!(20mm,10mm)$);
    \draw (ulna)            -- (20mm,10mm);
    \draw (triceps)         -- (48mm,52mm);
    \draw (biceps)          -- (33mm,52mm);
    \draw (brachialis)      -- (36mm,44mm);
    \draw (brachioradialis) -- (36mm,36mm);
    \draw (anonceus)        -- (38mm,20mm);
  \end{tikzpicture}%
  \caption[Extended model of the human upper limb with five muscles]{%
    Extended model of the human upper limb with
    the three bones humerus, radius, and ulna
    \emph{\textcolor[RGB]{191,162,118}{(light brown)}} and
    the five muscles
    triceps, biceps, brachialis, brachioradialis, and anonceus
    \emph{\textcolor[RGB]{150,58,46}{(red)}.}
    Each muscle has associated tendon
    \emph{\textcolor[RGB]{128,128,128}{(white)}}
    and muscle-tendon complexes
    \emph{\textcolor[RGB]{255,160,160}{(light red)}.}
    Biceps and brachioradialis have each been fixed with one and two bands
    \emph{\textcolor[RGB]{80,200,100}{(green)}}
    to simulate the effect of the missing skin.
    Without bands, the muscles would unnaturally raise from the bones.%
  }%
  \label{fig:upperLimb5D}%
\end{SCfigure}%
Here, it will be mandatory to employ spatial adaptivity
to cope with the increased dimensionality.
In the application of topology optimization,
more complicated micro-cell models and more complicated
settings could be studied.
For example, the widths of the diagonal macro-bars could be constrained
\cite{Allaire16Towards}.
The dynamic portfolio choice models in the financial application
were quite limited.
For example,
there was no inheritance motive (i.e., bequest),
the model did not contain the individual's regular income, and
the model did not account for savings for large necessary investments
(e.g., cars or houses), which seems unnecessarily unrealistic.
Finally, one could consider many other real-world optimization problems
or other application fields of B-splines on sparse grids,
for instance, data mining or uncertainty quantification.
If objective gradients are available besides function values,
it might be feasible to directly incorporate the gradients into
the interpolation scheme \cite{Baar15Gradient}.

% Chapter 8: model limitations, no inheritance,
% no saving money for housing, \dots

%\begin{itemize}
  %\item
  %steal from future work of Milestone Report,
  %steal from project description (JP program)

  %\item
  %other adaptivity criteria than Novak--Ritter
  %(e.g., for constrained optimization)

  %\item
  %dimensional adaptivity with the combination technique

  %\item
  %h-p-adaptivity,
  %special case: dimension-wise degree adaptivity

  %\item
  %data mining with the new bases

  %\item
  %uncertainty quantification with B-splines on sparse grids

  %\item
  %gradient-based approximation/interpolation methods
  %\cite{Baar15Gradient}

  %\item
  %biomechanical application: more complicated musculoskeletal model
  %with more parameters, have to exploit spatial adaptivity
  %(was proof of concept)

  %\item
  %topology optimization: more complicated micro-cell models,
  %more complicated constraints (bar widths like in \cite{Allaire16Towards})

  %\item
  %finance application: other models such as immediate annuity,
  %eliminate limitations

  %\item
  %other real-world optimization applications
%\end{itemize}

This extensive but by no means exhaustive list of possible future work
can be seen as an inspiration and starting point
for new and interesting applications of B-splines for sparse grids.

%I want to stay as close to the edge as I can without going over.
%Out on the edge you see all kinds of things you can't see from the center.

\cleardoublepage


\section{Error Calculation}
\label{sec:Error_Calculation}
This section contains the error calculation of the measured values. The systematic and the total error is calculated in this chapter. The error calculation is done for the fitted value of the Planck constant $h$ (see sections \ref{subsec:Direct_Measurement} to \ref{subsec:LED_Threshold_Voltage}).

% ----------------------------------------------------------------------------------
\subsection{Uncertainties}
\label{subsec:Uncertainties}
All conducted measurements in this experiment have uncertainties. Although, a 6$\,^{1}\!/_{2}$ digit multimeter and an oscilloscope was used to measure the values very precisely, there is still an uncertainty. This is partially due to the difficulty to move the cursors exactly to a peak. The systematic uncertainties are shown in table \ref{tab:equipment}.

% ----------------------------------------------------------------------------------
\subsection{Uncertainty of the Planck Constant $h$}
\label{subsec:Uncertainty_of_the_Planck_Constant}
First of all, equation \ref{eq:led_threshold} has to be rearranged as follows:

\begin{equation}
h\approx e\cdot U_{ph}\cdot\frac{\lambda}{c}
\label{eq:planck_constant}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			h & Planck constant in J$\cdot$s \\
			e & elementary charge in C \\
			U_{ph} & photoelectric voltage in V
		\end{conditions}
		\begin{conditions}
			\lambda & wave length in m \\
			c & speed of light in $\,^{\text{m}}\!/_{\text{s}}$
		\end{conditions}
	\end{center}
\end{multicols}

The total uncertainty $s_{h,\ \text{tot}}$ of the Planck constant $h$ is calculated with equation \ref{eq:total_uncertainty_planck_constant}:

\begin{equation}
s_{h,\ \text{tot}}=\sqrt{s_{h,\ \text{syst}}^2+s_{h,\ \text{stat}}^2}
\label{eq:total_uncertainty_planck_constant}
\end{equation}

with:

\begin{equation}
s_{h,\ \text{syst}}=\sqrt{\left(\frac{\partial h}{\partial U_{ph}}\Biggr|_{h}\cdot s_{U_{ph}}\right)^2 + \left(\frac{\partial h}{\partial \lambda}\Biggr|_{h}\cdot s_{\lambda}\right)^2}
\label{eq:syst_uncertainty_planck_constant}
\end{equation}

and:

\[
\frac{\partial h}{\partial U_{ph}}\Biggr|_{h}=\frac{e\cdot\lambda}{c} \qquad , \qquad \frac{\partial h}{\partial \lambda}\Biggr|_{h}=\frac{e\cdot U_{ph}}{c}
\]

where:
\begin{multicols}{2}
\begin{conditions}
	s_{h,\ \text{tot}} & total uncertainty of $h$ \\
	s_{h,\ \text{syst}} & systematic uncertainty of $h$ \\
	s_{h,\ \text{stat}} & statistical uncertainty of $h$ \\
	s_{U_{ph}} & uncertainty of $U_{ph}$ \\
	U_{ph} & photoelectric voltage in V
\end{conditions}
\begin{conditions}
	s_{\lambda} & uncertainty of $\lambda$ \\
	\lambda & wave length in m \\
	h & Planck constant \\
	e & elementary charge \\
	c & speed of light
\end{conditions}
\end{multicols}

\newpage
For the error calculation the following parameters were used:

\begin{multicols}{2}
	\begin{conditions}
		s_{U_{ph}} & 6 mV \\
		s_{U_{ph}}^\prime & 0.02 V \\
		U_{ph} & the respective photoelectric voltage \\
		e & $1.602 176 634\cdot 10^{-19}\ \si{C}$
	\end{conditions}
	\begin{conditions}
		s_{\lambda} & 0 \\
		s_{\lambda}^\prime & 1 nm \\
		\lambda & the respective wave length \\
		c & $299'792'458\ \,^{\text{m}}\!/_{\text{s}}$
	\end{conditions}
\end{multicols}

The values $s_{U_{ph}}$ and $s_{\lambda}$ are used for the photoelectric effect and the values $s_{U_{ph}}^\prime$ and $s_{\lambda}^\prime$ are used for the light-eimitting diode. This is due the fact, that different measurement devices were used (multimeter and oscilloscope). Furthermore the wave lengths of the mercury-vapor lamp were not measured (obtained online).

Table \ref{tab:Uncertainty_Planck_Constant} shows the statistical, the systematic and the total uncertainty. The systematic uncertainty was calculated by using equation \ref{eq:syst_uncertainty_planck_constant}. The statistical uncertainty was obtained from QtiPlot. The total uncertainty was calculated by using equation \ref{eq:total_uncertainty_planck_constant}. All calculations were done in MATLAB (see appendix \ref{sec:MATLAB_Error_Calculation}).

\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|l|c|c|c|}
		\cline{2-4}
		\multicolumn{1}{c|}{} & \textbf{Statistic} & \textbf{Systematic} & \textbf{Total} \\
		\multicolumn{1}{c|}{} & in J$\cdot$s & in J$\cdot$s & in J$\cdot$s \\
		\hline
		\textbf{Direct Measurement}\ $\boldsymbol{h}$ & $13.9\cdot10^{-36}$ & $1.2\cdot10^{-36}$ & $14.0\cdot10^{-36}$ \\
		\hline
		\textbf{Counter-Field Method}\ $\boldsymbol{h}$ & $51.2\cdot10^{-36}$ & $1.2\cdot10^{-36}$ & $51.2\cdot10^{-36}$ \\
		\hline
		\textbf{Light-Emitting Diode}\ $\boldsymbol{h}$ & $103.1\cdot10^{-36}$ & $5.2\cdot10^{-36}$ & $103.2\cdot10^{-36}$ \\
		\hline
	\end{tabular}
	\caption{The statistical uncertainty is from QtiPlot. Error propagation is used to calculate the systematic and the total uncertainty.}
	\label{tab:Uncertainty_Planck_Constant}
\end{table}


\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{multicol}
\usepackage{upquote}
\usepackage{url}
\newcommand{\class}{miniHive}
\newcommand{\term}{}
\newcommand{\examnum}{Milestone 2}
\usepackage{fancyvrb}
\newcommand{\examdate}{}
\usepackage{paralist}

\pagestyle{head}
\firstpageheader{}{}{}
\runningheader{\class}{\examnum\ - Page \thepage\ of \numpages}{}
\runningheadrule

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} r @{\extracolsep{6pt}} l}
\textbf{\class} & \\
\textbf{\term} &&\\
\textbf{\examnum} &&\\
\textbf{\examdate} &&\\
\end{tabular*}\\
\rule[2ex]{\textwidth}{2pt}

\section*{Selection Pushing in Relational Algebra}
In relational algebra, the following equivalencies apply (among others):

\begin{align}
    \sigma_{p_1\land p_2 \land \dots\land p_n}(R) \label{split}
    &=
    \sigma_{p_1}(\sigma_{p_2}(\dots (\sigma_{p_n}(R))\dots))
    \\
        \sigma_p( \sigma_q(R)) &= \sigma_q( \sigma_p(R)) \label{push_over_sel}
    \\
    \sigma_p(R_1 \times R_2)
    &=
    \sigma_p(R_1) \times R_2 \label{push_over_cross}
    \\
    \sigma_{R_1.A_1 = R_2.A_2}(R_1 \times R_2)
    &=
    R_1 \bowtie_{R_1.A_1 = R_2.A_1} R_2 \label{create_join}
\end{align}

\noindent
Some remarks:

\begin{compactitem}
    \item

Rule~(\ref{split}) states that a conjunction in a selection predicate may be broken into several nested selections.
At the same time, nested selections may be merged into a single selection with a conjunctive predicate.

\item
Rule~(\ref{push_over_sel}) states that nested selections may swap places.

\item
Rule~(\ref{push_over_cross}) states that a selection can be pushed down over a cross product,
if it only requires the attributes of one of the operands. In the rule as stated above,
we assume that predicate~$p$ only requires attributes from~$R_1$.
(We need to consult the data dictionary recording the name and attributes of each relation).

\item
Rule~(\ref{create_join}) describes how a selection and a cross product may be merged into a theta join,
provided that the selection predicate is a join condition. This is the case if it compares attributes of~$R_1$ and~$R_2$.
\end{compactitem}

\section{Material in Moodle}

\noindent
\begin{compactitem}
\item
The file \verb!test_raopt.py! contains unit tests. Make sure your implementation passes these tests.
\end{compactitem}

\section{What to Submit}
\begin{compactitem}

\item
Implement rule-based selection pushing and perform it on your relational algebra queries.
Proceed in these phases:
\begin{compactenum}
    \item Complex selection predicates are broken up, according to rule~(\ref{split}).
    \item All selections are pushed down as far as possible, according to rules~(\ref{push_over_sel}) and~(\ref{push_over_cross}).
    \item Nested selections are merged again, according to rule~(\ref{split}).
    \item Joins are introduced, where possible, according to~(\ref{create_join}).

\end{compactenum}

Note that there are more rules for the logical optimization of relational algebra, such as rules for join reordering or projection pushing. For {\em miniHive}\/, we will make do with this small set of optimization rules (for now).

\item
\noindent
Write a Python module \verb!raopt! that takes a relational algebra query. You may assume the query is the result of the canonical translation of SQL into relational algebra, so it uses only the operators $\sigma$, $\pi$, $\rho$ and $\times$ ).

This is how it should work. The data dictionary~\verb!dd! contains the relational schema and can consulted during selection pushing.

\end{compactitem}

\begin{Verbatim}[frame=single,fontsize=\small]
>>> import radb.parse
>>> import raopt
>>>
>>> # The data dictionary describes the relational schema.
>>> dd = {}
>>> dd["Person"] = {"name": "string", "age": "integer", "gender": "string"}
>>> dd["Eats"] = {"name": "string", "pizza": "string"}
>>>
>>> stmt = """\project_{Person.name, Eats.pizza}
...            \select_{Person.name = Eats.name}(Person \cross Eats);"""
>>> ra = radb.parse.one_statement_from_string(stmt)
>>>
>>> ra1 = raopt.rule_break_up_selections(ra)
>>> ra2 = raopt.rule_push_down_selections(ra1, dd)
>>> ra3 = raopt.rule_merge_selections(ra2)
>>> ra4 = raopt.rule_introduce_joins(ra3)
>>>
>>> print(ra4)
\project_{Person.name, Eats.pizza} (Person \join_{Person.name = Eats.name} Eats)
\end{Verbatim}

\bigskip
\noindent
\rule{\linewidth}{0.5mm}

{\bf Remarks:}
For Milestone 2, you are not asked to find any particular optimizations to make your implementation more efficient. All you are required to provide is a correct and clean implementation.

\noindent
\rule{\linewidth}{0.5mm}

\end{document}