GAMS: A Powerful Optimization tool and its interface to matlab

advertisement
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,
optimization problems
and
mixed
integer
- 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]
GAMS Structure and MATLAB Interface
4
MATLAB
GAMS Input File
(name.gms)
GAMS
Compilation
Optimization
Solver
GAMS Output File
(name.lst)
Outline
5
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
GAMS Input File Structure
6
Sets
Correspond to indices in you
problem
Data
Can be: parameters, tables,
and scalar
Variables
Can be: free (-∞,+∞), +ve, -ve,
binary, integer
Equations
Equalities and inequalities
Model & Call Solver
LP, NLP, MIP, MINLP
Problem Example
7
- 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
Mathematical Formulation
8
Assignment variable
Binary
Max
𝑛
π‘š {log
S.t. π΅π‘šπ‘–π‘›,π‘š ≤
1 + π‘₯π‘›π‘š π‘π‘›π‘š − π‘π‘›π‘š π‘₯π‘›π‘š π‘π‘›π‘š }
𝑛 π‘₯π‘›π‘š π‘π‘›π‘š
𝑛 π‘₯π‘›π‘š π‘π‘›π‘š
Total max. and
min. required
BW
Vector
𝑛 π‘₯π‘›π‘š
Bandwidth allocation variable
Positive
≤ π΅π‘šπ‘Žπ‘₯,π‘š ∀π‘š
Priority parameter
≤ 𝐢𝑛 ∀𝑛
Matrix  Table
= 1, π‘₯π‘›π‘š = 0,1 , ∀π‘š ∈ 𝑀1
π‘₯π‘›π‘š = 1, ∀π‘š ∈ 𝑀2
Problem  MINLP
Capacity of each network
Vector
GAMS Input File
9
Sets
𝑁, 𝑀
Data
π‘π‘›π‘š  Table, 𝑓 Scalar
𝐢𝑛 , π΅π‘šπ‘Žπ‘₯,π‘š , π΅π‘šπ‘–π‘›,π‘š  parameters
Variables
Equations
Model & Call Solver
π‘₯π‘›π‘š  Binary
π‘π‘›π‘š  Positive 𝑧  free
Objective function and constraints
(equalities and inequalities)
MINLP, solver = BARON
GAMS Input File Cont.
10
1. Sets:
Set declaration
Sets names
End Set declaration
2. Data:
Table declaration
Rows = same as N
Sets members
Comments
Table name  Domains = rows and columns
Columns = same as M
Data
End Table
GAMS Input File Cont.
11
2. Data Cont.:
Parameters
Names
And
Domain
Parameters
Declaration
Data
Scalar Scalar Name
Declaration Scalar Value End
3. Variables:
Declare
Obj. fn. Value
Variables
BW & Assign.
End
Parameters
Declaration
Variables types
z = free by default
GAMS Input File Cont.
12
4. Equations:
Declare Equations
Equations
Names and
Domain
Condition:
Apply this only
for M = 1:3, i.e.
only for multihoming users
End Equations
=
≤
≥
GAMS Input File Cont.
13
4. Model & Call Solver:
Problem Type
Solver Name
Problem Modeling
Maximize obj. fn.
GAMS Input File Cont.
14
Problem type
& Solver
Sets
Data
Equations
Model & Solve
Variables
Outline
15
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
GAMS Outputs
16
Run your Model
Name of
my GAMS
input file
GAMS Outputs Cont.
17
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
GAMS Outputs Cont.
18
Double click on error gives you
its location in your code
Outline
19
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
MATLAB Interface
20
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
MATLAB Interface Cont.
21
Step 1: Update MATLAB Path to Include GAMS Directory:
MATLAB: File > Set path > Add folder
Browse
Add
MATLAB Interface Cont.
22
Step 2: Update System Variables to Include GAMS Directory:
Computer: Right click > Properties > Advanced system settings
Environment Variables
Edit and Type GAMS Path
MATLAB Interface Cont.
23
Step 3: Modify your GAMS Input File:
No members
1. Open a file tstdat.gdx: “gdxin
filename”  tstdat created by MATLAB
2. Load set members and parameters
values from this file
No Values
Comes from MATLAB
3. Close the file: “gdxin”
;
Put the variables you want to read
on MATLAB in file tstsol.gdx
MATLAB Interface Cont.
24
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
MATLAB Interface Cont.
25
C. Define Parameters
Vector
Scalar
Table
MATLAB Interface Cont.
26
D. Write Values in tstdat.gdx
Write function
E. Run the GAMS Input File
Avoid crash
Function: Run
with loops GAMS input file
Name of my
GAMS input file
MATLAB Interface Cont.
27
F. Read GAMS Results on MATLAB
My GAMS Variables
Read function
MATLAB Interface Cont.
28
Define sets
Define
Parameters
Write set members and
parameters values
Run GAMS input file
Read GAMS results
MATLAB Interface Cont.
29
G. Save GAMS Input File and MATLAB function on Same Directory
H. On MATLAB Command Window
Input
Data
Run GAMS and Read Results
Results
MATLAB Interface Cont.
30
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
Summary
31
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
Download