(infeasible).
Download
Report
Transcript (infeasible).
Advanced GAMS
1.
Good Modeling Practices
2.
Fixing Misbehaving Models
3.
Linking GAMS
4.
Advanced GAMS Syntax
1 Good Modeling Practices
Document
Descriptive
Names
Sensible
Structure
Efficient
Programming
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
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_...
Structure
Number
and size of files
Number
and organization of
directories
Arrangement
of sets, data, model,
and base report
Scenarios,
Scenario Report
Efficient GAMS usage
Use
indexes, keep order index
consistent
Automate
put)
data processing (gdx, awk,
Experiment
with small models
Efficient GAMS usage
Taylor
output
Check
aggregate solutions first
Check
speed and memory
Avoid
irrelevant computations - use
conditions
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
2 Fixing Misbehaving Models
Unboundedness
Infeasibility
Bad
solution
Scaling,
Memory, Speed
Problems
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
GAMSCHK
Use
on single solve statements (not
in a scenario loop)
Start
For
with small model versions
larger models consider variable
and equation selections
Tayloring GAMSCHK
Create
<filename>.gck, where
filename is the name of the file that
is executed
Create gamschk.opt and use
<modelname>.optfile = 1;
Create/modify <defaultsolver>.opt
Content of <filename>.gck
Major
keywords:
– Analysis
– Postopt
– Displaycr
– Blockpic
Variable/Equation
selection possible
under each keyword
… see solver manual or McCarl user
guide for more exampels
Unboundedness
Place
artificial bound on objective
or other variables
Use
GAMSCHK nonopt
Set
filter in gamschk.opt
Infeasibility
Need
artificial variables
Use
BLOCKPIC to find candidate
equations for artificial variables
GAMSCHK
GAMSCHK
analysis
postopt on non-zero
artificial variables
Equation Candidates for Artificial
Variables using Blockpic Output
| V V V V |
R
| a a a a |
H
| 1 2 3 4 |
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 +”
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
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.
Bad solution
GAMSCHK
analysis routine
GAMSCHK
postopt routine
Trace
from symptom to cause(s)
Tracing unrealistic solutions
No
need to guess or remember all
changes from the last working model
Decompose
Get
solution
rid of generic errors using
GAMSCHK ANALYSIS routine
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)
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
Case A) Variable/Equation is
present but shouldn‘t be present
Solution (99%):
Impose
conditions
Case B) Variable/Equation is not
present but should be present
Solution:
Check
conditions and data
Display
data right before solve
statement
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
Conditions
Rule
of thumb: Every variable block
should have the same conditions in
each equation block