Description of the issue
I would like to access the A b and c matrix values, and the order of variables x before passing to solver. Is it possible to generate and write these out in gamspy?
Error message and stack trace
NA
GAMSPy version
NA- any gamspy
Hi @vpranjal ,
You could use getEquationListing and getVariableListing to get the generated variables and equations.
As an alternative, you could also use the convert “solver” and export the generated model instance to a gdx file
myModel.solve(solver="convert", solver_options={"dumpgdx": "path\\to\\myGDXFile.gdx"})
I hope this helps!
1 Like
Thanks for the reply. I am able to explore the GDXfile now (listVariables and listEquations are useful options to view).
I was trying to recover the following matrices from the formulation (A, b, Aeq and beq) similar to the following:
https://in.mathworks.com/help/optim/ug/mpsread.html
If it is possible. Thanks
You could extract the right hand side b and the sense of an equation by looking at the lo
and up
attributes of symbol e
in the gdx file.
- if they are equal, it is an equality constraint
- if
lo
is -inf
it is a =l=
constraint
- if
up
is +inf
it is a =g=
constraint
Thanks for the direction.
The following works:
(Let m be the container we read the .gdx file into)
from gamspy import Container, Set
m = Container()
m.loadRecordsFromGdx(“myGDXFile.gdx”)
m[“A”].records in GAMSPy - GAMS Studio has a way to do this in Table view
m[“A”].records.pivot(index=‘i’, columns=‘j’, values=‘value’) or something along these lines in GAMSPy for table view
and m.[“e”].records in GAMSPy - m.[“e”].records[‘level’] I believe for b matrix
lower and upper column for lo and up
m[“j”].records give the mapping between x variables and user given variable names