GAMS: A Powerful Optimization tool and its interface to...
Transcript of GAMS: A Powerful Optimization tool and its interface to...
![Page 1: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/1.jpg)
GAMS: A POWERFUL
OPTIMIZATION TOOL AND ITS
INTERFACE TO MATLAB
Muhammad Ismail
![Page 2: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/2.jpg)
Outline
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
2
![Page 3: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/3.jpg)
Introduction
- GAMS = General Algebraic Modeling System
- Model linear, nonlinear, and mixed integer
optimization 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
![Page 4: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/4.jpg)
GAMS Structure and MATLAB Interface
GAMS Input File
(name.gms)
GAMS Output File
(name.lst)
GAMS
Compilation
Optimization
Solver
MATLAB
4
![Page 5: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/5.jpg)
Outline
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
5
![Page 6: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/6.jpg)
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
![Page 7: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/7.jpg)
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
![Page 8: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/8.jpg)
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
![Page 9: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/9.jpg)
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
![Page 10: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/10.jpg)
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
![Page 11: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/11.jpg)
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
![Page 12: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/12.jpg)
GAMS Input File Cont.
4. Equations:
Declare Equations
End Equations
Equations
Names and
Domain =
≤
≥
Condition:
Apply this only
for M = 1:3, i.e.
only for multi-
homing users
12
![Page 13: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/13.jpg)
GAMS Input File Cont.
4. Model & Call Solver:
Problem Type Solver Name
Problem Modeling
Maximize obj. fn.
13
![Page 14: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/14.jpg)
GAMS Input File Cont.
Problem type
& Solver Sets
Data
Variables
Equations
Model & Solve
14
![Page 15: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/15.jpg)
Outline
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
15
![Page 16: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/16.jpg)
GAMS Outputs
Run your Model
Name of
my GAMS
input file
16
![Page 17: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/17.jpg)
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
![Page 18: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/18.jpg)
GAMS Outputs Cont.
Double click on error gives you
its location in your code
18
![Page 19: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/19.jpg)
Outline
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
19
![Page 20: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/20.jpg)
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
![Page 21: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/21.jpg)
MATLAB Interface Cont.
Step 1: Update MATLAB Path to Include GAMS Directory:
MATLAB: File > Set path > Add folder
Browse
Add
21
![Page 22: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/22.jpg)
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
![Page 23: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/23.jpg)
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
on MATLAB in file tstsol.gdx ;
23
![Page 24: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/24.jpg)
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
![Page 25: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/25.jpg)
MATLAB Interface Cont.
C. Define Parameters
Vector
Scalar Table
25
![Page 26: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/26.jpg)
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
![Page 27: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/27.jpg)
MATLAB Interface Cont.
F. Read GAMS Results on MATLAB
My GAMS Variables
Read function
27
![Page 28: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/28.jpg)
MATLAB Interface Cont.
Define sets
Define
Parameters
Write set members and
parameters values Run GAMS input file
Read GAMS results
28
![Page 29: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/29.jpg)
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
![Page 30: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/30.jpg)
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
![Page 31: GAMS: A Powerful Optimization tool and its interface to matlabbbcr.uwaterloo.ca/~m6ismail/CoNET/Slides/GAMS.pdf · GAMS Structure and MATLAB Interface GAMS Input File (name.gms) GAMS](https://reader030.fdocuments.in/reader030/viewer/2022041103/5f0336ba7e708231d4081966/html5/thumbnails/31.jpg)
Summary
Introduction
GAMS Input File
GAMS Output
MATLAB Interface
31