GAMS: A POWERFUL OPTIMIZATION TOOL AND ITS INTERFACE TO MATLAB - - PowerPoint PPT Presentation
GAMS: A POWERFUL OPTIMIZATION TOOL AND ITS INTERFACE TO MATLAB - - PowerPoint PPT Presentation
GAMS: A POWERFUL OPTIMIZATION TOOL AND ITS INTERFACE TO MATLAB Muhammad Ismail Outline 2 Introduction GAMS Input File GAMS Output MATLAB Interface Introduction 3 - GAMS = General Algebraic Modeling System - Model linear, nonlinear, and
SLIDE 1
SLIDE 2
Outline
Introduction GAMS Input File GAMS Output MATLAB Interface
2
SLIDE 3
Introduction
- GAMS = General Algebraic Modeling System
- Model linear, nonlinear, and mixed integer
- ptimization problems
- GAMS can be downloaded from its home page:
http://www.gams.com/
- Without a valid GAMS license, GAMS will operate as
a free demo with limitations on number of constraints and variables [GAMS license is placed, when available, in the GAMS directory]
3
SLIDE 4
GAMS Structure and MATLAB Interface
GAMS Input File (name.gms) GAMS Output File (name.lst) GAMS Compilation Optimization Solver MATLAB
4
SLIDE 5
Outline
Introduction GAMS Input File GAMS Output MATLAB Interface
5
SLIDE 6
GAMS Input File Structure
Sets Data Variables Equations Model & Call Solver Correspond to indices in you problem Can be: parameters, tables, and scalar Can be: free (-β,+β), +ve, -ve, binary, integer Equalities and inequalities LP , NLP , MIP , MINLP
6
SLIDE 7
Problem Example
- Consider π networks with overlapped coverage and π users
- Out of π users, we have:
π1 users can get service (bandwidth) using only single-network π2 users can get service (bandwidth) using all available networks, i.e. multi-homing
- Obj.: Find network assignment for single-network users and
bandwidth allocation for both single-network and multi-homing users which maximizes some utility function
7
SLIDE 8
Mathematical Formulation
Max {log 1 + π¦πππππ β ππππ¦πππππ}
π π
S.t. πΆπππ,π β€ π¦πππππ β€ πΆπππ¦,π
π
βπ π¦ππ = 1, π¦ππ = 0,1 , βπ β π1
π
π¦ππ = 1, βπ β π2 Assignment variable Binary Bandwidth allocation variable Positive Priority parameter Matrix ο¨ Table Total max. and
- min. required
BW Vector Problem ο¨ MINLP π¦πππππ β€ π·π
π
βπ Capacity of each network Vector
8
SLIDE 9
GAMS Input File
Sets Data Variables Equations Model & Call Solver π, π πππο¨ Table, πο¨ Scalar π·π, πΆπππ¦,π, πΆπππ,π ο¨ parameters π¦ππ ο¨ Binary πππ ο¨ Positive Objective function and constraints (equalities and inequalities) MINLP , solver = BARON
9
π¨ ο¨ free
SLIDE 10
GAMS Input File Cont.
Set declaration End Set declaration Sets names Comments Sets members
- 1. Sets:
- 2. Data:
Table declaration Table name ο¨ Domains = rows and columns Columns = same as M Rows = same as N Data End Table
10
SLIDE 11
GAMS Input File Cont.
- 2. Data Cont.:
Parameters Declaration Parameters Names And Domain Data End Parameters Declaration Scalar Declaration Scalar Name Scalar Value End
- 3. Variables:
Declare Variables
- Obj. fn. Value
BW & Assign. Variables types z = free by default
11
SLIDE 12
GAMS Input File Cont.
- 4. Equations:
Declare Equations End Equations Equations Names and Domain = β€ β₯ Condition: Apply this only for M = 1:3, i.e.
- nly for multi-
homing users
12
SLIDE 13
GAMS Input File Cont.
- 4. Model & Call Solver:
Problem Type Solver Name Problem Modeling Maximize obj. fn.
13
SLIDE 14
GAMS Input File Cont.
Problem type & Solver Sets Data Variables Equations Model & Solve
14
SLIDE 15
Outline
Introduction GAMS Input File GAMS Output MATLAB Interface
15
SLIDE 16
GAMS Outputs
Run your Model Name of my GAMS input file
16
SLIDE 17
GAMS Outputs Cont.
Listing file Check the results of your variables B is a Matrix πΆ = 0.101 β¦ . 0.411 β¦ . Rows = Networks Columns = Users Add bounds ο¨Necessary for BARON to guarantee global optimality
17
SLIDE 18
GAMS Outputs Cont.
Double click on error gives you its location in your code
18
SLIDE 19
Outline
Introduction GAMS Input File GAMS Output MATLAB Interface
19
SLIDE 20
MATLAB Interface
Why?
- Test how performance changes with some parameters, e.g.
how does bandwidth allocation changes with number of users?
- If you have a simulation on MATLAB and part of your MATLAB
code needs to solve a complex optimization problem
- Better view of your results ο¨ Matrix form, or a plot
GDX Utilities ο¨ GAMS Data Exchange
20
SLIDE 21
MATLAB Interface Cont.
Step 1: Update MATLAB Path to Include GAMS Directory: MATLAB: File > Set path > Add folder Browse Add
21
SLIDE 22
MATLAB Interface Cont.
Step 2: Update System Variables to Include GAMS Directory: Computer: Right click > Properties > Advanced system settings Environment Variables Edit and Type GAMS Path
22
SLIDE 23
MATLAB Interface Cont.
Step 3: Modify your GAMS Input File:
No members No Values Comes from MATLAB
- 1. Open a file tstdat.gdx: βgdxin
filenameβ ο¨ tstdat created by MATLAB
- 2. Load set members and parameters
values from this file
- 3. Close the file: βgdxinβ
Put the variables you want to read
- n MATLAB in file tstsol.gdx
;
23
SLIDE 24
MATLAB Interface Cont.
Step 4: MATLAB File:
- A. Create MATLAB function: inputs = set members and parameters
data, outputs: problem variables
- B. Define Sets
Same as in my GAMS input file
24
SLIDE 25
MATLAB Interface Cont.
- C. Define Parameters
Vector Scalar Table
25
SLIDE 26
MATLAB Interface Cont.
- D. Write Values in tstdat.gdx
Write function
- E. Run the GAMS Input File
Avoid crash with loops Function: Run GAMS input file Name of my GAMS input file
26
SLIDE 27
MATLAB Interface Cont.
- F. Read GAMS Results on MATLAB
My GAMS Variables Read function
27
SLIDE 28
MATLAB Interface Cont.
Define sets Define Parameters Write set members and parameters values Run GAMS input file Read GAMS results
28
SLIDE 29
MATLAB Interface Cont.
- G. Save GAMS Input File and MATLAB function on Same Directory
- H. On MATLAB Command Window
Input Data Run GAMS and Read Results Results
29
SLIDE 30
MATLAB Interface Cont.
Also, I can make a for loop in MATLAB on one of the parameters and fix other parameters to study some performance and plot results on MATLAB
30
SLIDE 31
Summary
Introduction GAMS Input File GAMS Output MATLAB Interface
31