81
GAMS Development Corp. GAMS Software GmbH www.gams.com An Introduction Frederik Fiand & Tim Johannessen GAMS Software GmbH

Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GAMS Development Corp. GAMS Software GmbH www.gams.com

An Introduction

Frederik Fiand & Tim Johannessen

GAMS Software GmbH

Content

ALl

Head

Page 2: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

2

Agenda

GAMS at a Glance

GAMS - Hands On Examples

APIs - Application Programming Interfaces to GAMS

Outlook - Some Advanced GAMS Features

Page 3: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

3

Company

Roots: World Bank, 1976

Went commercial in 1987

Locations GAMS Development Corporation (Washington) GAMS Software GmbH (Germany)

Product: The General Algebraic Modeling System

Page 4: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

4

What did this give us?

Simplified model development & maintenance

Increased productivity tremendously

Made mathematical optimization available to a broader audience (domain experts)

2012 INFORMS Impact Prize

Page 5: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

5

Broad User Community and Network

25+ Years GAMS Development

11,500+ licenses

Users: 50% academic, 50% commercial

GAMS used in more than 120 countries

Uniform interface to more than 30 solvers

Page 6: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

6

Broad Range of Application Areas

25+ Years GAMS Development

Agricultural Economics Applied General Equilibrium

Chemical Engineering Economic Development

Econometrics Energy

Environmental Economics Engineering

Finance Forestry

International Trade Logistics

Macro Economics Military

Management Science/OR Mathematics

Micro Economics Physics

Page 7: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

7

Foundation of GAMS

Powerful algebraic modeling language

Open architecture and interfaces to other systems, independent layers

Page 8: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

8

Powerful Declarative Language

Similar to mathematical notation

Easy to learn - few basic language elements: sets, parameters, variables, equations, models

Model is executable (algebraic) description of the problem

Page 9: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

9

Mix of Declarative and Imperative Elements

Advantages: Build complex problem algorithms within GAMS Simplified interaction with other systems: Data exchange GAMS process control

Control Flow Statements (e.g. loops, for, if,…), macros and functions

Page 10: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

10

Strong Development Environment

GAMS IDE Project management Editor / Syntax coloring / Spell checks Tree view / Syntax-error navigation Model Debugging & Profiling Solver selection & setup Data viewer

Export Charting

GAMS Processes Control

Page 11: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

11

Independence of Model and Operating System

Platforms supported by GAMS:

Model

Platform Solver Data Interface

Models can be moved between platforms with ease!

Page 12: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

12

Independence of Model and Solver

All major commercial LP/MIP solver

Open Source Solver (COIN) Also solver for NLP, MINLP,

global, and stochastic optimization

One environment for a wide range of model types and solvers

Switching between solvers with one line of code!

Model

Platform Solver Data Interface

Page 13: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

13

Independence of Model and Data

Application

GAMS

SOLVER GDX

• Declarative Modeling • ASCII: Initial model development

• GDX: Data layer (“contract”) between GAMS and applications – Platform independent – No license required – Direct GDX interfaces and

general API – …

Model

Platform Solver Data Interface

Page 14: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

14

Independence of Model and User Interface

API’s

• Low Level • Object Oriented: .Net, Java,

Python • No modeling capability:

Model is written in GAMS • Wrapper class that

encapsulates a GAMS model

Model

Platform Solver Data Interface

Page 15: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

15

Smart Links to other Applications

MS Excel

• User keeps working in his productive tool environment • Application accesses all optimization capabilities of GAMS through API • Visualization and analysis of model data and results in the application

Model

Platform Solver Data Interface

Page 16: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

16

Smart Links to other Applications

MatLab

• User keeps working in his productive tool environment • Application accesses all optimization capabilities of GAMS through API • Visualization and analysis of model data and results in the application

Model

Platform Solver Data Interface

Page 17: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

17

Smart Links to other Applications

R

• User keeps working in his productive tool environment • Application accesses all optimization capabilities of GAMS through API • Visualization and analysis of model data and results in the application

Model

Platform Solver Data Interface

Page 18: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

18

Striving for Innovation and Compatibility

Models must benefit from:

Advancing hardware / New Platforms

Enhanced / new solver and solution technology

Improved / upcoming interfaces to other systems

New Modeling Concepts

Protect investments of Users

Life time of a model: 15+ years

New maintainer, platform, solver, user interface

