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 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]
GAMS Structure and MATLAB Interface 4 MATLAB GAMS GAMS Input File GAMS Output File Compilation (name.gms) (name.lst) Optimization Solver
Outline 5 Introduction GAMS Input File GAMS Output MATLAB Interface
GAMS Input File Structure 6 Correspond to indices in you Sets problem Can be: parameters, tables, Data and scalar Can be: free (- β,+β), + ve, -ve, Variables 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 Bandwidth allocation variable Binary Positive Max {log 1 + π¦ ππ π ππ β π ππ π¦ ππ π ππ } π π S.t. πΆ πππ,π β€ π¦ ππ π ππ β€ πΆ πππ¦,π βπ π Priority parameter π¦ ππ π ππ β€ π· π βπ Matrix ο¨ Table π π¦ ππ = 1, π¦ ππ = 0,1 , βπ β π 1 Total max. and π min. required Capacity of each network π¦ ππ = 1, βπ β π 2 BW Vector Vector Problem ο¨ MINLP
GAMS Input File 9 π, π Sets π ππ ο¨ Table, π ο¨ Scalar Data π· π , πΆ πππ¦,π , πΆ πππ,π ο¨ parameters π¦ ππ ο¨ Binary Variables π ππ ο¨ Positive π¨ ο¨ free Equations Objective function and constraints (equalities and inequalities) Model & Call Solver MINLP , solver = BARON
GAMS Input File Cont. 10 1. Sets: Sets names Set declaration Sets members End Set declaration Comments 2. Data: Table name ο¨ Domains = rows and columns Table declaration Columns = same as M Rows = same as N Data End Table
GAMS Input File Cont. 11 2. Data Cont.: Parameters Declaration Scalar Scalar Name Declaration Scalar Value End Parameters Names Data 3. Variables: Declare Obj. fn. Value Variables BW & Assign. And Domain End Variables types Parameters z = free by default Declaration
GAMS Input File Cont. 12 4. Equations: Declare Equations Equations Names and End Equations Domain = β€ Condition: β₯ Apply this only for M = 1:3, i.e. only for multi- homing users
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 Equations Data 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 β¦ . Rows = 0.411 β¦ . 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 No Values filenameβ ο¨ tstdat created by MATLAB 2. Load set members and parameters values from this file 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 Name of my with loops GAMS input file 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 Run GAMS input file parameters values 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
Recommend
More recommend