model2tex

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
chrispahm
User
User
Posts: 9
Joined: 9 months ago

model2tex

Post by chrispahm » 9 months ago

Hi,

I'm currently using GAMS 25.0 and would like to use the model2tex feature.
The creation of the docfiles (as dicsussed in the documentation of model2tex) works fine, however when running model2tex I get the following error:

Code: Select all

PS C:\model\gams> model2tex mymodel -m m_farm -f
Traceback (most recent call last):
  File "model2tex.py", line 115, in <module>
  File "inst2py.py", line 1616, in latexVariables
NameError: global name 'split' is not defined
Failed to execute script model2tex
Note: The model is a large scale, multi file model using variable/equation suffixes here and there.

Any suggestion on how to solve this problem are highly appreciated! Thanks a lot in advance.

Clemens
Posts: 29
Joined: 2 years ago

Re: model2tex

Post by Clemens » 9 months ago

Hi,

This seems to be a bug in model2tex regarding SOS variables. Thank you very much for reporting. For now you could temporarily change your SOS variables to non-SOS variables to see if this lets you generate the LaTeX file. Afterwards you can change them back to SOS variables. The only effect on the LaTeX file will be the type of the variable which is reported at the end of the generated LaTeX file. Instead of an SOS variable, the type used for replacing them is reported. The actual bugfix will be available in future releases of GAMS. Please let me know if this helps.

Best,
Clemens

chrispahm
User
User
Posts: 9
Joined: 9 months ago

Re: model2tex

Post by chrispahm » 9 months ago

Hi Celmens,
thanks a lot for your reply! I will try removing the SOS variables tomorrow. Another question I have is whether there are any plans to publish the model2tex source code. The background is that I would like to create a little script where I could quickly transform single GAMS equations into Latex ones. Also I would like to tinker with the output currently generated, as right now the content is overflowing the page for equations using many dollar conditions/summands (as shown in the first picture). I also attached two pictures of what I had currently in mind (for the same equation), however I'm also not absolutely convinced that approach either.
Attachments
latex2.jpg
latex1.jpg
Bildschirmfoto 2018-02-25 um 22.40.37.png

Clemens
Posts: 29
Joined: 2 years ago

Re: model2tex

Post by Clemens » 9 months ago

The overflowing problem is well known to us. Unfortunately so far we do not have a general solution for this. model2tex is written in Python and implements a stack machine that works on the instructions generated by the GAMS compiler. If you put a $debug dmpins at the end of a model you can look at the generated instructions in the .lst file. E.g. for the cost equation of the transport model from the GAMS Model Library we get the following instructions:

Code: Select all

   20      0 UnitBeg       1         56
   21     14 DefBeg        0        144 cost
   22     55 EndLhs        0          0
   23      2 Push          0        143 z
   24     29 SumBeg        0          0
   25      7 CntrBeg       0        135 i
   26      7 CntrBeg       0        136 j
   27     12 Index         0          1
   28     12 Index         0          2
   29      2 Push          0        141 c
   30     12 Index         0          1
   31     12 Index         0          2
   32      2 Push          0        142 x
   33      4 MultOp        0          0
   34     30 SumOp         0          0
   35      8 CntrEnd       0          0
   36      8 CntrEnd       0          0
   37     42 EquOp         0          0
   38     15 DefOp         0        144 cost
   39     16 DefEnd        0        144 cost
   40      1 UnitEnd       0          0
   
While the instructions are relatively straight forward for simple models, they can become quite complicated for larger and more sophisticated ones.
The way model2tex generates the LaTeX output is just one way of doing so. There are several other formulations which might be better or worse depending on the context and the actual equation. Right now the best way to influence the output of model2tex is to use the JSON file, especially the nameMap that allows to replace GAMS symbols by user defined identifiers and the landscape flag that might reduce the extend of the overflowing equations. Please see the documentation on this: https://www.gams.com/latest/docs/T_MODEL2TEX.html#JSON
If you really want to modify the structure of the output it might be best to change the generated LaTeX file afterwards, either manually or by using a script.

Hope that helps,
Clemens

chrispahm
User
User
Posts: 9
Joined: 9 months ago

Re: model2tex

Post by chrispahm » 9 months ago

Thanks a lot for your help! I totally forgot to reply that removing the SOS variables did indeed resolve the issue.

Post Reply