Backward Compatibility

Software Quality Assurance

Page 19: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

19

Free Model Libraries

More than 1400 models!

Page 20: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

20

Why GAMS?

• Experience of 25+ years • Broad user community from different areas • Lots of model templates • Strong development interface

• Consistent implemenation of design principles

– Simple, but powerful modeling language – Independent layers – Open architecture: Designed to interact with other

applications

• Open for new developments • Protecting investments of users

Page 21: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

21

Agenda

GAMS at a Glance

GAMS - Hands On Examples

APIs - Application Programming Interfaces to GAMS

Outlook - Some Advanced GAMS Features

Page 22: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

22

A Simple Transportation Problem

What does this example show?

It gives a first glimpse of how a problem can be formulated in

GAMS

It shows how easy it is to change model type and, consequently,

solver technology

It shows some basics of data exchange with GAMS

Page 23: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

23

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 24: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

24

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 25: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

25

Canning Plants (supply) Markets (demand) shipments

A Simple Transportation Problem

(Number of cases)

Seattle

(350)

San Diego

(600)

Topeka

(275) Chicago

(300) New York

(325)

Freight: $90 case / thousand miles

Page 26: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

26

Minimize Transportation cost subject to Demand satisfaction at markets Supply constraints

350

San Diego 600

275

300

325

Topeka 1.4

2.5

1.8

1.8 1.7 2.5

Supply (cases)

Demand (cases)

Distance (thousand miles)

New York

Chicago

Seattle

Freight: $90 case / thousand miles

A Simple Transportation Problem

Page 27: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

27

Mathematical Model Formulation

Indices: 𝑖 (Canning plants) 𝑗 (Markets) Decision variables: 𝑥𝑖𝑗 (Number of cases to ship)

Data: 𝑐𝑖𝑗 (Transport cost per case)

𝑎𝑖 (Capacity in cases) 𝑏𝑖 (Demand in cases) min 𝑐𝑖𝑗 ∙ 𝑥𝑖𝑗𝑗𝑖 (Minimize total transportation cost)

subject to 𝑥𝑖𝑗𝑗 ≤ 𝑎𝑖 ∀ 𝑖 (Shipments from each plant ≤ supply capacity)

𝑥𝑖𝑗𝑖 ≥ 𝑏𝑗 ∀ 𝑗 (Shipments to each market ≥ demand)

𝑥𝑖𝑗 ≥ 0 ∀𝑖, 𝑗 (Do not ship from market to plant)

𝑖, 𝑗 ∈ ℕ

Page 28: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

28

GAMS Syntax (LP Model)

Page 29: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

29

GAMS Syntax (LP Model)

Hands-On

Page 30: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

30

GAMS Syntax (Data Input)

Page 31: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

31

GAMS Syntax (Data Input)

Page 32: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

32

GAMS Syntax (Data Input)

Page 33: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

33

Solution to LP model Canning Plants (supply) Markets (demand)

shipments

(Number of cases)

Seattle

(350)

San Diego

(600)

Topeka

(275) Chicago

(300) New York

(325)

Freight: $90 case / thousand miles Total cost: $153,675

275

0

0

300

275

50

Page 34: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

34

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 35: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

35

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 36: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

36

MIP Model: Minimum Shipment of 100 cases

• Shipment volume: x (continuous variable)

• Discrete decision: ship (binary variable)

add constraints: 𝑥𝑖,𝑗 ≥ 100 ∙ 𝑠ℎ𝑖𝑝𝑖,𝑗 ∀ 𝑖, 𝑗 (if ship=1, then ship at least 100)

𝑥𝑖,𝑗 ≤ 𝑏𝑖𝑔𝑀 ∙ 𝑠ℎ𝑖𝑝𝑖,𝑗 ∀ 𝑖, 𝑗 (if ship=0, then do not ship at all)

𝑠ℎ𝑖𝑝𝑖,𝑗 ∈ 0,1

100

ship = 0 ship = 1

0

Cost ($)

Not possible

x (Number of cases)

Page 37: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

37

MIP Model: GAMS Syntax

Page 38: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

38

MIP Model: GAMS Syntax

Hands-On

Page 39: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

39

MIP Model: Results

Page 40: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

40

MIP Model: Solution Canning Plants (supply) Markets (demand)

shipments

(Number of cases)

Seattle

(350)

San Diego

(600)

