Upload
emilio-lopez-cano
View
141
Download
0
Tags:
Embed Size (px)
Citation preview
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
OptimizationInvestigacion Operativa Reproducible. Aplicacion a la
optimizacion de sistemas energeticos
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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 IntroductionReproducible Research
2 Integrated FrameworkSymbolic Model Specification
3 ApplicationThe EnRima ProjectDSS DescriptionSolver ManagerReporting
IV Jornadas de Usuarios de R, 2012 2/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 IntroductionReproducible Research
2 Integrated FrameworkSymbolic Model Specification
3 ApplicationThe EnRima ProjectDSS DescriptionSolver ManagerReporting
IV Jornadas de Usuarios de R, 2012 3/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 tiespecific instructions to data analysis andexperimental data so that results can berecreated, better understood and verified
IV Jornadas de Usuarios de R, 2012 4/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Workflow
NeedsStatistical Software
Data Visualization
Data Analysis
MathematicalRepresentation
Solver Input Generation
Output Documentation
IV Jornadas de Usuarios de R, 2012 5/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 boxCompiled software for specific solutions
IV Jornadas de Usuarios de R, 2012 6/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 IntroductionReproducible Research
2 Integrated FrameworkSymbolic Model Specification
3 ApplicationThe EnRima ProjectDSS DescriptionSolver ManagerReporting
IV Jornadas de Usuarios de R, 2012 7/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 Programmingcapabilities.
Integrated framework for SMS, data, equationsand solvers.
Data Analysis (pre- and post-), graphics andreporting.
IV Jornadas de Usuarios de R, 2012 8/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 mathematicalrepresentation of optimization models forall relevant energy subsystems and theirinteractions.
This mathematical representation iscomposed of variables, parameters, andrelations between them. Individualentities (variables and parameters) areidentified through the indices representingthe elements in different set.
IV Jornadas de Usuarios de R, 2012 9/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Outline
1 IntroductionReproducible Research
2 Integrated FrameworkSymbolic Model Specification
3 ApplicationThe EnRima ProjectDSS DescriptionSolver ManagerReporting
IV Jornadas de Usuarios de R, 2012 17/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 todevelop a decision-support system (DSS)for operators of energy-efficient buildingsand spaces of public use.
IV Jornadas de Usuarios de R, 2012 18/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Decision Scope
EnRiMaDSSStrategicModule
OperationalModule
StrategicDVs
StrategicConstraints
Upper-LevelOperational DVs
Upper-LevelEnergy-BalanceConstraints
Lower-LevelEnergy-BalanceConstraints
Lower-LevelOperational DVs
IV Jornadas de Usuarios de R, 2012 21/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Solution and reportSweave 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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
PP
SP
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
Pric
e (E
UR
/kW
h)
Energy Type
Electricity
NG
Energy Prices SimulationOptimisation Result − Operational Decisions
Technology by Year
Ope
ratio
n Le
vel
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
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 torepresent and solve the optimizationmodels developed within the EnRiMaDSS have been described
OutlookAlgebraic Modeling Languages for R solversand APIsExtend representation formats: HTML,ODF, . . .Further formats: AMPL, XML, . . .user-friendly inputrelease roptim library
IV Jornadas de Usuarios de R, 2012 32/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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 torepresent and solve the optimizationmodels developed within the EnRiMaDSS have been described
OutlookAlgebraic Modeling Languages for R solversand APIsExtend representation formats: HTML,ODF, . . .Further formats: AMPL, XML, . . .user-friendly inputrelease roptim library
IV Jornadas de Usuarios de R, 2012 32/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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’sFP7 project (number 260041)Project RIESGOS-CM: code S2009/ESP-1685AGORANET project (IPT-430000-2010-32)HAUS: IPT-2011-1049-430000EDUCALAB: IPT-2011-1071-430000DEMOCRACY4ALL: IPT-2011-0869-430000CORPORATE COMMUNITY: IPT-2011-0871-430000
IV Jornadas de Usuarios de R, 2012 33/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier 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. URLhttp://support.gams-software.com/doku.php?id=gdxrrw:
interfacing_gams_and_r. retrieved 2012-03-06.
Josef Kallrath. Algebraic modeling languages: Introduction and overview. InJosef Kallrath, editor, Algebraic Modeling Systems, volume 104 ofApplied Optimization, pages 3–10. Springer Berlin Heidelberg, 2012.ISBN 978-3-642-23591-7. doi: 10.1007/978-3-642-23592-4 1. URLhttp://dx.doi.org/10.1007/978-3-642-23592-4_1.
R Development Core Team. R: A Language and Environment for StatisticalComputing. 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 mathematicalprogramming, 2012. URL http://cran.r-project.org/.
IV Jornadas de Usuarios de R, 2012 34/35
ReproducibleOperations Research
IV Jornadas R
Emilio L. CanoJavier M. Moguerza
Introduction
Reproducible Research
Framework
Symbolic Model Specification
Application
EnRiMa Project
DSS Description
Solver Manager
Reporting
Bibliography
Discussion
¡ Gracias !
@emilopezcano
IV Jornadas de Usuarios de R, 2012 35/35