GamsTutorial_rev1

  • Upload
    meca12

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

  • 8/2/2019 GamsTutorial_rev1

    1/24

    DEPARTAMENTO DE INGENIERA CIVIL. HIDRULICA Y ENERGTICA

    MASTER Y PROGRAMA DE DOCTORADO:SISTEMAS DE INGENIERA CIVIL

    ANLISIS DE SISTEMAS APLICADO A LA INGENIERA CIVIL------------------------------

    PROGRAMA DE DOCTORADO:

    ANLISIS DE SISTEMAS APLICADO A RECURSOS HIDRULICOS

    GAMS TUTORIAL--------------------------

    TUTORIAL DE GAMS

  • 8/2/2019 GamsTutorial_rev1

    2/24

    0. Index

    1. Introduction

    2. Basic features

    3. Case study

    6. GAMS output

    5. Basic GAMS statements

    8. Flow control expressions

    4. Structure of a GAMS model

    7. GAMS options

    9. GAMS solvers and links to other programs

    10. Useful references

  • 8/2/2019 GamsTutorial_rev1

    3/24

    -GAMS (General Algebraic Modelling System) is aprogramming language that allows modelling, analyzing

    and solving a wide variety of optimization problems

    -Main highlights:

    i. Modelling and solution processes are separated to

    each other

    ii. The model representation is pretty similar to theproblem mathematical formulation

    iii. It allows easily solving very large problems

    iv. It is a very versatile tool

    v. With only few commands, it is possible to solve

    large complex problems

    1. Introduction

  • 8/2/2019 GamsTutorial_rev1

    4/24

    -There exist some other algebraic modelling languages,such as:

    AMPL

    http://www.ampl.com AIMMS

    http://www.aimms.com

    X-PRESShttp://www.fico.com/en/Products/DMTools/Pages/FICO-Xpress-Optimization-Suite.aspx

    WHATS BESThttp://www.lindo.com/products/lingo/lingom.html

    LINGO

    http://www.lindo.com/products/lingo/lingom.html

    1. Introduction

  • 8/2/2019 GamsTutorial_rev1

    5/24

    2. Basic features

    -GAMS compiler does not distinguish between upper- andlower case letters

    - GAMS commands can be used both in singular and plural

    -It is advisable to terminate every statement with asemicolon (;)

    - Statements can be written in any order provided that

    no entity (data, variables, constraints, etc.) is referencedbefore it has been declared

    - Names assigned to data, variables, etc., must start with

    a letter and must not coincide with any of the reservedwords

    - Explanatory comments can be included either with an

    asterisk (*) in the first column or directly after declaring

    commands

  • 8/2/2019 GamsTutorial_rev1

    6/24

    3. Case study

    CLASSIC TRANSPORTATION PROBLEM

    - Certain company is planning its shipping activities from

    two different canning plants to three different markets

    - A consultant engineer has evaluated the demand for the

    product manufactured by the company in the three

    markets

    - Canning plants shall not exceed their corresponding

    maximum capacities

  • 8/2/2019 GamsTutorial_rev1

    7/24

    3. Case study

    -The transportation cost per ton of product is 90 $ perthousand miles

    -Determine the amount of tons to be shipped from eachcanning plant to each market so as to minimize the total

    transportation cost

  • 8/2/2019 GamsTutorial_rev1

    8/24

    3. Case study Mathematical formulation

  • 8/2/2019 GamsTutorial_rev1

    9/24

    4. Structure of a GAMS model

    Indices

    Given data

    Dec. var

    Const. & O.f.

  • 8/2/2019 GamsTutorial_rev1

    10/24

    5. Basic statements - Indices

    - Set(s): are the basic building blocks of a GAMS model andcorrespond to the indices in the algebraic representation

    - Elements shall be written in slashes / /

    - Elements are stored as characters strings

    - An (*) indicates that the elements follow a sequence

    - It is possible to define subsets of already defined sets

    or relationships among elements of already defined sets

    very useful to define the arcs of a network

  • 8/2/2019 GamsTutorial_rev1

    11/24

    5. Basic statements - Data

    - Scalar(s)

    - Parameter(s)

    - Table(s)

  • 8/2/2019 GamsTutorial_rev1

    12/24

    5. Basic statements - Data

    -Data can be declared and assigned values in differentstatements

    - It is possible make assignments for specific elements

  • 8/2/2019 GamsTutorial_rev1

    13/24

    5. Basic statements - Variables

    -Variables declaration

    -Types of variables

    - Variables attributes

  • 8/2/2019 GamsTutorial_rev1

    14/24

    5. Basic statements - Equations

    -Equations declaration

    - Relational and arithmetic operators in equations

    -

    Equations definition

  • 8/2/2019 GamsTutorial_rev1

    15/24

    5. Basic statements Model & Solve

    - Model specifies which of the defined equations take partin the model

    - Solve asks GAMS for solving the problem

    family of solvers

  • 8/2/2019 GamsTutorial_rev1

    16/24

    6. GAMS output

    - Echo print: copy of the input file- Error messages: one of the most useful GAMS features

    - Equation & Column listing: did GAMS interpret themodel properly?

  • 8/2/2019 GamsTutorial_rev1

    17/24

    6. GAMS output

    - Model statistics: last section before invoking the solver

    - Status reports: brief summary after execution

    - Display

  • 8/2/2019 GamsTutorial_rev1

    18/24

    7. GAMS options

  • 8/2/2019 GamsTutorial_rev1

    19/24

    8. Flow control expressions

    -Relational and logic operators in conditional expressions

    - Dollar condition ($): very useful, among other things, todiscretize state equations

    - Conditional expressions can not contain variables

  • 8/2/2019 GamsTutorial_rev1

    20/24

    8. Flow control expressions

    -If-Elseif-Else statement

    e.g.

  • 8/2/2019 GamsTutorial_rev1

    21/24

    8. Flow control expressions

    -Loop statement

    e.g.

    - While statement

    e.g.

  • 8/2/2019 GamsTutorial_rev1

    22/24

    8. Flow control expressions

    -Dynamic sets

  • 8/2/2019 GamsTutorial_rev1

    23/24

    9. GAMS solvers and links to other programs

    -Some common solvers: CPLEX

    MINOS

    CONOPT BARON

    -Default solver (and options): File Options Solvers

    - GAMS can pass data from and to (read and write) other

    programs

    Text files, HTML Excel

    Matlab

  • 8/2/2019 GamsTutorial_rev1

    24/24