1 Introduction

Energy systems optimization is increasing its importance due to de-regulations in energy sector and the setting of targets such as the European Union (EU) 20-20-20 (see Appendix “Literature review and background”). In turn, these changes increase exposure to new risks shaped by decisions of various agents, which motivate new regulations and policies. For example, emissions trading schemes, renewable energy and/or efficient generators subsidies, or efficiency requirements such as buildings labeling, among others. This new situation is motivated by several concerns of the post-industrial era, namely: global warming, economy globalization, resources scarcity, and awareness for sustainability.

In spite of the above-mentioned globalization, usually global changes must be tackled at a regional or local scale. Thus, utilities and fuel producers, yet global, must fulfill local market requirements, e.g., enough amount of electricity for a given city. Moreover, final users of energy have their own requirements whose satisfaction depends on decisions made at the shop-floor stage. Users’ comfort, security, and energy availability are challenges for decision makers at the building level, who have to deal with limited budgets in addition to the regulations regardless their global, regional or local scope. Furthermore, new technologies and refurbishment options are available and continuously evolving, widening the range of options for main concerns of stakeholders including decision makers, operators, consultants, modelers, and data managers. There can also be external stakeholders, such as policy makers or mass media.

Considering the complexity of the emerging problem, this paper develops a model-based decision support system (DSS) for optimal strategic planning and operation of a building infrastructure. Although, stakeholders usually have different or even conflicting goals, they all are able to have a tailored dialogue with the DSS by means of interfaces and output reporting at different detail levels, but consistent between them. The DSS includes by design capabilities that enforce this dialogue. Specific attention is paid for developing new dynamic stochastic optimization models involving ex-ante strategic and ex-post operational variables. The model developed in this paper has moving time horizons defined by stopping time moments generated by potential extreme events and the stakeholders dialogue. This integrated framework provides an environment that enforces the necessary stakeholders communication.

As shown in Fig. 1, the purpose of this dialogue is twofold: on the one hand, a dialogue between the stakeholders and the DSS; on the other hand, among the stakeholders themselves, likely with different motivations and targets. The dialogue between stakeholders and the DSS is self-contained. Regarding the dialogue among stakeholders (internal and external), it can take place at any point of the decision making process, and a user communication is crucial for the accurateness of the inputs. Therefore, this dialogue may provide exogenous feedback to the decision process. In addition, since decision making is a possibly iterative process, the outcomes may provide endogenous feedback to the DSS structure through stopping time moments and moving time horizons (see Sect. 2).

Fig. 1
figure 1

Decision support system (DSS) framework diagram

Regarding DSSs, this term is usually defined as “an information system that supports decision making” with more or less detail and its use is often abused in Computer Science and in Management. Thus, any information system could claim to be a DSS. However, more specific boundaries are needed to capture the preferred analysis approach (see Appendix “Literature review and background”). Under that paradigm the model plays an important role in a DSS. Both the model and the data are the basis for decisions. Therefore, the proposed DSS is also capable of preparing the data in a model-suitable way. Appropriate algorithms are applied once the model is defined and the data is available. Decisions obtained by the DSS, regardless of their category (descriptive, normative, or prescriptive) include interpretation and analysis, probably requiring some posterior data analysis.

The developed framework provides a new flexible approach for DSS-based decision making process on optimal planning and operation of a building infrastructure in a dialogue with stakeholders. The proposed use of both human and machine readable formats through the use of algebraic modeling languages (AMLs) boosts the dialogue between stakeholders remarked in this section. On the other hand, the reproducible research approach (Leisch 2002) adopted in the following allows to record and track consistent updates throughout the time, and to provide a sort of balanced scorecard (BSC) to stakeholders consistent with all the components of the DSS. Furthermore, the results obtained are reproducible for any of the stakeholders, which increase the efficiency in multi-agent, multi-disciplinary and changing environments, and the quality of the communication processes.

Finally, it is important to remark that this framework has been successfully applied within the EnRiMa (Energy Efficiency and Risk Management in Public Buildings) project.Footnote 1 EnRiMa is a 7th Framework Program (FP7) research project whose overall objective is to develop a DSS for operators of energy-efficient buildings and spaces of public use.

This paper is organized as follows: in Appendix “Literature review and background”, a brief literature review is made. Subsection “Optimization of building infrastructure systems under uncertainty” provides an overview of the decision making problem on optimization and operation of a building infrastructure. The model and the data for the DSS are developed in Sects. 2 and 3 respectively. Section 4 proposes a framework for DSS and implements the model developed. Concluding remarks are provided in Sect. 5.

2 DSS models

2.1 A baseline example

