Re: [AMPL 24007] ampl.eval

9 views
Skip to first unread message

AMPL Google Group

unread,
Jul 6, 2022, 7:33:00 AM7/6/22
to AMPL Modeling Language
Is k a variable in Python or an AMPL parameter? If it is a variable in python you should use the following instead:

ampl.eval('display _varname, _var > "/home/monpc/optimal_sizing/ampl_results/solution{}.out";'.format(k))



--
Filipe Brandão
am...@googlegroups.com
{#HS:1940369161-110838#}
On Tue, Jul 5, 2022 at 4:08 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
In python script, I have a loop, each loop I solve an ampl optimization problem. I want to store all variables for each optimization as follows: (k is the number of the current loop)




ampl.eval('display _varname, _var > ("/home/monpc/optimal_sizing/ampl_results/solution" & k & ".out");')


However I got this error:



File "/home/monpc/optimal_sizing/main.py", line 593, in <module>
ampl.eval('display _varname, _var > ("/home/monpc/optimal_sizing/ampl_results/solution" & k & ".out");')

File "/home/monpc/anaconda3/lib/python3.9/site-packages/amplpy/ampl.py", line 263, in eval
self._error_handler_wrapper.check()

File "/home/monpc/anaconda3/lib/python3.9/site-packages/amplpy/ampl.py", line 697, in check
raise exp

File "/home/monpc/anaconda3/lib/python3.9/site-packages/amplpy/ampl.py", line 681, in error
self.error_handler.error(exception)

File "/home/monpc/anaconda3/lib/python3.9/site-packages/amplpy/errorhandler.py", line 25, in error
raise exception

AMPLException: line 1 offset 0
syntax error
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/85b93471-dc4e-43ad-9614-0e19e122fbd9n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages