% NB: use pdflatex to compile NOT pdftex.  Also make sure youngtab is
% there...

% converting eps graphics to pdf with ps2pdf generates way too much
% whitespace in the resulting pdf, so crop with pdfcrop
% cf. http://www.cora.nwra.com/~stockwel/rgspages/pdftips/pdftips.shtml




\documentclass[10pt]{beamer}
%\usetheme[everytitleformat=uppercase]{m}
\usetheme[everytitleformat=regular]{m}
\usepackage[absolute,overlay]{textpos}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}


\usepackage[official]{eurosym}

\usepackage[scale=2]{ccicons}


%use this to add space between rows
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}


\newcommand{\R}{\mathbb{R}}

\def\l{\lambda}
\def\m{\mu}
\def\d{\partial}
\def\cL{\mathcal{L}}
\def\co2{CO${}_2$}

\def\mw{\text{ MW}}
\def\mwh{\text{ MWh}}
\def\emwh{\text{ \euro/MWh}}

\newcommand{\ubar}[1]{\text{\b{$#1$}}}



% for sources http://tex.stackexchange.com/questions/48473/best-way-to-give-sources-of-images-used-in-a-beamer-presentation

\setbeamercolor{framesource}{fg=gray}
\setbeamerfont{framesource}{size=\tiny}


\newcommand{\source}[1]{\begin{textblock*}{4cm}(8.0cm,8.0cm)
    \begin{beamercolorbox}[ht=0.5cm,right]{framesource}
        \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
    \end{beamercolorbox}
\end{textblock*}}

\usepackage{hyperref}


%\usepackage[pdftex]{graphicx}


\graphicspath{{graphics/}}

\DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg}



\def\goat#1{{\scriptsize\color{green}{[#1]}}}



\let\olditem\item
\renewcommand{\item}{%
\olditem\vspace{5pt}}

\title{Electricity Markets: Summer Semester 2016, Lecture 3}
%\subtitle{---}
\author{
  Tom Brown, Mirko Schäfer
}

\institute{
  Frankfurt Institute of Advanced Studies (FIAS), Goethe-Universit\"at Frankfurt \\
  FIAS Renewable Energy System and Network Analysis (FRESNA) \\
  \\
  \url{{brown, schaefer}@fias.uni-frankfurt.de}
}


\date{25th April 2016}


\titlegraphic{%
  \vspace{7cm}
    \includegraphics[width=4cm]{FIAS-logo}
}

\begin{document}

\maketitle


\begin{frame}

  \frametitle{Table of Contents}
  \setbeamertemplate{section in toc}[sections numbered]
  \tableofcontents[hideallsubsections]
\end{frame}





\section{Short-run efficient operation of electricity markets}

\begin{frame}{Consumers and generators}

{\bf Consumers:} Their \alert{utility} or \alert{value function} $U(Q)$ in \euro/h is a
  measure of their benefit for a given consumption rate $Q$. For a given price $\lambda$ they adjust their consumption rate $Q$ such that their \alert{net surplus} is maximised:
    \begin{equation*}
    \max_Q \left[U(Q) - \l Q \right]
  \end{equation*}
  
{\bf Generators:}  A generator has a \alert{cost} or \alert{supply function} $C(Q)$ in \euro/h, which
  gives the costs (of fuel, etc.) for a given rate of electricity
  generation $Q$~MW. If the market price is $\lambda$ \euro/MWh, the revenue is $\l Q$ and the generator should adjust their
generation rate $Q$ to maximise their \alert{net generation surplus}, i.e. their profit:
  \begin{equation*}
    \max_Q \left[ \l Q - C(Q) \right]
  \end{equation*}

  
  \end{frame}

\begin{frame}{Setting the quantity and price}

  Total welfare (consumer and generator surplus) is maximised if the
  total quantity is set where the marginal cost and marginal utility curves meet.

  If the price is also set from this point, then the individual
  optimal actions of each actor will achieve this result in a perfect
  decentralised market.

  \centering
  \includegraphics[width=8cm]{consumer_producer_surplus.pdf}

\end{frame}

\begin{frame}{The result of optimisation}

  This is the result of maximising the total economic welfare, the sum of the consumer and the producer surplus for consumers with consumption $Q_i^B$ and generators generating with rate $Q_i^S$:
  \begin{align*}
    \max_{\{Q_i^B\}, \{Q_i^S\}}\left[ \sum_i U_i (Q_i^B)  -  \sum_i C_i (Q_i^S) \right]
  \end{align*}
  subject to the supply equalling the demand in the balance constraint:
  \begin{align*}
    \sum_i Q_i^B -  \sum_i Q_i^S  = 0 \hspace{1cm} \leftrightarrow \hspace{1cm} \l
  \end{align*}
  and any other constraints (e.g. limits on generator capacity, etc.).

  Market price $\l$ is the shadow price of the balance constraint,
  i.e. the cost of supply an extra increment 1~MW, or reduce generation by an increment of 1~MW.

\end{frame}

\begin{frame}{Limits of this model}

{\bf Consumers:} How do they participate in the market? Role of retail? Demand side management? "Prosumers"?

{\bf Generators:} Ramp-rates? Startup costs?

{\bf Markets:} How to balance supply and demand at all times? Time structure of different markets? Managing risk? Market coupling? Role of the market operator?

{\bf Long-term decisions:} Investment decisions of consumers and generators? Regulation? 

{\bf Market power}

{\bf Transmission:} \alert{Network constraints}? Role of the system operator? Transmission expansion?

\end{frame}

\section{General constrained optimisation theory: Lagrangians and Karush-Kuhn-Tucker conditions}


\begin{frame}
  \frametitle{Optimisation problem}


We have an \emph{objective function} $f: \R^k \to \R$
\begin{equation*}
  \max_{x} f(x)
\end{equation*}
[$x = (x_1, \dots x_k)$] subject to some constraints within $\R^k$:
\begin{align*}
  g_i(x) & = c_i \hspace{1cm}\leftrightarrow\hspace{1cm} \l_i \hspace{1cm} i = 1,\dots n \\
  h_j(x) & \leq d_j \hspace{1cm}\leftrightarrow\hspace{1cm} \m_j \hspace{1cm} j = 1,\dots m
\end{align*}

$\l_i$ and $\m_j$ are the KKT `Lagrange' multipliers we introduce for
each constraint equation; it measures the change in the objective value of the optimal solution obtained by relaxing the constraint (shadow price).

\end{frame}

\begin{frame}
  \frametitle{KKT conditions}

The Karush-Kuhn-Tucker (KKT) conditions are necessary conditions that an optimal solution $x^*,\m^*,\l^*$ always satisfies (up to some regularity conditions):
\begin{enumerate}
\item Stationarity: For $l = 1,\dots k$
  \begin{equation*}
  \frac{\d f}{\d x_l} - \sum_i \l_i^* \frac{\d g_i}{\d x_l}  - \sum_j \m_j^* \frac{\d h_j}{\d x_l} = 0
  \end{equation*}
    \item Primal feasibility:
      \begin{align*}
        g_i(x^*) & = c_i \\
        h_j(x^*) &\leq d_j
      \end{align*}
    \item Dual feasibility: $\m_j^* \geq 0$
    \item Complementary slackness: $\m_j^* (h_j(x^*) - d_j) = 0$
\end{enumerate}

\end{frame}





\begin{frame}
  \frametitle{Complementarity slackness for inequality constraints}


  We have for each inequality constraint
  \begin{align*}
    \m_j^* & \geq  0 \\
    \m_j^*(h_j(x^*) - d_j) & = 0
  \end{align*}

  So \alert{either} the inequality constraint is binding
  \begin{align*}
    h_j(x^*)  = d_j
  \end{align*}
  and we have $\m_j^* \geq 0$.

  \alert{Or} the inequality constraint is NOT binding
  \begin{align*}
    h_j(x^*)  < d_j
  \end{align*}
  and we therefore MUST have $\m_j^* = 0$.

  If the inequality constraint is non-binding, we can remove it from the optimisation problem, since it has no effect on the optimal solution.
\end{frame}

\begin{frame}{Example: Two generators, fixed demand}

  Suppose marginal costs $c_1 = 10$ \euro/MWh, $c_2 = 30$ \euro/MWh,
  fixed demand $Q^B$, generation limits $\hat{Q}_1 = 300$ MW, $\hat{Q}_2 = 400$ MW.

  What is the optimal power plant dispatch, i.e. what values of $Q_1,Q_2$ maximise efficiency?

\end{frame}  

\begin{frame}{Example: Two generators with fixed demand}
Demand $Q^B=200$ MW.
  The optimal dispatch is $Q_1^* = 200 \text{ MW} < \hat{Q}_1$ and $Q_2^* = 0 < \hat{Q}_2$.

  \centering
  \includegraphics[width=6cm]{supply-demand-low.pdf}


\end{frame}

\begin{frame}{Example: Two generators with fixed demand}
Demand $Q^B=500$ MW.

  The optimal dispatch is $Q_1^* = 300 \text{ MW} = \hat{Q}_1$ and $Q_2^* = 200 \text{ MW} < \hat{Q}_2$.

  \centering
  \includegraphics[width=6cm]{supply-demand-high.pdf}


\end{frame}

\begin{frame}
  \frametitle{KKT: Application to 2-generator example with fixed demand}

  Our optimisation variables are $\{x\} = \{Q_1,Q_2\}$ with objective function

    \begin{equation*}
    \max_{Q_1,Q_2} f(Q_1,Q_2) = - c_1\cdot Q_1 - c_2\cdot Q_2
  \end{equation*}
  subject to one equality and four inequality \alert{constraints}:
  \begin{align*}
    Q^{B} -Q_1 - Q_2 & = 0  \hspace{1cm}\leftrightarrow\hspace{1cm} \l \\
    Q_1 & \leq \hat Q_1  \hspace{1cm}\leftrightarrow\hspace{1cm} \bar{\m}_1 \\
    Q_2 & \leq \hat Q_2  \hspace{1cm}\leftrightarrow\hspace{1cm} \bar{\m}_2 \\
    -Q_1 & \leq 0  \hspace{1cm}\leftrightarrow\hspace{1cm} \ubar{\m}_1 \\
    -Q_2 & \leq 0  \hspace{1cm}\leftrightarrow\hspace{1cm} \ubar{\m}_2
  \end{align*}

\end{frame}


\begin{frame}
  \frametitle{KKT: Application to 2-generator example with fixed demand}


  Stationarity:
  \begin{align*}
    -c_1 + \l^* -\bar{\m}_1^* + \ubar{\m}_1^* & = 0 \\
    -c_2 + \l^* -\bar{\m}_2^* + \ubar{\m}_2^* & = 0
  \end{align*}

  Primal feasibility:
  \begin{align*}
    Q^{B} - Q^*_{1}-Q^*_{2} & = 0\\
    0 \leq Q_{l} & \leq \hat Q^*_{l} \hspace{1cm} \forall l \in {1,2}
  \end{align*}
  
  Dual feasibility and complementary slackness:
  \begin{align*}
    \bar{\m}_l^* & \geq 0 \hspace{1cm} \forall l \in {1,2} \\
    \ubar{\m}_l^* & \geq 0 \hspace{1cm} \forall l \in {1,2} \\
    \bar{\m}_l^*(Q_l^*-\hat Q_l) & = 0 \hspace{1cm} \forall l \in {1,2} \\
    \ubar{\m}_l^*(-Q_l^*) & = 0 \hspace{1cm} \forall l \in {1,2} 
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{KKT: Application to the example}

  Stationarity:
  \begin{align*}
    -10\emwh + \l^* -\bar{\m}_1^* + \ubar{\m}_1^* & = 0 \\
    -30\emwh + \l^* -\bar{\m}_2^* + \ubar{\m}_2^* & = 0
  \end{align*}

  Primal feasibility:
  \begin{align*}
    Q^{B} - Q^*_{1}-Q^*_{2} & = 0\\
    0 \leq Q^*_1 & \leq 300\mw\\
    0 \leq Q^*_2 & \leq 400\mw
  \end{align*}
  
  Dual feasibility and complementary slackness:
  \begin{align*}
    & \bar{\m}_1^*  \geq 0\;,\; \ubar{\m}_1^* \geq 0\;,\; \bar{\m}_2^* \geq 0\;,\; \ubar{\m}_2^* \geq 0\\
    & \bar{\m}_1^*(Q_1^*- 300\mw) = 0
    \;,\;
    \bar{\m}_2^*(Q_2^*- 400\mw) = 0 \\
    & \ubar{\m}_1^*(-Q_1^*) = 0\;,\;
    \ubar{\m}_2^*(-Q_2^*) = 0 \\
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{Application to the example, $Q^B=200$ MW}

Stationarity shows that $\m_{l}^*\neq 0$ for some $j$.

From $Q^{B}<\hat Q_{1}$ and $Q^{B}<\hat Q_{2}$ it follows that $\bar{\m}^*_1=0$ and $\bar{\m}^*_2=0$.

We observe that from $\ubar{\m}^*_1\neq 0$ it follows $Q^*_1=0$, and from $\ubar{\m}^*_2\neq 0$ it follows $Q^*_2=0$. From the primal feasibility constraint it follows that either $Q^*_1>0$ or $Q^*_2>$, so either $\ubar{\mu}^*_1=0$ or $\ubar{\mu}^*_2=0$. 

If we substract the second stationarity equation from the first one, we obtain with $\bar{\m}^*_1=\bar{\m}^*_2=0$
\begin{align*}
20\emwh +\ubar{\m}^*_1 - \ubar{\m}^*_2 =0
\end{align*}
From the dual feasibility it follows that $\ubar{\m}^*_1=0$ and $\ubar{\m}^*_2=20\emwh$. Using the first stationarity equation we get $\lambda^*=10\emwh$.
    
\end{frame}

\begin{frame}
  \frametitle{Application to the example, $Q^B=500$ MW}

Stationarity shows that $\m_{l}^*\neq 0$ for some $l$.

From the primal feasibility constraint it follows that both $Q^*_1>0$ and $Q^*_2>0$, so both $\ubar{\m}^*_1=0$ and $\ubar{\m}^*_2=0$. 

From $\bar{\m}^*_1\neq 0$ it follows $Q^*_1 = 300\mw$, from $\bar{\m}^*_2\neq 0$ it follows $Q^*_2= 400\mw$. Due to primal feasibility thus either $\bar{\m}^*_1=0$ or $\bar{\m}^*_2=0$.

If we substract the second stationarity equation from the first one, we obtain with $\ubar{\m}^*_1=\ubar{\m}^*_2=0$
\begin{align*}
20\emwh +\bar{\m}^*_2 - \bar{\m}^*_1 =0
\end{align*}
From the primal feasibility it follows that $\bar{\m}^*_2=0$ and $\bar{\m}^*_1=20\emwh$. Using the first stationarity equation we get $\lambda^*=30\emwh$.
    
\end{frame}

\begin{frame}{Example: $N$ generators, fixed demand}
Suppose marginal costs $c_{l}$ and generation limits $\hat Q_{l}$, and assume a total fixed demand $Q^B$.

What is the optimal power plant dispatch, i.e. what values of $Q_{l}$ maximise efficiency?

\end{frame}

\begin{frame}
  \frametitle{KKT: Application to $N$ generators, fixed demand}

  Our optimisation variables are $\{x\} = \{Q_1,\ldots,Q_N\}$ with objective function

    \begin{equation*}
    \max_{Q_1,\ldots,Q_N} f(Q_1,\ldots,Q_N) = - \sum_{l=1}^{N}c_l\cdot Q_l
  \end{equation*}
  subject to one equality and $2N$ inequality \alert{constraints}:
  \begin{align*}
    g(Q_{l}) = Q^{D} -\sum_{l=1}^{N}Q_{l} & = 0  \hspace{1cm}\leftrightarrow\hspace{1cm} \l \\
    \bar{h}_{l}(Q_{l})=Q_l & \leq \hat Q_l=\bar{d}_{l}  \hspace{1cm}\leftrightarrow\hspace{1cm} \bar{\m}_l \\
    \ubar{h}_{l}(Q_{l})= -Q_l & \leq 0 = \ubar{d}_{l} \hspace{1cm}\leftrightarrow\hspace{1cm} \ubar{\m}_l
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{KKT: Application to $N$ generators, fixed demand}


  Stationarity:
  \begin{align*}
-c_{l} +  \lambda^* - \bar{\m}_{l} + \ubar{\m}_{l} = 0 \hspace{1cm} \forall l \in {1,\ldots,N}
  \end{align*}

  Primal feasibility:
  \begin{align*}
    Q - \sum_{l}Q^*_{l} & = 0\\
    0 \leq Q_{l} & \leq \hat Q^*_{l} \hspace{1cm} \hspace{1cm} \forall l \in {1,\ldots,N}
    \end{align*}
  
  Dual feasibility and complementary slackness:
  \begin{align*}
    \bar{\m}_l^* & \geq 0 \hspace{1cm} \forall l \in {1,\ldots,N} \\
    \ubar{\m}_l^* & \geq 0 \hspace{1cm} \forall l \in {1,\ldots,N} \\
    \bar{\m}_l^*(Q_l^*-\hat Q_l) & = 0 \hspace{1cm} \forall l \in {1,\ldots,N} \\
    \ubar{\m}_l^*(-Q_l^*) & = 0 \hspace{1cm} \forall l \in {1,\ldots,N}
  \end{align*}

\end{frame}


\begin{frame}{A remark on the parameter $\l$}

In the KKT formalism for efficient short term market operation, the parameter $\lambda$ gives the relative change of the objective function for the optimal solution, when we relax the balancing condition
\begin{align*}
\sum_{l}Q_{l}^{B} - \sum_{l}Q_{l}^{S} = 0~.
\end{align*}
The parameter $\l^*$ as the shadow price of this constraint is interpreted as the \alert{market price} (competitive price).

There is a little ambiguity about the marginal cost, when the supply and demand curves don't intersect, and the constraints determine the value $\l^*$.

\end{frame}

\begin{frame}{A remark on the parameter $\l$}

Consider a consumer with utility function $uQ^B$, and a generator with cost function $cQ^S$, and assume $u>c$. Furthermore assume that the consumption is limited by $\hat Q^B$, and generation is limited by $\hat Q^S$.

The objective function is
\begin{align*}
f(Q_B,Q_S)=uQ_B - cQ_S~,
\end{align*} 
with the balancing condition
\begin{align*}
Q_B - Q_S = 0~.
\end{align*}
The constraints are
\begin{align*}
0\leq Q_B \leq \hat Q_B \quad , \quad
0\leq Q_S \leq \hat Q_S~.
\end{align*}

\end{frame}

\begin{frame}{A remark on the parameter $\l$}

Running KKT on this problem gives the following result:

$\hat Q_S > \hat Q_B$: Optimal solution is $Q^*_S = Q^*_B=\hat Q_B$, with the competitive $\lambda^* = c$. Relaxing the balancing constraint would allow the generator to reduce the generation, and thus the relative cost by $c$, while the demand is still $\hat Q_B$. Lowering the demand would not increase the objective function, while increasing it is not possible due to the constraint.

$\hat Q_B > \hat Q_S$: Optimal solution is $Q^*_B =Q^*_s= \hat Q_S$, with the competitive price $\lambda^* = u$. Relaxing the balancing constraint would allow the consumer to increase the consumption, and thus the relative utility by $u$, while the generation is still $\hat Q_S$. Increasing the generation would not increase the objective function, while reducing it gives a smaller increase in the objective function than increasing the demand.
\end{frame}

\begin{frame}{A remark on the parameter $\l$}

But does this give the right competitive price? Interpreting the supply and demand curves as aggregates, we can understand the situation as follows:

In the first case a supplier could raise the price above its marginal cost $c$. But since $Q_S>\hat{Q}_S$, another generator would immediately jump in and fulfill the demand at the price $c$, so this is the competitive price.

Would the competitive price be less than $u$ in the second case, due to $Q_B<\hat Q_B$ there always will be a consumer willing to pay $u$ to satisfy his demand, so this is the competitive price.

For a discussion of this point see Chapter 1.6 in the book \emph{Power System Economics} by Steven Stoft.
\end{frame}

\section{Transmission and distribution networks}

\begin{frame}{Transmission and distribution networks}

Electricity usually is not consumed where it is produced, so it has to be transported via \alert{transmission} and \alert{distribution networks}.

Transmission networks: Transport large volumes of electric power over relatively long distances.

Distribution networks: Take power from the transmission network and deliver it to a large number of end points in a certain geographic area.

\end{frame}

\begin{frame}{Transmission and distribution networks}

  \centering
  \includegraphics[width=6cm]{powergrid.jpg}
  
  \source{VKU}
\end{frame} 
 
 \begin{frame}{European Transmission Grid}

  \centering
  \includegraphics[width=8cm]{ENTSOE_grid.png}
  
  \source{ENTSO-E}
\end{frame} 
 

\begin{frame}{Transmission and distribution networks in Germany}
  \centering
  \includegraphics[width=9cm]{verteilnetz.pdf}
  
  \source{BMWi}

%Four \alert{Transmission System Operators}: Amprion [partially: RWE], Tennet TSO [past: E.ON], 50 Hertz Transmission [past: Vattenfall], Transnet BW [EnBW]) 

%888 \alert{Distribution System Operators}: RWE, EnBW, E.ON, Vattenfall, Stadtwerke, regional companies
  
\end{frame}

\begin{frame}{Transmission and distribution networks in Germany}
  \centering
  \includegraphics[width=10cm]{tso_dso.png}
  
  \source{Agora Energiewende / RAP}
  
\end{frame}



\begin{frame}{TSOs in Germany}

  \centering
  \includegraphics[width=6cm]{tsos_germany.png}
  
  \source{Wikipedia (Francis McLloyd)}

\end{frame}

\begin{frame}{Transmission grid near Frankfurt}

  \centering
  \includegraphics[width=6cm]{hvgrid_ffm.png}
  
  \source{ENTSO-E}

\end{frame}

\begin{frame}{Frankfurts DSO}

  \centering
  \includegraphics[width=6cm]{NRM.pdf}
  
  \source{NRM Netzdienste Rhein-Main}
NRM Netzdienste Rhein-Main (subsidiary company of Mainova)

\end{frame}


\begin{frame}{Power grids and electricity markets}

The (physical) balancing of supply and demand has to respect the \alert{network constraints} of the system. These constraints have to be implemented by the \alert{system operator}, but to some extent can also be included into the \alert{market design}.

Transmission and distribution networks are (almost?) natural monopolies, which leads to substantial \alert{market power}. These networks are typically state owned, cooperatives or heavily regulated (many interesting problems with respect to incentives, tariffs, etc.).

Network expansion is part of the \alert{long-term} efficient operation of the system.

\end{frame}


\begin{frame}{Copyright}


  Unless otherwise stated the graphics and text is Copyright
  \copyright Tom Brown and Mirko Sch\"{a}fer, 2016.

  We hope the graphics borrowed from others have been attributed
  correctly; if not, drop a line to the authors and we will correct
  this.

  The source \LaTeX, self-made graphics and Python code used to
  generate the self-made graphics are available on the course website:

  \url{http://fias.uni-frankfurt.de/~brown/courses/electricity_markets/}

  The graphics and text for which no other attribution are given are licensed under a
  \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative Commons
  Attribution-ShareAlike 4.0 International License}.

  \begin{center}\ccbysa\end{center}

\end{frame}



\end{document}