To illustrate the proposed model, a simple example will be used. It shows that explicit introduction of a second-stage ex-post decisions induces risk aversion in strategic first-stage ex-ante decisions in the form of a dynamic CVaR risk measure and corresponding discounting. This example is inspired by the classical news vendor problem (e.g., Ermoliev and Wets (1988); Birge and Louveaux (2011)). In Sect. 2.4 this example is extended to illustrate specifics of dynamic two-stage stopping time models. Suppose a building manager can decide each year the energy capacity x of the building. For simplicity in the exposition, aggregated values and decisions are assumed. The price of each unit of capacity, e.g., kW, is c. During the year, the energy demand varies following a probability distribution described by a random variable \(\xi \). We have to specify in which sense \(x=\xi \) for a random \(\xi \). If the demand is larger than the capacity, i.e., \(\xi > x\), then the building manager has to increase the capacity to fulfill the demand, but at a higher cost \(d^+ > c\). If the demand is lower than the capacity x, i.e., \(\xi < x\) then the building manager can sell energy at a lower price \(d^-<c\). Let \(y^-\) \((y^+)\) be such excess (shortage) of capacity. Then, for a given \(\xi \), the balance equation is defined as \(x = \xi + y^+ - y^-\), and the cost function for the building energy procurement is:

$$\begin{aligned} cx + d^+ y^+ (\xi ) - d^-y^-(\xi ). \end{aligned}$$
(1)

Note that in these types of problems, there are strategic first-stage decisions x that are to be made before uncertainty \(\xi \) is resolved and operational second-stage decisions y that are made once uncertainty is resolved. As we have seen above, the optimal value of the second stage decision depends on both the random variable \(\xi \) and the first-stage decision x: \({y^+}^*=\max \{0, \xi - x\}\) and \({y^-}^*=\max \{0, x - \xi \}\). Therefore, the expected value of the cost function we want to minimize can be expressed as:

$$\begin{aligned} C(x) = cx&+ {\mathbf {E}}_{\xi } \min _{y^+,y^-} \left[ d^+ y^+ (\xi ) - d^- y^- (\xi ) \right] \nonumber \\ = cx&+ {\mathbf {E}}_{\xi } \left[ d^+ \max \{0, \xi - x\} - d^- \max \{0, x - \xi \} \right] , \end{aligned}$$
(2)

where \({\mathbf {E}}[\cdot ]\) is the mathematical expectation function. Developing the following optimality condition under optimal \(x>0\):

$$\begin{aligned} C'(x)=\frac{\partial C}{\partial x} = 0, \end{aligned}$$
(3)