Topeka

(275) Chicago

(300) New York

(325)

Freight: $90 case / thousand miles Total cost: $153,675

275

0

100

200

175

150

Page 41: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

41

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 42: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

42

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty, e.g. uncertain demand

Page 43: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

43

MINLP: Cost Savings

100

ship = 0 ship = 1

0

Cost ($)

Not possible

The cost per case

decreases with a

increasing shipment

volume

Replace: min 𝑐𝑖𝑗 ∙ 𝑥𝑖𝑗𝑗𝑖 (Minimize total transportation cost)

With

min 𝑐𝑖𝑗 ∙ 𝑥𝑖𝑗𝒃𝒆𝒕𝒂

𝑗𝑖 (Minimize total transportation cost)

x (Number of cases)

Page 44: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

44

MINLP Model: GAMS Syntax

Page 45: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

45

MINLP Model: GAMS Syntax

Hands-On

Page 46: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

46

MINLP Model: Results

Page 47: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

47

MINLP Model: Solution Canning Plants (supply) Markets (demand)

shipments

(Number of cases)

Seattle

(350)

San Diego

(600)

Topeka

(275) Chicago

(300) New York

(325)

Freight: $90 case / thousand miles Total cost: $153,675

275

0

100

200

175

150

Page 48: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

48

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty,

e.g. uncertain demand

Page 49: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

49

Model types in this example

• Determine minimum transportation cost. Result: city to city shipment volumes.

LP

MIP

MINLP

• Allows discrete decisions, e.g. if we ship, then we ship at least 100 cases.

• Allows non-linearity,

e.g. a smooth decrease in unit cost when shipping volumes grows

SP • Allows uncertainty,

e.g. uncertain demand

Page 50: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

50

Stochastic Programming in GAMS EMP

Information (uncertain Par.)

Reformulated Model

Solution

Ma

pp

ing

So

lutio

n

Into

ori

gin

al sp

ace

Deterministic Model

Translation

Solve with established Algorithms

EMP/SP Simple interface to add uncertainty to

existing deterministic models (EMP) Keywords to describe

uncertainty include: discrete and parametric random variables, stages, chance constraints, Value at Risk, ...

Available solution methods: Automatic generation of

Deterministic Equivalent (can be solved with any solver)

Specialized commercial algorithms (DECIS, LINDO)

Page 51: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

51

Transport Example - Uncertain Demand

bf

Prob: 0.3 Val: 0.90

Prob: 0.5 Val: 1.00

Prob: 0.2 Val: 1.10

Decisions to make

First-stage decision: How many units should be shipped “here and now” (without knowing the outcome)

Second-stage (recourse) decision: How can the model react if we do not ship enough? Penalties for “bad” first-stage decisions, e.g. buy additional

cases u(j) at the demand location: costsp .. z =e= sum((i,j), c(i,j)*x(i,j))+

sum(j,0.3*u(j));

demandsp(j) .. sum(i, x(i,j)) =g= bf*b(j) - u(j) ;

Uncertain demand factor bf

Page 52: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

52

Uncertain Demand - GAMS Algebra

Page 53: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

53

Uncertain Demand - GAMS Algebra

Hands-On

Page 54: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

54

Uncertain Demand - Results

Page 55: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

55

Stochastic Program: Solution Canning Plants (supply) Markets (demand)

shipments

(Number of cases)

Seattle

(350)

San Diego

(600)

Topeka

(~275) Chicago

(~300) New York

(~325)

Freight: $90 case / thousand miles Total cost: $158,588

275

0

0

300

242.5

50

Page 56: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

56

Stochastic Programming in GAMS

• The Extended Mathematical Programming (EMP) framework is used to replace parameters in the model by random variables

• Support for Multi-stage recourse problems and chance constraint models

• Easy to add uncertainty to existing deterministic models, to either use specialized algorithms or create Deterministic Equivalent (new free solver DE)

• More information: http://www.gams.com/dd/docs/solvers/empsp.pdf

49

Page 57: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

57

Agenda

GAMS at a Glance

GAMS - Hands On Examples

APIs - Application Programming Interfaces to GAMS

Outlook - Some Advanced GAMS Features

Page 58: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

58

Calling GAMS from your Application

Creating Input for GAMS Model

Data handling using GDX API

Callout to GAMS

GAMS option settings using Option API Starting GAMS using GAMS API

