I am trying to convert a set of GAMS models to a custom matrix style format. Is there a way to access each equation in a GAMS model and read the coefficients of each variable + type (=l=,=e= or =g=) & RHS for each equation?

The closest I get is the Equations Listing, which gives me more or less what I need, as it is in a format that could be easily parsed, but as it says in the manual: "In nonlinear models, the GAMS equation listing shows first-order Taylor approximations of the nonlinear equa- tions." and not the equation itself.

The other approach I investigated was using put statements, but I can't find a way to read the equations. What I had in mind was looping over all equations, and for each equation loop over all indices and put the coefficients for each row to an output file. Is something like this at all possible?

Any ideas on how to proceed?

asked 22 Nov '12, 07:04

hellemo's gravatar image

accept rate: 0%

Is your model linear? If not, are you trying to get the Jacobian of the constraints? (which corresponds to the A matrix of an LP if the system is linear)

(22 Nov '12, 13:40) Gilead ♦

No, it's non-linear. I'm not trying to get the Jacobian, I want the coefficients from the original equations. I also need the name of the variables to be able to treat then differently (for decomposition).

(22 Nov '12, 15:15) hellemo

I'm not sure GAMS is capable of doing what you need, but it seems that writing a specialized code in a programming language would do the trick as well.

(22 Nov '12, 15:21) Ehsan ♦

@hellemo: Can you give us an example of what your equations look like? I suspect there isn't a pre-packaged way of doing what you want, but if the form is regular enough, you can write a simple parser to do the job.

(22 Nov '12, 16:44) Gilead ♦

what about letting GAMS write the model to a file which is then in a "standard" format (like LP format for linear and integer program) and parse that?


answered 22 Nov '12, 10:53

Marco%20Luebbecke's gravatar image

Marco Luebbecke ♦
accept rate: 16%

Yes, something like LP format would be great. Is that possible from GAMS?

(22 Nov '12, 15:16) hellemo

Try using Convert as the selected solver. See GAMS solvers help for more information.

(22 Nov '12, 15:18) Ehsan ♦

@hellemo: As I understand it, the LP format can only store linear coefficients. I'm not sure if there is a standard way of extracting coefficients from nonlinear equations. You might need a way of specifying how the coefficients appear in the terms, and which coefficients you want.

(22 Nov '12, 16:43) Gilead ♦

Thanks @marco-luebbecke & @Ehsan. I forgot about convert, I thought it changed all variable names. On further investigation it turns out with the option dict, GAMS writes a dictionary to map variable names back to the original name. This gives me exactly what I need!

In case it could be of use to someone else, see here.

(23 Nov '12, 04:31) hellemo
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 22 Nov '12, 07:04

Seen: 1,748 times

Last updated: 23 Nov '12, 04:36

OR-Exchange! Your site for questions, answers, and announcements about operations research.