Download presentation

Presentation is loading. Please wait.

Published byJoella Doyle Modified about 1 year ago

1
Advanced GAMS 1. Good Modeling Practices 2. Fixing Misbehaving Models 3. Linking GAMS 4. Advanced GAMS Syntax

2
1 Good Modeling Practices Document Descriptive Names Sensible Structure Efficient Programming

3
Documentation Use “*” comments Symbol descriptions & units at declaration $ontext $offtext $oneolcom, $eolcom, $oninlinecom, … Put all data in named parameters Keep original data files Track gams program versions

4
Naming Choose Descriptive Names up to 64 Characters Avoid Special Characters Avoid set elements which look like numbers Use …_var, …_equ, …_data Use desired capitalization on 1st occurrence, be aware of unique element ordering Name files which need to be run sequentially 1_..., 2_..., 3_...

5
Structure Number and size of files Number and organization of directories Arrangement of sets, data, model, and base report Scenarios, Scenario Report

6
Efficient GAMS usage Use indexes, keep order index consistent Automate data processing (gdx, awk, put) Experiment with small models

7
Efficient GAMS usage Taylor output Check aggregate solutions first Check speed and memory Avoid irrelevant computations - use conditions

8
Efficiency and Errors Avoid copies of the same piece of code to facilitate model development and to reduce errors from incomplete updating –use indexes –may introduce accounting variables to reduce code copies in report statements

9
2 Fixing Misbehaving Models Unboundedness Infeasibility Bad solution Scaling, Memory, Speed Problems

10
Using GAMSCHK Option LP=GAMSCHK; Option MIP=GAMSCHK; Option NLP=GAMSCHK; Place option before solve statement Works best for large LP models where variables and equations have many indexes

11
GAMSCHK Use on single solve statements (not in a scenario loop) Start with small model versions For larger models consider variable and equation selections

12
Tayloring GAMSCHK Create.gck, where filename is the name of the file that is executed Create gamschk.opt and use.optfile = 1; Create/modify.opt

13
Content of.gck Major keywords: –Analysis –Postopt –Displaycr –Blockpic Variable/Equation selection possible under each keyword … see solver manual or McCarl user guide for more exampels

14
Unboundedness Place artificial bound on objective or other variables Use GAMSCHK nonopt Set filter in gamschk.opt

15
Infeasibility Need artificial variables Use BLOCKPIC to find candidate equations for artificial variables GAMSCHK analysis GAMSCHK postopt on non-zero artificial variables

16
Equation Candidates for Artificial Variables using Blockpic Output | V V V V | R | a a a a | H | | S Equ_1 | | E 0 Equ_2 | + | L - Equ_3 | - m m | L 0 Equ_4 | + | G Typ | u Assume that all variables are zero and then check which equations would be violated (infeasible). Thus, look for “L –”, “G +”, “E -“, or “E +”

17
Artificial Variables, 1 Declare artificial variables as nonnegative variables Place a high penalty for artificial variables in the objective function –High negative values in max problems –High positive values in min problems Use each artificial variable only in one constraint

18
Artificial Variables, 2 For each =L= equation with a negative r.h.s. value add the artificial variable to the l.h.s with a coefficient of -1. For each =G= equation with a positive r.h.s. value add the artificial variable to the l.h.s with a coefficient of 1. For each =E= equation with a non-zero r.h.s. value add two artificial variables to the l.h.s one with a coefficient of 1 and one with a coefficient of -1.

19
Bad solution GAMSCHK analysis routine GAMSCHK postopt routine Trace from symptom to cause(s)

20
Tracing unrealistic solutions No need to guess or remember all changes from the last working model Decompose solution Get rid of generic errors using GAMSCHK ANALYSIS routine

21
Tracing unrealistic solutions Alternate between variables and equations in GAMSCHK Alternate between individual GAMSCHK output and aggregated model structure Use display statements (don‘t look at original data)

22
Fixing Analysis Errors First decide between 2 general cases A) Variable/Equation is present but shouldn‘t be present B) Variable/Equation is not present but should be present

23
Case A) Variable/Equation is present but shouldn‘t be present Solution (99%): Impose conditions

24
Case B) Variable/Equation is not present but should be present Solution: Check conditions and data Display data right before solve statement

25
Postopt Output Output for Variables –Aij coefficients –Ui shadow prices –Aij * Ui –True reduced costs Output for Equations –Aij coefficients –Xj variable levels –Aij*Xj –Shadow price

26
Conditions Rule of thumb: Every variable block should have the same conditions in each equation block

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google