where \(C'(x)\) denotes the first order derivative of C(x) evaluated at x, yields the following expression (Cano et al. 2014b):

$$\begin{aligned} {\mathbf {P}}\left[ \xi < x \right] = \frac{d^+ - c}{d^+ - d^-}, \end{aligned}$$
(4)

where \({\mathbf {P}}[\cdot ]\) is the probability function. So, the probability of the demand being lower than the optimal is defined by the whole structure of the energy supply systems, i.e., the structure of unite costs and the distribution of threats. Given that \(d^+> c > d^-\), Eq. (4) assures a level of security for the solution. Namely, this solution depends on the probability distribution of \(\xi \) and costs \(d^+, d^-, c\). Therefore, the solution of two-stage (strategic-operational) stochastic problems ends up in the fulfillment of some security level, whereas \({\mathbf {P}}\left[ \xi > x \right] \) characterizes the Value-at-Risk (VaR). Such solutions \(\left( x^{*},y^{+*},y^{-*} \right) \) are optimal for all the scenarios at a time, thereby providing robust solutions for strategic \(x^{*}\) and operational decisions \(y^{+*}, y^{-*}\) decisions. In contrast, the solution of the deterministic problem, i.e., substituting the uncertain parameters \(\xi \) by its expectation \({\mathbf {E}}\left[ \xi \right] \) and solving the optimization problem, is a degenerated solution for an average scenario, which might never occur. Likewise, solving the worst case scenario problem, i.e., using \(\max \{\xi \}\) as fixed, would be too conservative and unrealistic, consequently leading to very high costs.

In this example, both first- and second-stage decisions are represented within a given time horizon. Due to the problem own structure, operational decisions induce risk aversion on strategic decisions.

2.2 The dynamic two-stage model with random horizons

The main specifics of the following model is its ability to inforce a dialogue among stakeholders (internal and external). It can take place at any point of the decision making process and provide feedback to the DSS structure including the model, sets of decisions, and data. We define these points as a stopping time moments, which may also be associated with the occurrence of extreme weather related events, earthquakes, failures of markets, or learning new information. Proper adjustments of strategic decisions after these moments reduce irreversibilities of decisions (Arrow and Fisher 1974). In this section we develop a new two-stage dynamic optimal planning and operation of a building infrastructure model with random duration of stages bounded by stopping time moments.

Strategic and operational decisions concern demand and supply sides of different energy loads and resources (electricity, gas, heat, etc.). The demand side is affected by old and new equipment and activities including such end uses as electricity only, heating, cooling, cooking, new types of windows and shells, and energy-saving technologies, etc. The supply side is affected by decisions on new technologies. The notion of technology must be understood in a rather broad sense. This may be either direct generation of electricity and heat, or the purchase of certain amounts of, e.g., electricity from a market, i.e., the market can also be viewed as energy generating technology with specific cost functions. Independently of the content, different options i are available at time t to satisfy energy demand, \(i \in {{\mathcal {I}}}=\{1,\ldots , I\}, t \in {\mathcal {T}}= \{1,\ldots ,T\}\), where T is a random planning horizon. For each case study, feasible options at time t have to be characterized explicitly.

The model is dynamic and the planning horizon comprises T years. Uncertainties pertaining to demands, fuel prices, operational costs, and the lifetime of technologies are considered. Demand may be affected by weather conditions. It may also substantially differ by the time of the day and the day of a week. However, instead of considering 8760 hourly values per year, demands and prices are aggregated into J periods representatively describing the behavior of the system within a year. Similar approaches can be found in the literature (Conejo et al. 2007).

The demand profile within each year t, can be adequately characterized by the demand within representative periods \(j, j \in {{\mathcal {J}}}=\{1,\ldots ,J\}\). This time structure is represented in Figure 2, where \(D_j^t, \mathrm{CO}_{i,j}^t\) denote the energy demand and costs of technology i in period j of year t, and \(y_{i,j}^t\) are operational decisions for technology i in period j of year t. The goal of the strategic model is to find technologies i and their capacities \(x_i^t\), installed at the beginning of year t to satisfy demands \(D_j^t\), in each period j.

Fig. 2
figure 2

Temporal resolutions of the strategic planning model

In the following \(\omega \) is used to denote a sequence \(\omega =(\omega _1, \omega _2, \ldots , \omega _t, \ldots , \omega _T)\) of uncertain vectors \(\omega _t\) of general interdependent parameters which may affect outcomes of the strategic model, e.g., market prices, perceived outcomes of the stakeholder dialogue, or weather conditions. Formally, assume planning time horizon of T years. Let \(x_i^t\) be the additional capacity of technology i installed in year t, and \(s_i^t\) the total capacity by i available in t. Then,

$$\begin{aligned}&\displaystyle x _{i}^{t} \ge 0 \quad \forall i \in {{\mathcal {I}}},t \le \tau (\omega _n),\end{aligned}$$
(5)
$$\begin{aligned}&\displaystyle s _{i}^{t} = s _{i}^{ t - 1 }+ x _{i}^{t}- x _{i}^{ t - LT _{i}^{}} \quad \forall \;i \in {{\mathcal {I}}},\; t > \mathrm {LT}_i, \end{aligned}$$
(6)

where \(\mathrm{LT}_i\) is in general random lifetime of technology i and \(s_i^0\) is initial capacity of i existent before \(t=1\).

In addition to operational costs \(\mathrm{CO}_{i,j}^t\), investment costs \(\mathrm{CI}_i^t\) are considered. In general, the operational and investment costs, as well as energy demand \(D_j^t\), are uncertain. Strategic first stage investment decisions \(x_i^t\), are made at the beginning of the planning horizon \(t=1\) using a perception of potential future scenarios \(\mathrm {CI}_i^t(\omega ), {\mathrm {CO}}_{i,j}^t(\omega ), D_j^t(\omega )\) of costs and energy demands dependent on the stochastic parameter \(\omega \). Second stage adaptive operational decisions \(y_{i,j}^t\) are made after observing real demands and costs. They depend on observable scenario \(\omega \), i.e., \(y_{i,j}^t=y_{i,j}^t(\omega )\). Therefore, any choice of investment decisions \({x}=x_i^t\), may not yield feasible second stage solutions \({y}(\omega ) = y_{i,j}^t(\omega )\) satisfying the following equations for all \(\omega \):

$$\begin{aligned} \sum _{i \in \mathcal { I }} y _{i,j}^{t}(\omega ) = D _{j}^{t}(\omega ) \quad \forall \;j \in {{\mathcal {J}}},\; t \le \tau (\omega _n), \end{aligned}$$
(7)
$$\begin{aligned} y _{i,j}^{t} (\omega ) \le G _{i,j}^{t} \cdot s _{i}^{t} \quad \forall \;i \in {{\mathcal {I}}},\; j \in {{\mathcal {J}}},\; t \le \tau (\omega _n), \end{aligned}$$
(8)
$$\begin{aligned} y _{i,j}^{t}(\omega ) \ge 0 \quad \forall \; i\in {{\mathcal {I}}}, j \in {{\mathcal {J}}}, t \le \tau (\omega _n), \end{aligned}$$
(9)

where \(G_{i,j}^t\) may be interpreted as the availability factor corresponding to the technology operating in period j in t (\(G_{i,j}^t=0\) for not yet existing technologies).

Thus, the set of feasible solutions is characterized by the decision variables \((x,y(\omega ))\), where the strategic decisions \(x=(x_1,...,x_T)\) are made before observing a scenario \(\omega \), and operational decisions \(y(\omega )=(y_ij^t(\omega )), t=1,...,T\) for all technologies i and periods j are made after learning scenarios \(\omega \) and \(\tau (\omega ))\) The feasibility of constraints (7)–(9) for any scenario \(\omega \) can be guaranteed by assuming the existence of a back-stop technology with high operating costs that can also be viewed as purchasing without delay but at high price. In particular, it can be viewed as a contingent credit or a catastrophe (black-out) bond, similar as in Ermoliev et al. (2012). Without loosing generality it can be assumed that for any period j and time t it is the same technology \(i=1\). Then the basic dynamic stochastic two-stage model is formulated as the minimization of the expected total cost function:

