an integrated solver manager: using r and python for energy systems optimization

28
Energy Systems Planning useR! 2013 Emilio L. Cano Introduction Motivation DSS Solver Manager Architecture Components Example A simplified model Model instance Solution An integrated Solver Manager: using R and Python for energy systems optimization Emilio L. Cano 1 Antonio Alonso Ayuso 1 Javier M. Moguerza 1 Felipe Ortega 1 1 DEIO, Universidad Rey Juan Carlos, Madrid The R user Conference 2013 Albacete July 10-12 2013 The R User Conference 2013 1/27

Upload: emilio-lopez-cano

Post on 19-Jun-2015

454 views

Category:

Technology


5 download

DESCRIPTION

Presentation at the R User Conference 2013, Albacete, Spain

TRANSCRIPT

Page 1: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

An integrated Solver Manager:

using R and Python for energy systems

optimization

Emilio L. Cano1 Antonio Alonso Ayuso1

Javier M. Moguerza1 Felipe Ortega1

1DEIO, Universidad Rey Juan Carlos, Madrid

The R user Conference 2013Albacete July 10-12 2013

The R User Conference 2013 1/27

Page 2: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Outline

1 IntroductionMotivationDSS

2 Solver ManagerArchitectureComponents

3 ExampleA simplified modelModel instanceSolution

The R User Conference 2013 2/27

Page 3: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Outline

1 IntroductionMotivationDSS

2 Solver ManagerArchitectureComponents

3 ExampleA simplified modelModel instanceSolution

The R User Conference 2013 3/27

Page 4: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Global changes, local challenges

GlobalRegulations:emissions,efficiency

De-regulations:market

Global warming

Resources scarcity

Global markets

LocalUsers’ confort

Security

Availability

Limited budget

New options

The R User Conference 2013 4/27

Page 5: An integrated Solver Manager: using R and Python for energy systems optimization

Building systems enery flow: Sankey diagram

Page 6: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Decision Support Systems

The R User Conference 2013 6/27

Page 7: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

EnRiMa DSS

The R User Conference 2013 7/27

Page 8: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Outline

1 IntroductionMotivationDSS

2 Solver ManagerArchitectureComponents

3 ExampleA simplified modelModel instanceSolution

The R User Conference 2013 8/27

Page 9: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

DSS Integration

The R User Conference 2013 9/27

Page 10: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Solver Manager

The R User Conference 2013 10/27

Page 11: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

SM Interface - overview

The SM Interface allows to separatecommunication tasks and other interaction

features from the core features of the SolverManager

The R User Conference 2013 11/27

Page 12: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

SM Interface (Python)

Model

Tasks

Data

Interaction

Logs

The R User Conference 2013 12/27

Page 13: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Solver Manager core script

Instance checking

Input datapreparation

Call to theOptimiser

Result checking

Output datapreparation

Control and log

Librariesoptimr:optimSMS andoptimInstance S4objects

gdxrrw: GAMSInterface

The R User Conference 2013 13/27

Page 14: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Solver Manager process flow

The R User Conference 2013 14/27

Page 15: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Outline

1 IntroductionMotivationDSS

2 Solver ManagerArchitectureComponents

3 ExampleA simplified modelModel instanceSolution

The R User Conference 2013 15/27

Page 16: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Optimization model

min∑t∈T

(∑i∈I

CI ti · x ti +

∑i∈I,j∈J

CO ti ,j · DT t

j · y ti ,j

)

s.t. : s ti = s t−1i + x ti − x

t−LT ii ∀ i ∈ I, t ∈ T∑

i∈I

y ti ,j = D t

j ∀ j ∈ J , t ∈ T

y ti ,j ≤ G t

i ,j · s ti ∀ i ∈ I, j ∈ J , t ∈ T

The R User Conference 2013 16/27

Page 17: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Symbolic Model Specification

showClass("optimSMS")

## Class "optimSMS" [package "optimr"]

##

## Slots:

##

## Name: consts sets vars pars

## Class: data.frame data.frame data.frame data.frame

##

## Name: eqs terms name sDes

## Class: data.frame data.frame character character

##

## Name: lDes

## Class: character

data(mod1SMS)

The R User Conference 2013 17/27

Page 18: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

SMS Sets and Variables

SMSsets(mod1SMS)

## id symbol tag sDes lDes loc inSet setType dataCom

## 1 1 i NA Technology NA sub NA set NA

## 2 2 j NA Period NA sub NA set NA

## 3 3 t NA Year NA sup NA set NA

## ordered setDom

## 1 NA NA

## 2 NA NA

## 3 NA NA

SMSvars(mod1SMS)[, c(1:4, 11)]

## id symbol tag sDes ind

## 1 1 x NA Capacity to be installed 1, 3

## 2 2 y NA Production plan 1, 2, 3

## 3 3 s NA Available capacity 1, 3

## 4 4 z NA Total cost NULL

The R User Conference 2013 18/27

Page 19: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

SMS parameters and expressions

SMSpars(mod1SMS)[, c(1:4, 7, 12)]

