Vous êtes sur la page 1sur 17

Introduction To Applied Optimization

GAMS TUTORIAL

GAMS Basics
GAMS: General Algebraic Modeling System (GAMS) High-level modeling system for mathematical programming and optimization Useful only for solving optimization problems

Student version (with restrictions on number of variables and number of constraints) available at: http://www.gams.com/
2 BioE 494

GAMS Basics
GAMS advantages:
Problem representation is much simpler: Intuitive representation due to the representation syntax Various output options to analyze the results and carry out debugging Incorporates different solvers for the given problem and various options to select desired solver properties Possible to define an integer variable

GAMS disadvantages:
No option for data visualization No option to include breakpoints to debug the code Performs only optimization: Cannot carry out other related tasks such as ODE simulation.
3 BioE 494

GAMS Environment

Single window to write and execute the code

4 BioE 494

GAMS Model Components

5 BioE 494

Set Declaration
Very important aspect of a GAMS model Declaration necessary for multi-dimensional parameter/variable declaration Simple set example:
courses={BioE 123, BioE 234, BioE 345} set courses / BioE 123, BioE 234, BioE 345 / ;

Sequence set:
Year={2000, 2001, 2002, 2010} set Year /2000 * 2010/ ;

Multiple sets with the same elements:


alias(Year,Horizon) ; Another set named Horizon created with same elements
6 BioE 494

Data Declaration: Scalar


Single dimensional constant value Syntax:
scalar scalar name / value /; scalar MaxCredits / 12 /; scalar MaxCredits / 12 / scalar MinCredits / 8 /;

Semicolon only at the end of the particular type declaration

7 BioE 494

Data Declaration: Parameters


Lists of constant data (list of scalars) Declared over a predefined set Prior definition of a set with correct dimension is necessary Syntax:
parameter(s) parameter name / element1 value1, element2 value2, .. /; parameter Number_of_Students(courses) / BioE123 24, BioE234 21, BioE 345 17 /; Important to use the right set for defining the data
8 BioE 494

Data Declaration: Tables


Multi-dimensional data for constants Prior definition of a sets with correct dimension is necessary Syntax:
table table name Declaration of the data in table format

Data of number of students in each class in each year


table StudentInfo(year,courses)
BioE 123 BioE 234 BioE 345

2001 2002 2003 2004 2010

12 15 21 18 21

34 31 33 21 31

25 30 32 22 26;

Data alignment important Semicolan at the end of the data entry

9 BioE 494

Data Access
Data accessing for parameters and tables is different Parameter defined as: parameter Number_of_Students(courses) / BioE123 24, BioE234 21, BioE 345 17 /; I want to know the number of students taking BioE123 Number_of_Students(1) ---- WRONG Syntax Correct: Number_of_Students(BioE 123) I want to know the number of students taking BioE234 in 2003 Correct: StudentInfo(2002,BioE 234) This is a fundamental difference from the programming philosophy of MATLAB, FORTRAN, C etc.
10 BioE 494

Variable Declaration
Variables: Unknown quantities which are computed as the solution of the problem Variables are part of the equations (constraints and objective) defined in the optimization problem Syntax:
variable variable name(set name)

Different types of variables can be defined:



BioE 494

free (with no bounds): This is the default declaration positive variable negative variable binary variable integer variable
11

Equations
Used to define constraints and objectives An inequality is also defined as an equation Equation declaration
equations Equation1(set) name of the equation Equation2(set) name of the equation;

Equation definition
Equation_name(set).. actual equation ..

Equation types:
=e= =l= =g=
BioE 494

Equality Less than or equal to Greater than or equal to


12

Model and Solve Statements


Once all the problem information has been written, model statement is used to formulate the model Syntax:
model mode_name model description / list of equations to be included in the model /;

If all the defined equations are to be included:


model mode_name model description / all /;

Solve statement to ask GAMS to solve using a particular model type


solve model_name using model_type maximizing/minimzing variable_name;
13 BioE 494

Example Problem from LP


Example linear programming problem:
Min 4x1-x2 Subject to: 2x1 + x2 8 x2 5 x1 - x2 4 x1 0, x2 0

14 BioE 494

Example Problem from LP

Press F9 to execute the code Errors are listed in the output list file and the solution is not reported 15
BioE 494

Example Problem from LP

16 BioE 494

Important Model Types


The list of models that can be defined in GAMS
LP = Linear programming NLP = Nonlinear programming MIP = Mixed integer (linear) programming MINLP = Mixed integer nonlinear programming RMIP = Relaxed mixed integer (linear) programming RMINLP = Relaxed mixed integer nonlinear programming

17 BioE 494

Vous aimerez peut-être aussi