Investigación Operativa Reproducible. Aplicación a la o o optimización de sistemas energéticos
1. Reproducible
Operations Research
IV Jornadas R
Reproducible Operations Research.
Emilio L. Cano
Javier M. Moguerza An Application to Energy Systems
Introduction
Reproducible Research
Optimization
Framework
Symbolic Model Specification
Investigaci´n Operativa Reproducible. Aplicaci´n a la
o o
Application optimizaci´n de sistemas energ´ticos
o e
EnRiMa Project
DSS Description
Solver Manager
Reporting
Emilio L. Cano1 Javier M. Moguerza1
Bibliography
1 DEIO, 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 Outline
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
1 Introduction
Introduction
Reproducible Research
Reproducible Research
Framework
Symbolic Model Specification
Application
2 Integrated Framework
EnRiMa Project
DSS Description
Symbolic Model Specification
Solver Manager
Reporting
Bibliography 3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 2/35
3. Reproducible
Operations Research Outline
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
1 Introduction
Introduction
Reproducible Research
Reproducible Research
Framework
Symbolic Model Specification
Application
2 Integrated Framework
EnRiMa Project
DSS Description
Symbolic Model Specification
Solver Manager
Reporting
Bibliography 3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 3/35
4. Reproducible
Operations Research Reproducible OResearch
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
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 Workflow
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction Needs
Reproducible Research
Framework Statistical Software
Symbolic Model Specification
Application Data Visualization
EnRiMa Project
DSS Description
Solver Manager Data Analysis
Reporting
Bibliography
Mathematical
Representation
Solver Input Generation
Output Documentation
IV Jornadas de Usuarios de R, 2012 5/35
6. Reproducible
Operations Research Approaches
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Copy-paste
Introduction
Reproducible Research
Framework Inconsistencies
Symbolic Model Specification
Application Errors
EnRiMa Project
DSS Description
Solver Manager
Out-of-date
Reporting
Bibliography
non-reproducible
Painful changes
Black box
Compiled software for specific solutions
IV Jornadas de Usuarios de R, 2012 6/35
7. Reproducible
Operations Research Outline
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
1 Introduction
Introduction
Reproducible Research
Reproducible Research
Framework
Symbolic Model Specification
Application
2 Integrated Framework
EnRiMa Project
DSS Description
Symbolic Model Specification
Solver Manager
Reporting
Bibliography 3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 7/35
8. Reproducible
Operations Research R as an Integrated Environment
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Advantages
Introduction Open Source
Reproducible Research
Framework Reproducible Research and Literate Programming
Symbolic Model Specification
Application
capabilities.
EnRiMa Project
DSS Description
Solver Manager
Integrated framework for SMS, data, equations
Reporting
Bibliography
and solvers.
Data Analysis (pre- and post-), graphics and
reporting.
IV Jornadas de Usuarios de R, 2012 8/35
9. Reproducible
Operations Research Symbolic Model Specification
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
The SMS contains the mathematical
Reproducible Research
representation of optimization models for
Framework
Symbolic Model Specification all relevant energy subsystems and their
Application
EnRiMa Project
interactions.
DSS Description
Solver Manager
Reporting
This mathematical representation is
Bibliography
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 Data-driven Modelling
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
IV Jornadas de Usuarios de R, 2012 10/35
11. Reproducible
Operations Research Sets and Indices
IV Jornadas R
Emilio L. Cano
> head(SMSsets(model1SMS)[,c(1,3,4,6,7,8,9)])
Javier M. Moguerza
id tag sDes loc inSet aux subSet
Introduction 1 1 NA Energy-creating technology sub NA NA FALSE
Reproducible Research 2 2 NA Energy-storing technology sub NA NA FALSE
Framework
3 3 NA Type of energy sub NA NA FALSE
Symbolic Model Specification
4 4 NA Type of pollutant sub NA NA FALSE
5 5 NA Energy market sub NA NA FALSE
Application
EnRiMa Project
6 6 NA Long-term period sup NA NA FALSE
DSS Description
Solver Manager > cat(getSets(model1SMS, format = "tex", compact = FALSE))
Reporting
Bibliography 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 Decision Variables
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza > head(SMSvars(model1SMS)[,c(1,2,4, 7,9)])
Introduction id symbol sDes units ind
Reproducible Research 1 1 si Generators to be installed Devices 1, 6
Framework 2 2 sd Generators to be decommissioned Devices 1, 6, 9
Symbolic Model Specification 3 3 s Available generation capacity kW 1, 6
Application 4 4 xi Storing devices to be installed Devices 2, 6
EnRiMa Project 5 5 xd Storing devices to be decommissioned Devices 2, 6, 9
DSS Description 6 6 x Available storing capacity kWh 2, 6
Solver Manager
Reporting
> cat(getVars(model1SMS, format = "tex"))
Bibliography
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 Parameters
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza > head(SMSpars(model1SMS)[, c(1,2,4,7, 10)])
Introduction id symbol sDes units ind
Reproducible Research 1 1 D Energy demand kWh 3, 6, 7, 8
Framework 2 2 G Generation capacity kW/Device 1
Symbolic Model Specification 3 3 GS Storage capacity kW/Device 2
Application 4 4 AG Generation aging factor kW/kWh 1, 11
EnRiMa Project 5 5 AS Storage aging factor kW/kW 2, 11
DSS Description 6 6 AV Technology availability factor kW/kW 1, 6, 7, 8
Solver Manager
Reporting
> cat(getPars(model1SMS, format = "tex"))
Bibliography
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 Equations
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza > head(SMSeqs(model1SMS)[,c(1,2,6,7,8)])
Introduction id symbol nature relation domain
Reproducible Research 1 1 eqAvailg constraint eq 1, 6
Framework 2 2 eqAvails constraint eq 2, 6
Symbolic Model Specification 3 3 eqDecomLimg constraint lte 1, 6
Application 4 4 eqDecomLims constraint lte 2, 6
EnRiMa Project 5 5 eqEnergyBal constraint gte 3, 6, 7, 8
DSS Description 6 6 eqOutputCalc constraint eq 1, 6, 7, 8, 20
Solver Manager
Reporting
> head(model1SMS@terms[,c(1,6,7,8,9,10,11)])
Bibliography
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 Equations (cont.)
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework mathit{s}_{i}^{p} = mathit{G}_{i}^{} cdot
Symbolic Model Specification sum _{ mathit{a'} leq mathit{p} , mathit{a'}
Application geq mathit{0} } mathit{AG}_{i}^{mathit{p}-mathit{a'}}
EnRiMa Project cdot left ( mathit{si}_{i}^{mathit{a'}}-
DSS Description
sum _{ mathit{a''} leq mathit{p} ,
Solver Manager
Reporting
mathit{a''} > mathit{a'} }
Bibliography 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 Complete Model
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
IV Jornadas de Usuarios de R, 2012 16/35
17. Reproducible
Operations Research Outline
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
1 Introduction
Introduction
Reproducible Research
Reproducible Research
Framework
Symbolic Model Specification
Application
2 Integrated Framework
EnRiMa Project
DSS Description
Symbolic Model Specification
Solver Manager
Reporting
Bibliography 3 Application
The EnRima Project
DSS Description
Solver Manager
Reporting
IV Jornadas de Usuarios de R, 2012 17/35
18. Reproducible
Operations Research Objective
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
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 Consortium
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
IV Jornadas de Usuarios de R, 2012 19/35
20. Reproducible
Operations Research EnRiMa DSS
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
IV Jornadas de Usuarios de R, 2012 20/35
21. Reproducible
Operations Research Decision Scope
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction EnRiMaDSS
Reproducible Research Strate ic
g
Strategic DVs
Module
Framework
Symbolic Model Specification
Application
Strategic Upper-Level
EnRiMa Project
Constraints Operational DVs
DSS Description
Solver Manager
Reporting
Upper-Level Lower-Level
Bibliography Energy-Balance Operational DVs
Constraints
Lower-Level
Energy-Balance
Operational Constraints
Module
IV Jornadas de Usuarios de R, 2012 21/35
22. Reproducible
Operations Research Instance
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
IV Jornadas de Usuarios de R, 2012 22/35
23. Reproducible
Operations Research Instance (cont.)
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
> instancePars(model1Instance, "CI")[sort(sample(1:975,
10, FALSE )),]
Introduction
Reproducible Research
i p a value
Framework 251 CHP 22 19 1021.45984
Symbolic Model Specification
313 CHP 25 12 830.54032
Application 450 PV 16 4 18.57636
EnRiMa Project
476 PV 17 14 24.96507
DSS Description
Solver Manager
517 PV 20 1 17.00000
Reporting 578 PV 22 21 30.70389
Bibliography 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 Problem
IV Jornadas R
Emilio L. Cano > wProblem(example1Instance, "basicExample.gms", "gams", "lp")
Javier M. Moguerza
Introduction *GAMS file created with R
Reproducible Research $if NOT set outfile $set outfile outSol
Framework Sets
Symbolic Model Specification i Technology / RTE, PV, CHP/
j Period / winter, spring, summer, autumn/
Application t Year / 2013, 2014, 2015, 2016, 2017/
EnRiMa Project ;
DSS Description ...
Solver Manager parameter
Reporting D(j,t) Demand Level
Bibliography / 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 Problem (cont.)
IV Jornadas R
Positive variable y ;
Emilio L. Cano Positive variable s ;
Javier M. Moguerza ;
Equations
Introduction
eqAvail (i,t) Available technologies capacity calculation
Reproducible Research
eqDemand (j,t) Production plan for demand
Framework eqCapacity (i,j,t) Technologies capacity
Cost Total Cost
Symbolic Model Specification
;
Application
EnRiMa Project
eqAvail(i,t) .. s(i,t) =e= s(i,t-1)+x(i,t)-x(i,t-LT(i)) ;
DSS Description
eqDemand(j,t) .. Sum((i), y(i,j,t)) =e= D(j,t) ;
Solver Manager
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))))
Reporting
Bibliography
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 Architecture
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
IV Jornadas de Usuarios de R, 2012 26/35
27. Reproducible
Operations Research Architecture (cont.)
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application > # .... Data preparation
EnRiMa Project
> load("./data/exampleCMS.RData")
DSS Description
Solver Manager
> wProblem(mod1Instance, "example.gms", "gams", "lp")
Reporting > #
Bibliography > # 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 DSS Integration
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
IV Jornadas de Usuarios de R, 2012 28/35
29. Reproducible
Operations Research Solution and report
IV Jornadas R
Sweave file example:
Emilio L. Cano
Javier M. Moguerza
%
Introduction documentclass[a4paper]{article}
Reproducible Research
usepackage{Sweave}
Framework
Symbolic Model Specification
title{Example Symbolic Model Specification}
Application author{urjc}
EnRiMa Project
DSS Description
begin{document}
Solver Manager
Reporting
Bibliography 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 Solution and report (cont.)
IV Jornadas R
Emilio L. Cano
format = "tex",
Javier M. Moguerza solver = "lp" )
#generate gams file
Introduction wProblem(initStochImplem,
Reproducible Research filename = "myImplem.gms",
Framework format = "gams",
Symbolic Model Specification solver = "lp" )
Application @
EnRiMa Project
DSS Description section{Symbolic Model Specification}
Solver Manager
%Write the LaTeX equations
Reporting
Bibliography
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 Solution and report (cont.)
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza solverResults <- rgdx("mySol.gdx", lst)
#Some analysis and charts over solverResults object
Introduction @
Reproducible Research
Framework end{document}
Symbolic Model Specification
Application Optimisation Result − Operational Decisions
Energy Prices Simulation
EnRiMa Project
0.6
RTE
DSS Description
20
Solver Manager
0.4
Reporting 15
PP
Bibliography
10
0.2
Price (EUR/kWh)
Operation Level
5
Energy Type
Electricity
NG
CHP PV
0.6
20
15
0.4
SP
10
0.2
5
2013 2014 2015 2016 2017 2013 2014 2015 2016 2017
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 Technology by Year
IV Jornadas de Usuarios de R, 2012 31/35
32. Reproducible
Operations Research Summary
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza In this presentation the method used to
Introduction represent and solve the optimization
Reproducible Research
Framework models developed within the EnRiMa
Symbolic Model Specification
Application
DSS have been described
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
IV Jornadas de Usuarios de R, 2012 32/35
33. Reproducible
Operations Research Summary
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza In this presentation the method used to
Introduction represent and solve the optimization
Reproducible Research
Framework models developed within the EnRiMa
Symbolic Model Specification
Application
DSS have been described
EnRiMa Project
DSS Description
Solver Manager
Reporting
Outlook
Bibliography
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 Acknowledgements
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction R-project
Reproducible Research
Framework
Symbolic Model Specification
GAMS Software
Application
EnRiMa Project
EnRiMa project partners
DSS Description
Solver Manager
Reporting This work has been partially funded by the projects:
Bibliography
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 References
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
COIN-OR Foundation. Internet, 2012. URL http://www.coin-or.org/.
Introduction retrieved 2012-06-12.
Reproducible Research EnRiMa. Energy efficiency and risk management in public buildings.
Framework www.enrima-project.eu, 2012.
Symbolic Model Specification
GAMS. gdxrrw: interfacing gams and R. Internet, 2012. URL
Application http://support.gams-software.com/doku.php?id=gdxrrw:
EnRiMa Project
interfacing_gams_and_r. retrieved 2012-03-06.
DSS Description
Solver Manager Josef Kallrath. Algebraic modeling languages: Introduction and overview. In
Reporting
Bibliography
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 Discussion
IV Jornadas R
Emilio L. Cano
Javier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
¡ Gracias !
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography emilio.lopez@urjc.es
@emilopezcano
IV Jornadas de Usuarios de R, 2012 35/35