$$\begin{aligned} {{\mathbf {F}}}(x)&= {\mathbf {E}}_{\omega } \left[ \min _{y(\omega )} \sum _{i \in \mathcal { I }, t \le \tau (\omega )} \left( \mathrm {CI}_{i}^{t}(\omega ) \cdot x _{i}^{t} + \sum _{j \in \mathcal {J}} \mathrm {CO}_{i,j}^{t}(\omega ) \cdot \mathrm {DT}_{j}^{t} \cdot y _{i,j}^{t}(\omega ) \right) \right] \nonumber \\&= \sum _{i \in \mathcal { I }, t \in \mathcal { T }} \left( \mathrm {CI}_{i}^{t} \cdot x _{i}^{t} + {\mathbf {E}}_{\omega } \left[ \min _{y(\omega )} \sum _{j \in \mathcal {J}} \mathrm {CO}_{i,j}^{t}(\omega ) \cdot \mathrm {DT}_{j}^{t} \cdot y _{i,j}^{t}(\omega ) \right] \right) , \end{aligned}$$
(10)

This problem can be easily extended to deal with advanced energy systems features such as efficiency, emissions, or storage (Cano et al. 2014b, a).

2.3 Numerical methods: learning by doing and moving random time horizons

The model (5)–(10) is formulated in the space of variables \(\left. ( x_i^t, y_{i,j}^t(\omega )\right. , i \in {{\mathcal {I}}}, t \in \mathcal {T(\omega )}, \left. \omega \in \Omega \right. )\), where the set of scenarios \(\Omega \) may include a finite number of implicitly given scenarios, e.g., by scenario trees (Kaut et al. 2013) or other scenario generating methods based on requirement equations and perceptions of stakeholders. A realistic practical model (5)–(10) excludes analytically tractable solutions, although the model has an important block-structure that is usually utilized for most effective numerical solutions in DSS. In a rather general case, \(\Omega \) contains or can be approximated by scenarios \(\omega ^n, n\in {{\mathcal {N}}}\), characterized by probabilities \(p_n, n \in {{\mathcal {N}}}\). e.g., by sample mean approximations with \(p_n=1/N\), where N is the number of scenarios. Then the model (5)–(10) is formulated as the minimization of the function:

$$\begin{aligned} \sum _{n \in {\mathcal {N}}} p_n \left[ \sum _{i \in \mathcal { I }, t \le \tau (\omega ^n)} \left( \mathrm {CI}_{i}^{t}(\omega ^n) \cdot x _{i}^{t} + \sum _{j \in \mathcal { J }} \mathrm {CO}_{i,j}^{t}(\omega ^n) \cdot \mathrm {DT}_{j}^{t} \cdot y _{i,j}^{t}(\omega ^n) \right) \right] , \end{aligned}$$
(11)

subject to:

$$\begin{aligned} \sum _{i \in \mathcal { I }} y _{i,j}^{t}(\omega ^n) = D _{j}^{t}(\omega ^n) \; \forall \;j \in \mathcal {J},\; t \le \tau (\omega ^n),\quad n \in {{\mathcal {N}}}, \end{aligned}$$
(12)
$$\begin{aligned} y _{i,j}^{t} (\omega ^n) \le G _{i,j}^{t} \cdot s _{i}^{t} \; \forall \;i \in {{\mathcal {I}}},\; j \in \mathcal {J},\; t \le \tau (\omega ^n),\quad n \in \mathcal {N}, \end{aligned}$$
(13)
$$\begin{aligned} y _{i,j}^{t}(\omega _n) \ge 0 \; \forall \;j \in \mathcal {J},\; t \le \tau (\omega ^n),\quad n \in \mathcal {N}, \end{aligned}$$
(14)
$$\begin{aligned} s _{i}^{t} = s _{i}^{ t - 1 }+ x _{i}^{t}- x _{i}^{ t - \mathrm {LT}_{i}^{}} \; \forall \;i \in {{\mathcal {I}}},\quad t > \mathrm {LT}_{i} ,\end{aligned}$$
(15)
$$\begin{aligned} x _{i}^{t} \ge 0 \; \forall i \in {{\mathcal {I}}},\quad t \le \tau (\omega ^n) . \end{aligned}$$
(16)

Sequential decision making process under a dialogue of stakeholders can be written in the following form. The model (11)–(16) is focused on a sample \({\tau (\omega )}\) of random time horizons. The robust strategic solution solving the model (11)–(16) can be denoted as:

$$\begin{aligned} \pmb {x}^{[1,T]}=\left( x_i^{1,[1,T]}, \ldots , x_i^{T,[1,T]}\right) ,\quad i \in {{\mathcal {I}}}. \end{aligned}$$

