from gamspy import Container, Sum, Sense
ct = Container()
s = ct.addSet("s", records=[1, 2])
x = ct.addVariable("x", type="positive", domain=s)
eq = ct.addEquation("eq", domain=s)
eq[s].where[~s.first] = x[s] >= 1
m = ct.addModel(
problem="LP",
name="test",
sense=Sense.MIN,
equations=[eq],
objective=Sum(s, x[s]))
res = m.solve()
print(res)
m.toGams(".")
This results in the following output:
Solver Status Model Status Objective Num of Equations Num of Variables Model Type Solver Solver Time
0 Normal OptimalGlobal 1 2 3 LP CPLEX 0
Traceback (most recent call last):
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\containers\_container.py", line 147, in __getitem__
return self.data[sym]
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\_internals\casepreservingdict.py", line 62, in __getitem__
return self.data[self._casefolded_key_map[key.casefold()]]
KeyError: 's.first'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\rech_ge\Documents\workspace\simplesom\simplesom\test\to_gams_example.py", line 19, in <module>
m.toGams(".")
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gamspy\_model.py", line 796, in toGams
all_needed_symbols = sorted(all_symbols, key=sort_names)
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gamspy\_model.py", line 784, in sort_names
return PRECEDENCE[type(self.container[name])]
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\containers\_container.py", line 149, in __getitem__
raise KeyError(
KeyError: 'Attempted retrieval of symbol `s.first`, but `s.first` does not exist in the Container'
The model is fine, but toGams() fails. So GAMSPy must be using a different toGams() function under the hood?
Here's an example:
This results in the following output:
The model is fine, but
toGams()
fails. So GAMSPy must be using a differenttoGams()
function under the hood?