Reproducible Operations Research. An Application to Energy Systems Optimization
1. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Reproducible Operations Research.
An Application to Energy Systems
Optimization
Investigaci´on Operativa Reproducible. Aplicaci´on a la
optimizaci´on de sistemas energ´eticos
Emilio L. Cano1
Javier M. Moguerza1
1DEIO, Universidad Rey Juan Carlos, Madrid
IV Jornadas de Usuarios de R, Barcelona
15 y 16 de noviembre de 2012
IV Jornadas de Usuarios de R, 2012 1/35
2. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 Introduction
Reproducible Research
2 Integrated Framework
Symbolic Model Specification
3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 2/35
3. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 Introduction
Reproducible Research
2 Integrated Framework
Symbolic Model Specification
3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 3/35
4. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Reproducible OResearch
The goal of reproducible research is to tie
specific instructions to data analysis and
experimental data so that results can be
recreated, better understood and verified
IV Jornadas de Usuarios de R, 2012 4/35
5. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Workflow
Needs
Statistical Software
Data Visualization
Data Analysis
Mathematical
Representation
Solver Input Generation
Output Documentation
IV Jornadas de Usuarios de R, 2012 5/35
6. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Approaches
Copy-paste
Inconsistencies
Errors
Out-of-date
non-reproducible
Painful changes
Black box
Compiled software for specific solutions
IV Jornadas de Usuarios de R, 2012 6/35
7. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 Introduction
Reproducible Research
2 Integrated Framework
Symbolic Model Specification
3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 7/35
8. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
R as an Integrated Environment
Advantages
Open Source
Reproducible Research and Literate Programming
capabilities.
Integrated framework for SMS, data, equations
and solvers.
Data Analysis (pre- and post-), graphics and
reporting.
IV Jornadas de Usuarios de R, 2012 8/35
9. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Symbolic Model Specification
The SMS contains the mathematical
representation of optimization models for
all relevant energy subsystems and their
interactions.
This mathematical representation is
composed of variables, parameters, and
relations between them. Individual
entities (variables and parameters) are
identified through the indices representing
the elements in different set.
IV Jornadas de Usuarios de R, 2012 9/35
10. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Data-driven Modelling
IV Jornadas de Usuarios de R, 2012 10/35
11. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Sets and Indices
> head(SMSsets(model1SMS)[,c(1,3,4,6,7,8,9)])
id tag sDes loc inSet aux subSet
1 1 NA Energy-creating technology sub NA NA FALSE
2 2 NA Energy-storing technology sub NA NA FALSE
3 3 NA Type of energy sub NA NA FALSE
4 4 NA Type of pollutant sub NA NA FALSE
5 5 NA Energy market sub NA NA FALSE
6 6 NA Long-term period sup NA NA FALSE
> cat(getSets(model1SMS, format = "tex", compact = FALSE))
begin{description}
item[$i$] Energy-creating technology.
item[$j$] Energy-storing technology.
item[$k$] Type of energy.
item[$l$] Type of pollutant.
item[$n$] Energy market.
item[$p$] Long-term period.
item[$m$] Mid-term period.
item[$t$] Short-term period.
item[$a$] Technology age. a = 0,...,P-1
end{description}
IV Jornadas de Usuarios de R, 2012 11/35
12. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Decision Variables
> head(SMSvars(model1SMS)[,c(1,2,4, 7,9)])
id symbol sDes units ind
1 1 si Generators to be installed Devices 1, 6
2 2 sd Generators to be decommissioned Devices 1, 6, 9
3 3 s Available generation capacity kW 1, 6
4 4 xi Storing devices to be installed Devices 2, 6
5 5 xd Storing devices to be decommissioned Devices 2, 6, 9
6 6 x Available storing capacity kWh 2, 6
> cat(getVars(model1SMS, format = "tex"))
begin{description}
... ...
item[$ mathit{s}_{i}^{p}$] Available generation capacity (kW).
... ...
item[$ mathit{r}_{j,k}^{p,m,t}$] Energy stored (kWh).
item[$ mathit{c}_{}^{}$] TotalCost (EUR).
item[$ mathit{e}_{}^{p,m,t}$] Primary energy consumed (kWh).
end{description}
IV Jornadas de Usuarios de R, 2012 12/35
13. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Parameters
> head(SMSpars(model1SMS)[, c(1,2,4,7, 10)])
id symbol sDes units ind
1 1 D Energy demand kWh 3, 6, 7, 8
2 2 G Generation capacity kW/Device 1
3 3 GS Storage capacity kW/Device 2
4 4 AG Generation aging factor kW/kWh 1, 11
5 5 AS Storage aging factor kW/kW 2, 11
6 6 AV Technology availability factor kW/kW 1, 6, 7, 8
> cat(getPars(model1SMS, format = "tex"))
begin{description}
item[$ mathit{D}_{k}^{p,m,t}$] Energy demand (kWh).
item[$ mathit{G}_{i}^{}$] Generation capacity (kW/Device).
item[$ mathit{GS}_{j}^{}$] Storage capacity (kW/Device).
... ...
item[$ mathit{IL}_{}^{}$] Investment limit (EUR).
... ...
end{description}
IV Jornadas de Usuarios de R, 2012 13/35
14. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Equations
> head(SMSeqs(model1SMS)[,c(1,2,6,7,8)])
id symbol nature relation domain
1 1 eqAvailg constraint eq 1, 6
2 2 eqAvails constraint eq 2, 6
3 3 eqDecomLimg constraint lte 1, 6
4 4 eqDecomLims constraint lte 2, 6
5 5 eqEnergyBal constraint gte 3, 6, 7, 8
6 6 eqOutputCalc constraint eq 1, 6, 7, 8, 20
> head(model1SMS@terms[,c(1,6,7,8,9,10,11)])
id eq side parent nature item setSums
1 1 1 l NA vars 3 NA
2 2 1 r NA pars 2 NA
3 3 1 r 2 pars 4 NA
4 4 1 r 3 vars 1 NA
5 5 1 r 3 vars 2 NA
6 1 2 l NA vars 6 NA
> cat(getEq(model1SMS, 1, format = "tex"))
IV Jornadas de Usuarios de R, 2012 14/35
15. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Equations (cont.)
mathit{s}_{i}^{p} = mathit{G}_{i}^{} cdot
sum _{ mathit{a'} leq mathit{p} , mathit{a'}
geq mathit{0} } mathit{AG}_{i}^{mathit{p}-mathit{a'}}
cdot left ( mathit{si}_{i}^{mathit{a'}}-
sum _{ mathit{a''} leq mathit{p} ,
mathit{a''} > mathit{a'} }
mathit{sd}_{i}^{mathit{a'},mathit{a''}} right)
qquad forall ;i in mathcal{I},; p in mathcal{P}
IV Jornadas de Usuarios de R, 2012 15/35
16. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Complete Model
IV Jornadas de Usuarios de R, 2012 16/35
17. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 Introduction
Reproducible Research
2 Integrated Framework
Symbolic Model Specification
3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 17/35
18. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Objective
The overall objective of EnRiMa is to
develop a decision-support system (DSS)
for operators of energy-efficient buildings
and spaces of public use.
IV Jornadas de Usuarios de R, 2012 18/35
19. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Consortium
IV Jornadas de Usuarios de R, 2012 19/35
20. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
EnRiMa DSS
IV Jornadas de Usuarios de R, 2012 20/35
21. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Decision Scope
EnRiMaDSS
Strategic
Module
Operational
Module
StrategicDVs
Strategic
Constraints
Upper-Level
Operational DVs
Upper-Level
Energy-Balance
Constraints
Lower-Level
Energy-Balance
Constraints
Lower-Level
Operational DVs
IV Jornadas de Usuarios de R, 2012 21/35
22. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Instance
IV Jornadas de Usuarios de R, 2012 22/35
23. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Instance (cont.)
> instancePars(model1Instance, "CI")[sort(sample(1:975,
10, FALSE )),]
i p a value
251 CHP 22 19 1021.45984
313 CHP 25 12 830.54032
450 PV 16 4 18.57636
476 PV 17 14 24.96507
517 PV 20 1 17.00000
578 PV 22 21 30.70389
581 PV 23 2 17.51000
586 PV 23 7 20.29889
669 Wind 6 3 212.18000
758 Wind 15 2 206.00000
> instanceSets(model1Instance, c("i"))
[1] "CHP" "PV" "Wind"
IV Jornadas de Usuarios de R, 2012 23/35
24. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Problem
> wProblem(example1Instance, "basicExample.gms", "gams", "lp")
*GAMS file created with R
$if NOT set outfile $set outfile outSol
Sets
i Technology / RTE, PV, CHP/
j Period / winter, spring, summer, autumn/
t Year / 2013, 2014, 2015, 2016, 2017/
;
...
parameter
D(j,t) Demand Level
/ winter .2013 = 5.25
spring .2013 = 5.83333333333333
...
autumn .2017 = 7.75833333333333
/ ;
Variables
x(i, t)
y(i, j, t)
s(i, t)
z
;
Positive variable x ;
IV Jornadas de Usuarios de R, 2012 24/35
25. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Problem (cont.)
Positive variable y ;
Positive variable s ;
;
Equations
eqAvail (i,t) Available technologies capacity calculation
eqDemand (j,t) Production plan for demand
eqCapacity (i,j,t) Technologies capacity
Cost Total Cost
;
eqAvail(i,t) .. s(i,t) =e= s(i,t-1)+x(i,t)-x(i,t-LT(i)) ;
eqDemand(j,t) .. Sum((i), y(i,j,t)) =e= D(j,t) ;
eqCapacity(i,j,t) .. y(i,j,t) =l= G(i,j,t)*s(i,t) ;
Cost .. z =e= Sum((t), (Sum((i), CI(i,t)*x(i,t))+Sum((i,j), CO(i,j,t)*DT(j,t)*y(i,j,t))))
Model Deterministic1 /all/;
solve Deterministic1 using lp minimizing z ;
scalars modelstat, solvestat, obj;
modelstat = Deterministic1.modelstat;
solvestat = Deterministic1.solvestat;
obj = Deterministic1.objVal;
execute_unload '%outfile%', modelstat, solvestat, obj, x, y, s, z ;
IV Jornadas de Usuarios de R, 2012 25/35
26. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Architecture
IV Jornadas de Usuarios de R, 2012 26/35
27. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Architecture (cont.)
> # .... Data preparation
> load("./data/exampleCMS.RData")
> wProblem(mod1Instance, "example.gms", "gams", "lp")
> #
> # solve
> gams("example.gms --outfile=exampleSol.gdx")
> #
> ## import solution
> oldOpt <- options(stringsAsFactors= FALSE)
> importGams(model1Instance)<- "exampleSol.gdx"
> options(oldOpt)
> #
> getsolution(model1Instance)
IV Jornadas de Usuarios de R, 2012 27/35
28. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
DSS Integration
IV Jornadas de Usuarios de R, 2012 28/35
29. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Solution and report
Sweave file example:
%
documentclass[a4paper]{article}
usepackage{Sweave}
title{Example Symbolic Model Specification}
author{urjc}
begin{document}
maketitle
section{Data analysis}
<<>>=
# Some code for importing the
# Symbolic Model and analyzing the
# input data ...
#Generate tex file
wProblem(myImplem,
filename = "myImplem.tex",
IV Jornadas de Usuarios de R, 2012 29/35
30. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Solution and report (cont.)
format = "tex",
solver = "lp" )
#generate gams file
wProblem(initStochImplem,
filename = "myImplem.gms",
format = "gams",
solver = "lp" )
@
section{Symbolic Model Specification}
%Write the LaTeX equations
input{myImplem}
section{Call to solver}
<<>>=
require(gdxrrw)
gams("myImplem.gms --outfile=mySol.gdx")
@
section{Solution Analysis}
<<>>=
lst <- list(name='solvestat',form='full',compress=TRUE)
IV Jornadas de Usuarios de R, 2012 30/35
31. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Solution and report (cont.)
solverResults <- rgdx("mySol.gdx", lst)
#Some analysis and charts over solverResults object
@
end{document}
0.2
0.4
0.6
0.2
0.4
0.6
PPSP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Time Periods
Price(EUR/kWh)
Energy Type
Electricity
NG
Energy Prices Simulation
Optimisation Result − Operational Decisions
Technology by Year
OperationLevel 5
10
15
20
2013 2014 2015 2016 2017
CHP
2013 2014 2015 2016 2017
PV
5
10
15
20
RTE
IV Jornadas de Usuarios de R, 2012 31/35
32. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Summary
In this presentation the method used to
represent and solve the optimization
models developed within the EnRiMa
DSS have been described
IV Jornadas de Usuarios de R, 2012 32/35
33. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Summary
In this presentation the method used to
represent and solve the optimization
models developed within the EnRiMa
DSS have been described
Outlook
Algebraic Modeling Languages for R solvers
and APIs
Extend representation formats: HTML,
ODF, . . .
Further formats: AMPL, XML, . . .
user-friendly input
release roptim library
IV Jornadas de Usuarios de R, 2012 32/35
34. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Acknowledgements
R-project
GAMS Software
EnRiMa project partners
This work has been partially funded by the projects:
Energy Efficiency and Risk Management in Public Buildings (EnRiMa) EC’s
FP7 project (number 260041)
Project RIESGOS-CM: code S2009/ESP-1685
AGORANET project (IPT-430000-2010-32)
HAUS: IPT-2011-1049-430000
EDUCALAB: IPT-2011-1071-430000
DEMOCRACY4ALL: IPT-2011-0869-430000
CORPORATE COMMUNITY: IPT-2011-0871-430000
IV Jornadas de Usuarios de R, 2012 33/35
35. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
References
COIN-OR Foundation. Internet, 2012. URL http://www.coin-or.org/.
retrieved 2012-06-12.
EnRiMa. Energy efficiency and risk management in public buildings.
www.enrima-project.eu, 2012.
GAMS. gdxrrw: interfacing gams and R. Internet, 2012. URL
http://support.gams-software.com/doku.php?id=gdxrrw:
interfacing_gams_and_r. retrieved 2012-03-06.
Josef Kallrath. Algebraic modeling languages: Introduction and overview. In
Josef Kallrath, editor, Algebraic Modeling Systems, volume 104 of
Applied Optimization, pages 3–10. Springer Berlin Heidelberg, 2012.
ISBN 978-3-642-23591-7. doi: 10.1007/978-3-642-23592-4 1. URL
http://dx.doi.org/10.1007/978-3-642-23592-4_1.
R Development Core Team. R: A Language and Environment for Statistical
Computing. R Foundation for Statistical Computing, Vienna, Austria,
2012. URL http://www.R-project.org/. ISBN 3-900051-07-0.
Stefan Theussl. CRAN task view: Optimization and mathematical
programming, 2012. URL http://cran.r-project.org/.
IV Jornadas de Usuarios de R, 2012 34/35
36. Reproducible
Operations Research
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Discussion
¡ Gracias !
emilio.lopez@urjc.es
@emilopezcano
IV Jornadas de Usuarios de R, 2012 35/35