Solutions \(\left( x_t^{t,[1,T]} \right) ,t=1,...,\tau (\omega ) i \in {{\mathcal {I}}}\), are implemented at \(t=1,2,...\) until a stopping time moment \(\tau _1(\omega ) \le T\), that may reveal significant new information about necessary systemic changes and future uncertainties. Let us denote scenario \(\omega \) for interval [1, T] as \(\omega ^{[1,T]}\). New information provides a basis for readjustments of scenarios \(\omega ^{[1,T]}\) perceived at the beginning of time horizon [1, T]. Then, new set of scenarios \(\omega ^{[\tau _1,\tau _1+T]}\) are generated, robust strategic solutions \(\left( x^{\tau _1,\tau _1+T} \right) \) are obtained, and so on. Thus, initially a long-term strategic trajectory \(x^{[1,T]}\) is evaluated, the solutions \(\left( x^{1,\tau _1} \right) \) are implemented, new data are received, new scenarios \(\omega ^{[\tau _1,\tau _1+T]}\) are generated, solutions \(x^{[\tau _1,\tau _1+\tau _2]}\) for a stopping time \(\tau _2\) are calculated, and solutions \(x^{[\tau _1,\tau _1+T]}\) are implemented, and so on. This approach introduces a new type of models incorporating endogenous scenario generation shaped by previous decisions, i.e., learning-by-doing procedures.

Let us remark that the specific case of this model with deterministic stopping time interval \(\tau =1\) or, in general, equal to some positive \(\tau \), defines models with rolling time horizons. The use of these models significantly reduces difficulties of the traditional multi-stage models.

2.4 Endogenous dynamic systemic risks and discounting

In this section we extend the illustrative model presented in Sect. 2 to a dynamic with random horizon model. In this more general form, the problem becomes similar to catastrophic-risk-management problems discussed in Ermoliev et al. (2000). Here, we show that the dynamic with random horizon model has strong connections with endogenously generated, i.e. systemic, dynamic versions of VaR and CVaR risk measures.

Let us consider the total energy capacity (capacity) of the building defined by \(R_{t}=\sum _{k=1}^{t}x_{k}\) before a stopping time \(\tau \), where \(x_k\) denotes the additional energy capacity of the building installed in year k, i.e., decision variables \(x_{k} \ge 0, k=1,...,t, t \le T\). At time \(t=\tau \), the target value on total capacity \(R_{t}\) in period t is given as a random variable \(\rho _{t}\). It is assumed that the first replacement of technologies due to aging processes, arriving a disaster, or adopting a new regulation occurs at random stopping time moment \(\tau \). Since \(\tau \) is uncertain, the decision path \(x=(x_{1},...,x_{T})\) for the whole time horizon has to be chosen ex-ante in period \(t=1\) to ”hit” the target \(\rho _{t}, R_{\tau } \ge \rho _{\tau }\), at \(t=\tau \) in a sense specified further by (10). At random \(t=\tau \), the decision path can be revised for the remaining available time. Similar to the model of Sect. 2, consider random costs \(v(x)=\sum _{t=1}^{\tau }[c_{t}x_{t}+d_{t}\max \{0,\rho _{t}-R_{t}\}]\), where \(c_{t}>0, d_{t}>0, t=1,...,T\) are known ex-ante and ex-post costs. The expected value of costs can be written as:

$$\begin{aligned} V(x)=\sum _{t=0}^{T} \left[ c_{t}x_{t}+p_{t}d_{t} \max \left\{ 0,\rho _{t}-\sum _{k=0}^{t}x_{k} \right\} \right] , \end{aligned}$$
(17)

where \(p_{t}={\mathbf {P}}[\tau =t]\).

Let us consider a path \(x^{*}\) minimizing V(x) subject to \(x_{t} \ge 0, t=1,...,T\). Assume that V(x) is a continuously differentiable function (e.g., a component of random vector \(\rho =(\rho _{1},...,\rho _{T})\) has a continuous density function). Also, assume for now that there exist positive optimal solution \(x^{*}=(x_{0}^{*}, x_{1}^{*},..., x_{T}^{*}), x_{t}^{*}>0, t=1,...,T\). Then from the optimality condition (Ermoliev 2009) for stochastic minimax problem (17), similar to the one in Sect. 2.2, it follows that for \(x=x^{*}\),

$$\begin{aligned} V_{x_{t}}=c_{t}-\sum _{k=t}^{T}p_{k}d_{k}{\mathbf {P}}\left[ \sum _{s=0}^{k}x_{s} \le \rho _{k}\right] =0, \quad t=1,1,...,T. \end{aligned}$$

From this sequentially for \(t=T,T-1,...,1\), follow the equations

$$\begin{aligned} {\mathbf {P}}\left[ \sum _{k=0}^{T}x_{k} \le \rho _{T}\right] =\frac{c_{T}}{p_{T}d_{T}}, {\mathbf {P}}\left[ \sum _{k=0}^{t}x_{k} \le \rho _{t}\right] =\frac{(c_{t}-c_{t+1})}{p_{t}d_{t}}, \quad t=0,1,...,T-1, \end{aligned}$$
(18)

which can be viewed as a dynamic VaR-type endogenous (systemic) risk measure. Equations (18) can be used for analyzing desirable dynamic risk profiles, say, time independent risk profiles with a given risk factor \(\gamma : c_{T}/p_{T}d_{T}=(c_{t}-c_{t+1})/p_{t}d_{t}, t=1,...,T-1\), which can be achieved by decisions affecting parameters \(c_{t}, d_{t}, p_{t}\), i.e. by adjusting costs (penalties).

