using commands, model, reset in a loop

831 views
Skip to first unread message

erimk...@hotmail.com

unread,
Sep 2, 2008, 1:37:47 AM9/2/08
to AMPL Modeling Language
Hello,
I appreciate if anybody has an idea. I am in need of using the "model"
and "reset" commands in a repeat loop. Seeing some emails here, I
guess AMPL won't allow this. If the best thing to do is to give the
model command outside the loop and to reset specific model variables
in each pass in the loop, then what exactly does it mean to reset a
variable? Does this get rid of the values currently the variables are
at and treat the variables as they've just been defined?

If what I reset is a parameter, would it be set to its default
value?

Thank you very much.

Erim

Paul

unread,
Sep 3, 2008, 11:53:50 AM9/3/08
to AMPL Modeling Language


On Sep 2, 1:37 am, erimkar...@hotmail.com wrote:
> I appreciate if anybody has an idea. I am in need of using the "model"
> and "reset" commands in a repeat loop.

The reset command erases everything, including variable declarations,
the parameter indexing the loop you are in (if you are using a for
loop), etc. I suspect that's overkill for what you have in mind. You
might consider whether "reset data" (forget parameter values assigned
in data mode), "reset data <list>" (forget values of just the
parameters in the list), or "update data"/"update data <list>" (which
allows parameter values to be modified, but retains previous values if
not modified) would do the job for you. See section A.13.10 of the
AMPL book.

/Paul

Robert Fourer

unread,
Sep 4, 2008, 6:05:37 PM9/4/08
to am...@googlegroups.com, erimk...@hotmail.com
Erim,

Perhaps the command you want here is "reset data". If a has been declared as a
parameter and you execute

reset data a;

then a is set back to its default value, if you have given it one by writing,
say, "param a default 7.7;". If a has no default value then reset data causes
it to have no value until you again assign it one.

The same is true when reset data is applied to a variable, except that the
variable will automatically have a default value of 0 if you don't give it one.

Note that you can write, for example, "reset data a, b, x;" to reset more than
one parameter and/or variable at the same time.

Bob Fourer
4...@ampl.com

leoli...@gmail.com

unread,
Sep 16, 2008, 1:24:00 PM9/16/08
to AMPL Modeling Language
Actually, this raises an interesting question. I know "data" can be
used inside a loop and "model" (and so many other commands) can't, but
what if I _really_ need to use "model" rather than "data", because
_another_agent_ is writing a new .mod file at every iteration (and it
is really a .mod rather than a .dat because the script is supposed to
work on every possible user-defined .mod input, so it can't make
assumption as regards the model/data structure)? Any way to do this?
Any planned work to extend AMPL in this direction?

Leo Liberti
Reply all
Reply to author
Forward
0 new messages