I am a full-time consultant and provide services related to the design, implementation and deployment of mathematical programming, optimization and data-science applications. I also teach courses and workshops. Usually I cannot blog about projects I am doing, but there are many technical notes I'd like to share. Not in the least so I have an easy way to search and find them again myself. You can reach me at erwin@amsterdamoptimization.com.
Thursday, April 28, 2022
Inverting a large, dense matrix
Saturday, April 16, 2022
Expanding Visual Studio in the Task Manager
Thursday, April 14, 2022
GAMS: Undocumented PUT formats
The GAMS documentation mentions f.nr=1 (standard notation) and f.nr=2 (scientific notation) for formatting numeric items using the PUT statement. There are however a few more. Here we print values using different formats:
f.nr=1 f.nr=2 f.nr=3 f.nr=4 1.20 1.20E+00 1.2000000000 1.2 1.23 1.23E+00 1.2345000000 1.2345 123450000.00 1.23E+08 123450000.00 123450000 0.00 1.20E-07 0.0000001200 1.2E-7 0.00 1.23E-07 0.0000001235 1.2345E-7
References
- Dictionary of formats, https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0z62k899n6a7wn1r5in6q5253v1.htm
Appendix: GAMS code
set |
Sunday, April 10, 2022
Rewriting old GAMS code
It is always a good idea to revisit existing GAMS code and see if we can improve it. Here is an example of an actual model.
The problem is that we want to set up a mapping set between two sets based on the first two characters. If they are the same, the pair should be added to the mapping. The old code looked like:
sets |
To verify this indeed generates the correct result for set rs, we look at the output:
---- 27 PARAMETER value AP CB LA APN0501 APN0502 APN0504 CBL0704 CBM0404 LAM0404 1 6580.000 6766.000 7665.000 2 6580.000 6580.000 6580.000 6766.000 6766.000 7665.000 + LAM0406 2 7665.000 ---- 28 SET rs mapping regions<->subregions APN0501 APN0502 APN0504 CBL0704 CBM0404 LAM0404 LAM0406 AP YES YES YES CB YES YES LA YES YES
- The function ord(string, pos) returns the ASCII value of the character at position pos of the string.
- The suffix .TL is the text string of the set element (internally GAMS does not work with the strings but rather an integer id for each set element; here we make it explicit we want the string).
- The loops are not really needed. We could have used:
value('1',R) = 100*ord( R.tl,1) + ord( R.tl,2);
value('2',S) = 100*ord( S.tl,1) + ord( S.tl,2); - The mapping set is a very powerful concept in GAMS. It is somewhat like a dict in Python, except it is not one way. It can map from r to s but also from s to r.
* new
code: |
This gives the same result:
---- 22 SET rs mapping regions<->subregions
APN0501 APN0502 APN0504 CBL0704 CBM0404 LAM0404 LAM0406
AP YES YES YES
CB YES YES
LA YES YES
- No need for the auxiliary parameter value.
- No loops.
- We could add a check that we have no unmapped subregions. E.g. by:
abort$(card(rs)<>card(s)) "There are unmapped subregions"; - This will also catch cases where the casing does not match.
- Critical note: GAMS has very poor support for strings. This should have been rectified a long time ago. There is no excuse for this deficiency.