Reproducible Operations Research IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Application Reproducible Operations Research. An Application to Energy Systems Optimization Investigación Operativa Reproducible. Aplicación a la optimización de sistemas energéticos EnRiMa Project DSS Description Solver Manager Reporting Bibliography Emilio L. Cano1 1 DEIO, Javier M. Moguerza1 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 Reproducible Operations Research Outline IV Jornadas R Emilio L. Cano Javier M. Moguerza 1 Introduction Reproducible Research 2 Integrated Framework Symbolic Model Specification 3 Application The EnRima Project DSS Description Solver Manager Reporting Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography IV Jornadas de Usuarios de R, 2012 2/35 Reproducible Operations Research Outline IV Jornadas R Emilio L. Cano Javier M. Moguerza 1 Introduction Reproducible Research 2 Integrated Framework Symbolic Model Specification 3 Application The EnRima Project DSS Description Solver Manager Reporting Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography IV Jornadas de Usuarios de R, 2012 3/35 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 Reproducible Operations Research Workflow IV Jornadas R Emilio L. Cano Javier M. Moguerza Needs Introduction Reproducible Research Statistical Software Framework Symbolic Model Specification Data Visualization Application EnRiMa Project DSS Description Data Analysis Solver Manager Reporting Bibliography Mathematical Representation Solver Input Generation Output Documentation IV Jornadas de Usuarios de R, 2012 5/35 Reproducible Operations Research Approaches IV Jornadas R Emilio L. Cano Javier M. Moguerza Copy-paste Introduction Reproducible Research Inconsistencies Errors Out-of-date non-reproducible Painful changes Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography Black box Compiled software for specific solutions IV Jornadas de Usuarios de R, 2012 6/35 Reproducible Operations Research Outline IV Jornadas R Emilio L. Cano Javier M. Moguerza 1 Introduction Reproducible Research 2 Integrated Framework Symbolic Model Specification 3 Application The EnRima Project DSS Description Solver Manager Reporting Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography IV Jornadas de Usuarios de R, 2012 7/35 Reproducible Operations Research R as an Integrated Environment IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Advantages Open Source Reproducible Research Framework Symbolic Model Specification Application Reproducible Research and Literate Programming capabilities. EnRiMa Project DSS Description Solver Manager Reporting Integrated framework for SMS, data, equations and solvers. Bibliography Data Analysis (pre- and post-), graphics and reporting. IV Jornadas de Usuarios de R, 2012 8/35 Reproducible Operations Research Symbolic Model Specification 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 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 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 Reproducible Operations Research Sets and Indices IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project > head(SMSsets(model1SMS)[,c(1,3,4,6,7,8,9)]) 1 2 3 4 5 6 id tag sDes loc inSet aux subSet 1 NA Energy-creating technology sub NA NA FALSE 2 NA Energy-storing technology sub NA NA FALSE 3 NA Type of energy sub NA NA FALSE 4 NA Type of pollutant sub NA NA FALSE 5 NA Energy market sub NA NA FALSE 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 Reproducible Operations Research Decision Variables IV Jornadas R Emilio L. Cano Javier M. Moguerza > head(SMSvars(model1SMS)[,c(1,2,4, 7,9)]) Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description 1 2 3 4 5 6 id symbol sDes 1 si Generators to be installed 2 sd Generators to be decommissioned 3 s Available generation capacity 4 xi Storing devices to be installed 5 xd Storing devices to be decommissioned 6 x Available storing capacity units ind Devices 1, 6 Devices 1, 6, 9 kW 1, 6 Devices 2, 6 Devices 2, 6, 9 kWh 2, 6 Solver Manager Reporting Bibliography > 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 Reproducible Operations Research Parameters IV Jornadas R Emilio L. Cano Javier M. Moguerza > head(SMSpars(model1SMS)[, c(1,2,4,7, 10)]) Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description 1 2 3 4 5 6 id symbol sDes units ind 1 D Energy demand kWh 3, 6, 7, 8 2 G Generation capacity kW/Device 1 3 GS Storage capacity kW/Device 2 4 AG Generation aging factor kW/kWh 1, 11 5 AS Storage aging factor kW/kW 2, 11 6 AV Technology availability factor kW/kW 1, 6, 7, 8 Solver Manager Reporting Bibliography > 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 Reproducible Operations Research Equations IV Jornadas R Emilio L. Cano Javier M. Moguerza > head(SMSeqs(model1SMS)[,c(1,2,6,7,8)]) Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description 1 2 3 4 5 6 id symbol 1 eqAvailg 2 eqAvails 3 eqDecomLimg 4 eqDecomLims 5 eqEnergyBal 6 eqOutputCalc nature relation domain constraint eq 1, 6 constraint eq 2, 6 constraint lte 1, 6 constraint lte 2, 6 constraint gte 3, 6, 7, 8 constraint eq 1, 6, 7, 8, 20 Solver Manager Reporting Bibliography > head(model1SMS@terms[,c(1,6,7,8,9,10,11)]) 1 2 3 4 5 6 id eq side parent nature item setSums 1 1 l NA vars 3 NA 2 1 r NA pars 2 NA 3 1 r 2 pars 4 NA 4 1 r 3 vars 1 NA 5 1 r 3 vars 2 NA 1 2 l NA vars 6 NA > cat(getEq(model1SMS, 1, format = "tex")) IV Jornadas de Usuarios de R, 2012 14/35 Reproducible Operations Research Equations (cont.) 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 \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 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 Reproducible Operations Research Outline IV Jornadas R Emilio L. Cano Javier M. Moguerza 1 Introduction Reproducible Research 2 Integrated Framework Symbolic Model Specification 3 Application The EnRima Project DSS Description Solver Manager Reporting Introduction Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography IV Jornadas de Usuarios de R, 2012 17/35 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 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 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 Reproducible Operations Research Decision Scope IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Strategic DVs Framework EnRiMaDSS Strategic Module Symbolic Model Specification Application EnRiMa Project DSS Description Upper-Level Operational DVs Strategic Constraints Solver Manager Upper-Level Energy-Balance Constraints Reporting Bibliography Operational Module IV Jornadas de Usuarios de R, 2012 Lower-Level Operational DVs Lower-Level Energy-Balance Constraints 21/35 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 Reproducible Operations Research Instance (cont.) 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 > instancePars(model1Instance, "CI")[sort(sample(1:975, 10, FALSE )),] i p 251 CHP 22 313 CHP 25 450 PV 16 476 PV 17 517 PV 20 578 PV 22 581 PV 23 586 PV 23 669 Wind 6 758 Wind 15 a value 19 1021.45984 12 830.54032 4 18.57636 14 24.96507 1 17.00000 21 30.70389 2 17.51000 7 20.29889 3 212.18000 2 206.00000 > instanceSets(model1Instance, c("i")) [1] "CHP" "PV" "Wind" IV Jornadas de Usuarios de R, 2012 23/35 Reproducible Operations Research Problem IV Jornadas R Emilio L. Cano Javier M. Moguerza > wProblem(example1Instance, "basicExample.gms", "gams", "lp") Introduction *GAMS file created with R $if NOT set outfile $set outfile outSol Reproducible Research Framework Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography 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 Reproducible Operations Research Problem (cont.) IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Positive variable Positive variable ; y ; 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 ; Application EnRiMa Project DSS Description Solver Manager Reporting 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)))) 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, IV Jornadas de Usuarios de R, 2012 x, y, s, z ; 25/35 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 Reproducible Operations Research Architecture (cont.) 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 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 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 Reproducible Operations Research Solution and report IV Jornadas R Sweave file example: Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research % \documentclass[a4paper]{article} \usepackage{Sweave} Framework Symbolic Model Specification Application \title{Example Symbolic Model Specification} \author{urjc} EnRiMa Project DSS Description Solver Manager \begin{document} 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 Reproducible Operations Research Solution and report (cont.) IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Application format = "tex", solver = "lp" ) #generate gams file wProblem(initStochImplem, filename = "myImplem.gms", format = "gams", solver = "lp" ) @ EnRiMa Project DSS Description Solver Manager Reporting Bibliography \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 Reproducible Operations Research Solution and report (cont.) IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction solverResults <- rgdx("mySol.gdx", lst) #Some analysis and charts over solverResults object @ Reproducible Research Framework \end{document} Symbolic Model Specification Application Optimisation Result − Operational Decisions Energy Prices Simulation EnRiMa Project RTE 0.6 DSS Description 20 Solver Manager 0.4 15 PP Reporting Bibliography 10 Energy Type Electricity NG 0.6 Operation Level Price (EUR/kWh) 0.2 5 CHP PV 20 15 0.4 SP 10 0.2 5 2013 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 IV Jornadas de Usuarios de R, 2012 2014 2015 2016 2017 2013 2014 2015 2016 2017 Technology by Year 31/35 Reproducible Operations Research Summary IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Application In this presentation the method used to represent and solve the optimization models developed within the EnRiMa DSS have been described EnRiMa Project DSS Description Solver Manager Reporting Bibliography IV Jornadas de Usuarios de R, 2012 32/35 Reproducible Operations Research Summary IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework Symbolic Model Specification Application In this presentation the method used to represent and solve the optimization models developed within the EnRiMa DSS have been described EnRiMa Project DSS Description Solver Manager Reporting Bibliography 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 Reproducible Operations Research Acknowledgements IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction R-project Reproducible Research Framework GAMS Software Symbolic Model Specification 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 Reproducible Operations Research References 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 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 Reproducible Operations Research Discussion IV Jornadas R Emilio L. Cano Javier M. Moguerza Introduction Reproducible Research Framework ¡ Gracias ! Symbolic Model Specification Application EnRiMa Project DSS Description Solver Manager Reporting Bibliography [email protected] @emilopezcano IV Jornadas de Usuarios de R, 2012 35/35