# Get to know your model

Modern computer capacities and advances in modeling software and algorithms make numerical modeling much more accessible than a few decades ago. Nevertheless, basic understandings of the mathematical model structure and its feedback on the design stage are requirements to ensure that the model is not only credible but can also produce meaningful results.

With the knowledge of the previous weeks you should by now have designed a first model formulation. You will have a set of equations that translate your assignment idea into basic mathematical relations either as an optimization with several side constraints or a set of equilibrium conditions. Depending on what mathematical formulations you have chosen you will end up in a specific model sub-type. Those have advantages and disadvantages which may impact whether you can obtain a reasonable solution.

When it comes to optimization models, the main differentiation is between linear or non-linear model designs. A **Linear Program (LP)** consists of a linear objective function and linear constraints. A common formulation is a cost minimizing LP of the form:

\(min_{Q} C = \sum c_iQ_i\) | (Cost objective) | |

st | \(Q_i\leq q_{maxi}\) | (Production constraints) |

\(\sum Q_i \geq d\) | (Demand constraint) |

The advantage of LP formulations is that they can be solved relatively fast even for large scale models. The obtained solution furthermore provides a global optimum: either a unique solution, a continuum of equivalent solutions, or no solution. LP models therefore provide a good starting point to get familiar with the problem at hand. Albeit many relations and restrictions in the real world are non-linear oftentimes they can be reasonably approximated by linear formulations.

Naturally, **Non-Linear Programs (NLP)** relax the linearity constraints and the functional relations can take up any form. The advantage of NLPs comes with the possibility to remain closer to real world conditions. However, this comes at a price. First, NLPs are harder to solve and will normally need longer to find a solution. Second, most NLP solutions don’t guarantee a global optimum:

To ensure that a global maximum is reached further criteria in addition to the first-order conditions are needed. There are global solvers that ensure that a solution is a global optima, but the computational effort is much higher than for local solvers. Most of the time NLP models will therefore only ensure that a local optima is obtained. From a modeler perspective this means, that one should ensure that the obtained solution is reasonable; eg by providing starting points via LP approximations of the NLP model.

A special form of NLP models are formulations with quadratic elements. This can either be **Quadratic Programs (QP)** that have a quadratic term in the objective but only linear constraints or **Quadratic Constraints Programs (QCP)** in which the side constraints can contain quadratic formulations. Those NLPs are easier to solve and many solvers have special routines for this kind of problem. A typical QP is a welfare maximizing formulation assuming a linear demand function *(*\(P = a + bD\)*)* that translates into a quadratic welfare equation:

\(max_{D,Q}W=aD+_{b2}D_2-\sum c_iQ_i\) | (Welfare objective) | |

st | \(Q_i \leq q_{maxi}\) | (Production contraints) |

\(\sum Q_i \geq D\) | (Demand constraint) |

A final important form for optimization models are formulations involving integer variables. The most common form of models with integer elements are coded as **Mixed-Integer Linear Programs (MILP)** that involve both continuous and integer variables while keeping the linearity restrictions. You can also design non-linear formulations with integer elements (**Mixed-Integer Non-Linear Programs (MINLP))** but the current solver capability for those problems is rather limited. Integer elements are rather common in real life (ie most commodities are consumed in discrete amounts) but can often be reasonably approximated by continuous formulations for large-scale problems (ie models with a consumption of 1000.4 units are less of a problem than models with 1.4 units).

A common usage for integer elements are binary variables indicating choices (ie binary 0–1 variables), like fixed costs added if a production site is constructed. A typical example in electricity markets are power plant status conditions:

\(min_Q C = \sum c_i Q_i\) | (Cost objective) | |

st | \(S_i q_{min}\leq Q_i \leq S_i q_{max}\) | (Generation constraint) |

\(\sum Q_i \geq d\) | (Demand constraint) |