Reading Solution from GAMS Model

Data handling using GDX API

Application GDX

GAMS SOLVER

Page 59: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

59

• Low level APIs • GDX, OPT, GAMSX, GMO, …

• High performance and flexibility

• Automatically generated imperative APIs for several languages (C, Delphi, Java, Python, C#, …)

• Object Oriented GAMS API • Additional layer on top of the low level APIs

• Object Oriented

• Written by hand to meet the specific requirements of different Object Oriented languages

Low level APIs Object Oriented API

Page 60: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

60

• Scenario solves of the transportation problem

• Features:

• Preparation of input data

• Loading data from Access file

• Solving multiple scenarios of a model

• Displaying results

• Four implementation steps:

1. Graphical User Interface

2. Preparation of GAMS model

3. Implementation of scenario solving using GAMSJob

4. GAMSModelInstance for performance improvements

Transport Application GUI Example

Page 61: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

61

• Scenario solves of the transportation problem

• Features:

• Preparation of input data

• Loading data from Access file

• Solving multiple scenarios of a model

• Displaying results

• Four implementation steps:

1. Graphical User Interface

2. Preparation of GAMS model

3. Implementation of scenario solving using GAMSJob

4. GAMSModelInstance for performance improvements

Transport Application GUI Example

Hands-On

Page 62: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

62

Agenda

GAMS at a Glance

GAMS - Hands On Examples

APIs - Application Programming Interfaces to GAMS

Outlook - Some Advanced GAMS Features

Page 63: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

63

Model transport /all/ ;

Option solvelink = { %Solvelink.ChainScript%,

%Solvelink.CallScript%,

%Solvelink.CallModule%,

%Solvelink.AsyncGrid%,

%Solvelink.AsyncSimulate%,

%Solvelink.LoadLibrary%};

solve transport using lp minimizing z;

Solvelink Option controls GAMS function when linking to solve

Page 64: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

64

Model transport /all/ ;

Option solvelink = { %Solvelink.ChainScript%,

%Solvelink.CallScript%,

%Solvelink.CallModule%,

%Solvelink.AsyncGrid%,

%Solvelink.AsyncSimulate%,

%Solvelink.LoadLibrary%};

solve transport using lp minimizing z;

• ChainScript [0]: Solver process, GAMS vacates memory

+ Maximum memory available to solver

+ protection against solver failure (hostile link)

- swap to disk

Solvelink Option controls GAMS function when linking to solve

Page 65: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

65

• Call{Script [1]/Module [2]}: Solver process, GAMS stays live

+ protection against solver failure (hostile link)

+ no swap of GAMS database

- file based model communication

Solvelink Option – cont.

Page 66: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

66

• Call{Script [1]/Module [2]}: Solver process, GAMS stays live

+ protection against solver failure (hostile link)

+ no swap of GAMS database

- file based model communication

• LoadLibrary [5]: Solver DLL in GAMS process

+ fast memory based model communication

+ update of model object inside the solver (hot start)

- not supported by all solvers

Solvelink Option – cont.

Page 67: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

67

trnsport.gms (LP) solved 500 times with CPLEX:

Simple Serial Solve - Performance

Page 68: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

68

Setting Solve time (secs)

Solvelink=%Solvelink.ChainScript% 54.368

Solvelink=%Solvelink.CallModule% 42.909

Solvelink=%Solvelink.LoadLibrary% 05.039

trnsport.gms (LP) solved 500 times with CPLEX:

Simple Serial Solve - Performance

The solvelink option controls GAMS function when linking

to solve.

Hands-On

Page 69: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

69

Scenario Solver

Generation

Solution

Update

Simple Serial Solve Loop

Scenario Solver/GUSS

Generates model once and updates the algebraic model keeping the model “hot” inside the solver.

Loop

Generation

Solution

Update

Page 70: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

70

trnsport.gms (LP) solved 500 times with CPLEX:

Scenario Solver/GUSS - Performance

Setting Solve time (secs)

Solvelink=%Solvelink.ChainScript% 54.368

Solvelink=%Solvelink.CallModule% 12.909

Solvelink=%Solvelink.LoadLibrary% 05.039

GUSS 01.947

Page 71: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

71

Scenario Solver/GUSS - Performance

Setting Solve time (secs)

Loop: Solvelink=%Solvelink.Chainscript (default) 7,204

Loop: Solvelink=%Solvelink.LoadLibrary% 2,481

GAMS Scenario Solver 392

CPLEX Concert Technology 210

18.3

1.86

Factor

Example: Stochastic model with 66,320 linear problems

Page 72: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

72

Grid Computing Facility GAMS jobs in a distributed environment Scalable: supports large grids, but also works on

local machine Platform independent, works with all

solvers/model types Only minor changes to model required

GAMS

Solve Job 2

Solve Job ..

Solution Collection

Solve Job 1

Solve Job n

Job Submission

GAMS

Solve Job 1

Process solution information

Submit Job 1

Solve Job n

Process solution information

Page 73: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

73

Grid Computing Facility – Example 1 GAMS Model Library: trnsgrid

Page 74: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

74

Grid Computing Facility – Example 1 GAMS Model Library: trnsgrid

Hands-On

Page 75: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

75

Grid Computing Facility – Example 2 GAMS Model Library: tgridmix

Page 76: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

76

Grid Computing Facility – Example 2 GAMS Model Library: tgridmix

Hands-On

Page 77: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

77

Solving “many” Scenarios How to find the right approach?

1. Small Ratio of solver time / GAMS time Scenario Solver

2. Large ratio i.e. only solver time is relevant (pre/post processing not critical) Grid Computing Facility

3. Entire model run including pre processing / optimization / post processing is costly Parallel execution of entire model in the cloud

Page 78: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

78

Scenario Solver and Parallel Combined

Implementation Number of MIP models

Solve time Rest of algorithm

Total time

Traditional GAMS loop

100,000 1068 sec 169 sec 1237 sec

Scenario Solver 100,000 293 sec 166 sec 459 sec

Implementation Number of MIP models

Worker Threads

Parallel sub-problem time

Rest of algorithm (serial)

Total time

Parallel + Scenario Solver

100,000 4 116 sec 67 sec 183 sec

http://yetanothermathprogrammingconsultant.blogspot.de/2012/04/parallel-gams-jobs-2.html

Application - Scenario Solver

Page 79: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

79

Where to Find Help?

• Documentation Center: http://gams.com/help/index.jsp

• Support Wiki: http://support.gams.com/

• Mailing List(s): http://gams.com/maillist/index.htm

• YouTube Channel: https://www.youtube.com/user/GAMSLessons

• GAMS support: [email protected]

Meet us at the GAMS booth!

Page 80: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GENERAL ALGEBRAIC MODELING SYSTEM

80

Other GAMS Talks

BEAM-ME: Acceleration Strategies for Energy System Models

Given by: Frederik Fiand When: Thursday (Sep. 01), 09:00-09:30 Where: Hörsaal 3 Abstract: BEAM-ME is a project funded by the German Federal Ministry for Economic Affairs and Energy (BMWi) and addresses the need for new and improved solution approaches for energy system models. The project unites various partners with complementary expertise from the fields of algorithms, computing and application development. The con- sidered problems result in large-scale LPs that are computationally in- tractable for state-of-the-art solvers. Hence, new solution approaches combining decomposition methods, algorithm development and high performance computing are developed. We provide an overview on the large variety of challenges we are facing within this project, present current solutions approaches and provide first results.

Recent Enhancements in GAMS

Given by: Franz Nelissen When: Thursday (Sep. 01), 11:30-12:00 Where: Seminarraum 105 Abstract: Algebraic Modeling Languages (AML) are one of the success stories in Operations Research. GAMS is one of the prominent AMLs and has evolved continuously in response to user requirements, changes in computing environments and advances in the theory and practice of mathematical programing. In this talk we will begin with some fundamental principles and outline several recent enhancements of GAMS supporting efficient and productive development of optimization based decision support applications.

Page 81: Con tent ALl · GAMS at a Glance GAMS - Hands On Examples ... broader audience (domain experts) ... Broad User Community and Network 25+ Years GAMS Development 11,500+ licenses Users:

GAMS Development Corp. GAMS Software GmbH www.gams.com

Thank You Europe

GAMS Software GmbH P.O. Box 40 59

50216 Frechen, Germany Phone: +49 221 949 9170 Fax: +49 221 949 9171

[email protected]

USA GAMS Development Corp. 1217 Potomac Street, NW Washington, DC 20007, USA Phone: +1 202 342 0180 Fax: +1 202 342 0181 [email protected]