Running ampl's for loop
marcos-dv opened this issue · comments
Marcos commented
I tried ampl.eval('for{i in 0..2} { display i; }')
but an error showed up.
However, ampl.eval('for{i in 0..2} { display i;}')
works. The only difference is the space between the semicolon and the bracket in the failing example.
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from amplpy import AMPL
>>> ampl = AMPL()
>>> ampl.eval('for{i in 0..2} { display i; }')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/lib/python3.10/site-packages/amplpy/ampl.py", line 266, in eval
self._impl.eval(statements)
ValueError: Incomplete statements not allowed.
>>> ampl.eval('for{i in 0..2} { display i;}')
i = 0
i = 1
i = 2
API version:
amplpy==0.12.2
ampltools==0.6.4
Filipe Brandao commented
This has been fixed in version amplpy v0.13.1 (you can upgrade with python -m pip install amplpy==0.13.1 --upgrade
).