In case a plant is online (\(S=1\)) the output *(*\(X\)*)* of a plant \(i\) has to remain within the generation constraints defined by the lower and upper capacity limits. In case the plant is offline (\(S=0\)) the output is fixed to zero. MILP models are harder to solve than pure LP models but still perform reasonably well, normally obtain global optimality and can handle large datasets.

Equilibrium models are coded using the **Mixed Complementarity Problem (MCP)** format that formalizes the KKT structure we introduced in Week 3. The general formulation in case of maximization is:

\(\partial f\partial XX=0;\) | \(\partial f\partial X \leq0;\) | \(X \gt0\) |

The complementarity condition is often formulated as:

\[\partial f\partial X \leq0 \perp X \geq 0\]The interpretation is the same as we introduced in the basic design of equilibrium models: either X is positive, then the derivative has to hold with equality, or X is zero and the derivative can be in inequality (remember Step 3.7). This corresponds to the economic intuition behind the zero-profit and market clearing constraints. The advantage of the MCP formulation is that dual variables (ie the Langrangian multipliers, in other words the prices) are direct variables of the model.

All continuous optimization problems can be formulated as MCP. Depending on the solver capabilities you may prefer to keep them as optimization models, especially in the case of LPs. Adding integer variables to an MCP is not possible without further model tweaking which is not recommended without sufficient knowledge on modeling and it`s mathematical background.

From the overall model design perspective the above presented alternatives will have a feedback effect on the choices you make when deciding about the elements of your model. Oftentimes you will try to keep the model as simple as possible to ensure that you can derive a solution within a reasonable timeframe, meaning you aim for LP formulations. Then again, sometimes it is helpful to go beyond the simplest formulation to avoid the problem of LPs that you may end up in a continuum of equivalent solutions by introducing a quadratic element. If you aim for an elastic demand, LP formulations are no option. Game theoretic approaches typically need an MCP formulation. With time and experience you will get a feeling which formulations work reasonably well for which type of model elements. Model coding is something you can only learn by doing.

Now you should be able to evaluate your first model design a bit better. Did you include non-linear elements? Are they really necessary or could you find a linear formulation for them? Do you have integer elements in your model? Are they essential or can you relax them to be continuous variables?

One final note on coding your model: for numerical modeling the differentiation between **endogenous variables** (where the model will produce numbers for) and **exogenous parameters** (where you have to find numbers for) is important. So you may want to differentiate them in your code ie via upper and lower case letters as in the model examples above.

## Recommended readings:

Naturally this text cannot provide a complete overview on the mathematics of modelling. There are more complex model approaches, eg mathematical programs with equilibrium constraints (MPECs), and there are techniques to reformulate models to obtain solutions for otherwise unsolvable problems. However, there are plenty of books out there on this topic. You may want to start with Dantzig and Thapa (1997) or Williams (2013) to get more familiar with optimizations, and Gabriel et al. (2013) for complementarity modelling in energy markets. An applied comparison between different optimization approaches is provided in Ommen et al. (2014). A helpful reference for the numerical model assignment is Van den Bergh et al. (2014) that provides a comprehensive overview on approaches to model specific technical constraints in electricity markets.

#### Dantzig, G. B., & Thapa, M. N. (1997). Linear Programming 1: 1: Introduction (Vol. 1). Springer.

#### Gabriel, S. A., Conejo, A. J., Fuller, J. D., Hobbs, B. F., & Ruiz, C. (2012). Complementarity modeling in energy markets (Vol. 180). Springer Science & Business Media.

#### Ommen, T., Markussen, W. B., & Elmegaard, B. (2014). Comparison of linear, mixed integer and non-linear programming methods in energy system dispatch modelling. Energy, 74, 109-118.

#### Van den Bergh, K., Bruninx, K., Delarue, E., & D’haeseleer, W. (2013). A mixed-integer linear formulation of the unit commitment problem. KU Leuven Energy Institute Working papers EN2014-07.

#### Williams, H. P. (2013). Model building in mathematical programming. John Wiley & Sons.

© University of Basel