Equations (18) are derived from the existence of the positive optimal solution \(x^{*}\). It is easy to see that the existence of this solution follows from \(c_{T}/p_{T}d_{T}<1, 0 \le (c_{t}-c_{t+1})/p_{t}d_{t}<1, t=1,...,T-1\), and some other technical requirement discussed by O’Neill et al. (2006).

We can see that a simplest case of dynamic two-stage model (11)–(16) with random (stopping) time horizons induces endogenous risk measures, which take the form of a dynamic VaR-type systemic (dependent on the structure of the system) risk measures. Values \(p_t={\mathbf {P}}[\tau =t]\) can be viewed as endogenous discounting (see discussion in Ermoliev et al. (2010). Misperception of this discounting can lead to wrong policy implications.

3 DSS data

3.1 Two-stage problem instance

In this section, real data from the EnRiMa project are used to demonstrate the modeling approach. In particular, historical data from an EnRiMa test site in Asturias (Spain) have been used. Let us consider the model defined by (11)–(16). Starting from base values, the future development of the parameter values have been modeled through expert opinions getting average values and standard deviations for annual variations, see Table 1.

Table 1 Base parameter values an uncertain evolution

Assuming normal distributions, a set of 100 scenarios \(\omega _n\) have been simulated. In general cases, scenarios \(\omega _n\) are simulated using rather general scenario generators based on partial observations and experts perception. Figure 3 shows a representation of this simulation, which is basically a representation of the stochastic parameters’ possible evolution throughout the decision horizon: demand (left), strategic costs (center), and operational costs (right). The thick solid line indicates the average value of the parameter. In the following, a detailed description of the data used as input is given. For the sake of simplicity, only four representative periods (set \({{\mathcal {J}}}\)) have been defined: winter, spring, summer and autumn. The input technologies (set \({{\mathcal {I}}}\)) are Regulated Tariff of Electricity (RTE), Photovoltaic (PV) and Combined Heat and Power (CHP). In this simple example with only electricity demand, it is assumed that the heat produced by the CHP technology is not used. Regarding the technologies availability, RTE and CHP are always available \((G_{i,j}^t=1)\), whereas PV availability depends on the season as shown in Table 2 (assuming the same values for all the years). A Sunmodule SW 245 by Solarworld has been considered.Footnote 2 The availability factor has been computed using the on-line PGIS tool (Photovoltaic Geographical Information System) by the European Commission Joint Research Center - Institute for Energy and Transport.Footnote 3

Fig. 3
figure 3

Scenarios simulation for the two-stage model

As for investment costs \(CI_i^t\), the price for the PV panels has been taken from the PREOC price database,Footnote 4 whilst the price for the CHP has been gathered from the on-line seller myTub.Footnote 5 A 40% reduction has been applied to the investment costs to take into account available subsidies in the market.Footnote 6 This parameter also gathers a cost of contracting RTE of 50 EUR/kW, which increases at the same rate as the energy cost. For the operational costs \(CO_{i,j}^t\), the base fuel prices for electricity and natural gas are 0.134571 EUR/kWh and 0.05056 EUR/kWh for RTE and CHP, respectively, based on the EnRiMa project deliverable D1.1 “requirement assessment”, and no cost for PV. As a short horizon is considered, the lifetime parameter \(LT_i\), which has been set to 20 years, has no influence on the result. Finally, the duration time is set to 91 days \(\times \) 8 hours, considering 13 weeks each period.

Solving the SP problem the strategic decisions to be made are (see Table 3): contracting 45.65 kW to RTE and installing 57.65 kW of PV the first year, and extend the PV installation the second year in 1.77 kW. Note that the actual decisions to be made are those for the first year.

Table 2 PV technology availability (ratio)
Table 3 Strategic solutions for the two-stage problem

The total cost stemming from those decisions is 68,595 EUR. If we assumed average values for the uncertain parameters, i.e., solve the deterministic problem using the mean values represented in Fig. 3 as the solid thick line, we would get a total cost of 66.920 EUR and slightly different values for the decision variables. The deterministic problem can be seen as a single-scenario version of the stochastic problem (11)–(16). Given the figures, one could think that the deterministic solution is better than the stochastic one. But this is an illusion, because if we analyze the variability (robustness) of solutions using separately the 100 different scenarios, we realize that the solution returned by the deterministic optimization is unfeasible for 56 of them. This means that more than half the times the capacity of the building will not be able to fulfill the requirements of energy. On the contrary, the solution returned by the SP problem is a robust solution against all the scenarios.

To compute the value of stochastic solution (VSS), the first-stage decisions obtained in the deterministic problem, i.e., considering parameters’ average values, are fixed in the SP problem (11)–(16), which is then solved. The solution of this problem is called the expected result of using the expected value problem (Birge 1982) and represented by \({{\mathbf {F}}}(x^{*det})\), while the solution of the SP problem is represented by \({{\mathbf {F}}}(x^{*sto})\). In this case, as \({{\mathbf {F}}}(x^{*det})\) is unfeasible, it is considered infinite and therefore, the VSS is infinite:

$$\begin{aligned} {{\mathbf {F}}}(x^{*det}) - {{\mathbf {F}}}(x^{*sto}) = \infty - 68,595=\infty . \end{aligned}$$

It is important to remark that even if \({{\mathbf {F}}}(x^{*det})\) is feasible, the VSS is positive, and the magnitude will depend on the uncertainty structure. The value \({{\mathbf {F}}}(x^{*sto})\) is smaller than \({{\mathbf {F}}}(x^{*det})\) because the stochastic model has a richer set of feasible solutions, i.e., the deterministic solution \(x^{*det}\) is a degenerated version of \(x^{*sto}\).

4 DSS framework

4.1 Overview

The proposed framework relies on the use of Algebraic Modeling Languages (AMLs), in contrast to the use of whole matrices to represent the optimization problems. The advantages of AMLs versus matrix-like systems have been largely discussed (Fourer 1983; Kuip 1993). Recent advances on AMLs can be found in Kallrath (2012b). Nevertheless, usually optimization software accepts matrix files with the model coefficients and actually modeling software generates the matrix from the algebraic language. However, the process is usually more straightforward and less prone-error when using AMLs, as the modeler has just to write the model, and the coefficients are generated combining the data and the model. Despite AMLs have been selected to build the framework, it is important to remark that other structured formats, e.g., markup languages, can be used as far as they are useful to accomplish the DSS main mission, i.e., the stakeholders dialogue. For example, OS (optimization services)Footnote 7 is a COIN-OR (Computational Infrastructure for Operations Research)Footnote 8 project that uses the XML format to represent optimization problems and that is suitable to effectively communicate within an eventual DSS. As for AMLs, they are “declarative languages for implementing optimization problems” (Kallrath 2012a). They are able to include the elements of optimization problems in a similar way they are formulated mathematically using a given syntax that can be interpreted by the modeling software. This approach is essential for representing the models not only for machines, but also for humans, and allows to organize the stakeholders dialogue. There are several AMLs available both commercial and open source.

4.2 A reproducible research approach

Against the “copy-paste” approach frequently used to reach the final outcome of a decision making problem, the reproducible research one adopted in the framework proposed has a series of advantages worthy to consider, namely: (1) when coming back to the research in the future, i.e., due to moving time horizon, the results can be easily obtained again; (2) in case other researchers have to contribute to the work, all the process is at hand; changes on any step of the process (e.g., a new index in the mathematical model) are made seamlessly just changing the appropriate data object, the whole analysis is made again with the new information, and the changes are automatically reflected in the output results; and (3) the results can be verified by independent reviewers. The latter is particularly important in health research and other disciplines where security is an issue. A paradigmatic example to realize the importance of reproducible research is the scandal of the Duke cancer trials (CBS 2015; The New York Times 2011). For an example on energy issues see Jelliffe (2010), where reproducible research is pointed out as a powerful tool for the mainstream climate scientists.

To fulfill the requirements for a DSS detailed in Sect. “Optimization of building infrastructure systems under uncertainty”, a reproducible research approach is advisable. In the following subsection, a specific implementation of the general framework reflected in Fig. 1 is presented, including the model, the data, the algorithms and the solution, covering the needs for stakeholders dialogue at any level.

4.3 Implementation

The general framework outlined above can be implemented using different technologies according to the stakeholders needs, as far as their dialogue is assured. In this subsection, a possible implementation using the programming language and statistical software R (R Core Team 2013) is shown. The R Project for Statistical Computing is becoming the “de-facto standard for data analysis”, according to more and more authors from a variety of disciplines, from Ecology to Econometrics (Cano et al. 2012).

Some of the advantages of choosing R as the statistical software for a DSS are: It is Open Source; it has Reproducible Research and Literate Programming capabilities (Leisch 2002); it can be used as an integrated framework for models, data and solvers; it supports advanced data analysis (pre- and post-), graphics and reporting; interfacing with other languages such as C or Fortran is possible, as well as wrapping other programs within R scripts.

These capabilities allow the researcher to apply innovative methods and coherent results increasing the productivity and reducing errors and unproductive time. Moreover, R runs in almost any system and configuration, the installation is easy, and there are thousands of contributed packages for a wide range of applications available at several repositories. This extensibility provides the framework with the capability of adaptation to the stakeholders dialogue’s requirements through the creation of new libraries and functions, either public or private. Last but not least, the active R-Core development team jointly with the huge community of users provide an incredible support level (without warranty, skeptics would say), difficult to surpass by other support schemes.

One of the capabilities of this implementation of the framework is to represent the models in  format, which is one of the “Practitioner’s Wish List Towards Algebraic Modeling Systems” according to Kallrath (2012c). The AML selected for this implementation of the framework has been GAMS. Nonetheless, the classes explained below can be easily extended to other languages. This is possible due to the fact that the SMS is generically represented within the DSS using specific R data structures. Moreover, R provides functionality for all the required tasks within the DSS, including data analysis, visualization and representation tasks, allowing communicating to different optimization software through inner interfaces. Data cleaning and management can also be easily done with R and user interfaces can be provided, both through other technologies or through libraries devoted to user interfacing. Note that the spirit of the framework can apparently be applied using other programming and analysis tools.

An R package called optimr.Footnote 9 has been developed as an implementation of the framework described in this paper to deal with the model, the data, and the solutions. The optimr package revolves around two classes of objects: optimSMS and optimInstance. The former contains the Symbolic Model Specification (SMS), i.e., the mathematical model including all the entities such as parameters and variables and their interrelations. The latter contains the data of the particular instance of the problem to be solved. Figure 4 shows an outline of the package structure. Once the model is defined as an optimSMS object, the data are used to feed the model by means of an optimInstance object. Both levels of information can be represented in both human and machine readable formats through standard R objects of class data.frame.

Fig. 4
figure 4

The optimr package structure

The optimSMS class is composed by several members: Descriptive strings name, sDes, and lDes; Model entities consts, sets, vars, and pars for constants (scalars), sets, decision variables and model parameters respectively; Relations are stored in eqs and terms, for the equations and the terms respectively, using a tree structure. It also has a bunch of methods to get and represent the SMS. Thus, we can get expressions of any model entity in a given format, e.g., GAMS or , or data structures containing the information. The creation and addition of elements in a SMS is made through specific functions. The models in Sect. 2 can be easily created using R scripts (see the optimr package documentation). Moreover, the inclusion of risk measures such as Conditional Value at Risk (CVaR) as described in Cano et al. (2014b) is also possible. Once the SMS is in an optimSMS object, any expression can be straightforwardly obtained. Combining different expressions and working with text in R, complex representations of the models can be produced.

As for the instance, i.e., the concrete model to be solved using specific data, it can be stored in optimInstance class objects. An instance always corresponds to a model, and, therefore, to create an optimInstance object it is needed an optimSMS object. Once created, elements (actual sets, parameter values and equations to include) are added to the instance, related to its SMS. The slots (members) of an instance can be also accessed easily using self-explained functions. Then, the optimization problem can be automatically generated in the appropriate format, e.g., a GAMS file, through a specific method, then solved with the own R optimization capabilities or calling an interface such as that included in the gdxrrw Footnote 10 package, creating an output file with the solution. Finally, the solution can be imported to the optimInstance object and present the results to the stakeholders. Note that at any point data analysis and visualization can be straightforwardly performed over the data, as they are stored in homogeneous and consistent data structures. Finally, the package and the framework is intended to be available for generic problems use, beyond the models and problem tackled in this article.

It is important to remark that the process described above and outlined in Fig. 4 fulfills, in an outstanding way, the stakeholders dialog approach represented in Fig. 1 and detailed throughout the paper. Examples of (downloadable) data and code to use with the optimr package can be found in Cano et al. (2015).

5 Concluding remarks

The model and DSS presented in this paper have been tested using real data from the EnRiMa project. Results demonstrate the importance of using stochastic strategic-operational models improving the outcomes of deterministic models, i.e., providing robust solutions for long-term energy supply planning under uncertainty and risks management. In particular, using average values, deterministic models provide degenerated solutions violating simplest energy supply security requirements and even being infeasible for all real scenarios.

Decision support is not a static action, but rather an iterative process that requires stakeholders dialogue. Moreover, strategic decisions under uncertainty require the application of advanced models that provide robust solutions against all the possible scenarios under security requirements. Applications of inadequate DSS (regarding data treatment, models’ structure, analysis of results, etc.) generates serious risks of adopting wrong policies and irreversible developments. The proposed framework explicitly deals with those requisites in a flexible and extensible way. The DSS’s model includes random horizons and stopping time moments, which are necessary to enforce the stakeholders-DSS dialogue at any point of a decision making process that may provide feedbacks to the DSS structure including the model and data. Reproducible research techniques can be applied over different decision problems and environments taking advantage of a common structure and acquired knowledge. Moreover, as remarked in Sect. 4, the framework fulfills one of the “Practitioner’s Wish List Towards Algebraic Modeling Systems”, which represents in fact an example of the stakeholders’ needs that this work solves. As already mentioned, the framework as a whole has been successfully implemented in the EnRiMa project, including complete models gathering the building energy features (Cano et al. 2014a) and risk management (Cano et al. 2016). Moreover, the optimr R package is available to be used with other models and instances.

Future work will include the use of the models in other real-world situations, exploring further energy features such as energy storage. As far as the R package is concerned, to enhance stakeholders dialogue capabilities, further formats will be implemented, in addition to the ones supported in the current version, i.e.,  and GAMS. Further research over these results will be the in-depth analysis of global policies and long-term uncertainty modeling, as well as the benchmarking of the strategic two-stage dynamic model against computationally-intensive multi-stage models. Definitely, the proposed idea of learning-by-doing based on the moving time horizon (Sect. 2.3) provided a way to escape from irreversible predetermined in advance (at \(t=0\)) decisions using adaptive endogenous scenario generators.