## id symbol tag sDes units ind

## 1 1 LT NA Lifetime years 1

## 2 2 D NA Demand Level kW 2, 3

## 3 3 G NA Technology Availability kW/kW 1, 2, 3

## 4 4 CI NA Investment Cost EUR/kW 1, 3

## 5 5 CO NA Operational Cost EUR/kWh 1, 2, 3

## 6 6 DT NA Duration time of period hours 2, 3

getExpr(mod1SMS, "vars", 2, "gams")

## [1] "y(i,j,t)"

The R User Conference 2013 19/27

Page 20: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

SMS equations

SMSeqs(mod1SMS)[1:4, c(1, 2, 5, 6, 7)]

## id symbol lDes nature relation

## 1 1 aux1 NA aux eq

## 2 2 aux2 NA aux eq

## 3 3 eqAvail NA constraint eq

## 4 4 eqDemand NA constraint eq

mod1SMS@terms[1:4, c(1, 6:10)]

## id eq side parent nature item

## 1 1 1 l NA sets 3

## 2 2 1 r 0 sets 3

## 3 3 1 r 0 consts 1

## 4 1 2 l NA sets 3

getEq(mod1SMS, 5, "tex")

## [1] " \\mathit{y}_{i,j}^{t} \\leq \\mathit{G}_{i,j}^{t} \\cdot \\mathit{s}_{i}^{t} \\quad {\\forall \\;i \\in \\mathcal{I},\\; j \\in \\mathcal{J},\\; t \\in \\mathcal{T}}"

The R User Conference 2013 20/27

Page 21: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Optimization Instance

showClass("optimInstance")

## Class "optimInstance" [package "optimr"]

##

## Slots:

##

## Name: id name sDes lDes sets

## Class: integer character character character list

##

## Name: vars pars eqs sms

## Class: list list list optimSMS

The R User Conference 2013 21/27

Page 22: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Instance data

names(mod1Instance@pars)

## [1] "LT" "CI" "D" "G" "DT" "CO"

head(instancePars(mod1Instance, "CI"), 4)

## i t value

## 1 PV 2013 700

## 2 CHP 2013 1182

## 3 PV 2014 490

## 4 CHP 2014 1123

instanceSets(mod1Instance, "i")

## [1] "RTE" "PV" "CHP"

The R User Conference 2013 22/27

Page 23: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Getting the solution

setwd("~/gamsdir")

wProblem(mod1Instance, "mod1.gms", "gams", "lp")

library(gdxrrw)

igdx("~/Programs/gams")

## The GDX library has been loaded

## GDX library load path: /home/emilio/Programs/gams

gams("mod1.gms")

## [1] 0

importGams(mod1Instance) <- "outSolDeterministic1.gdx"

instanceVars(mod1Instance, "x")

## i t value

## 1 RTE 2013 6.30

## 2 PV 2015 17.50

## 3 PV 2016 1.75

## 4 CHP 2013 1.40The R User Conference 2013 23/27

Page 24: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Late motivation

Joseph Kallrath (2012). AlgebraicModeling Systems, Springer. Chapter12: A Practioner’s Wish List TowardsAlgebraic Modeling Systems

“The automatic generation of a model’sdocumentation in LATEX would be very helpfulfor mathematicians, physicists, astronomers,and other communities publishing in LATEX.”

The R User Conference 2013 24/27

Page 25: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Summary

New challenges for building managers.

Decision Support Systems are needed.

Solver Manager: flexible and extensible.

OutlookImprove optimr packageMore complex instancesMore modeling and optimization softwares,solvers, alogorithms and benchmarking.

The R User Conference 2013 25/27

Page 26: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Summary

New challenges for building managers.

Decision Support Systems are needed.

Solver Manager: flexible and extensible.

OutlookImprove optimr packageMore complex instancesMore modeling and optimization softwares,solvers, alogorithms and benchmarking.

The R User Conference 2013 25/27

Page 27: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Acknowledgements

This work has been partially funded by theproject Energy Efficiency and RiskManagement in Public Buildings (EnRiMa)EC’s FP7 project (number 260041)

We also acknowledge the projects:OPTIMOS3 (MTM2012-36163-C06-06)Project RIESGOS-CM: code S2009/ESP-1685HAUS: IPT-2011-1049-430000EDUCALAB: IPT-2011-1071-430000DEMOCRACY4ALL: IPT-2011-0869-430000CORPORATE COMMUNITY: IPT-2011-0871-430000CONTENT & INTELIGENCE: IPT-2012-0912-430000

and the Young Scientists Summer Program (YSSP) at the InternationalInstitute of Applied Systems Analysis (IIASA).

The R User Conference 2013 26/27

Page 28: An integrated Solver Manager: using R and Python for energy systems optimization

Energy SystemsPlanning

useR! 2013

Emilio L. Cano

Introduction

Motivation

DSS

Solver Manager

Architecture

Components

Example

A simplified model

Model instance

Solution

Discussion

Thanks !

[email protected]

@emilopezcanohttp://www.proyectum.es

The R User Conference 2013 27/27