How to solve one model with multiple .dat- files with help of a .run-file?

1,250 views
Skip to first unread message

A-man

unread,
Sep 22, 2011, 11:11:44 AM9/22/11
to am...@googlegroups.com

Hi everyone,

I have a rather technical question about AMPL.
I am trying to do a little computational study. I have one .mod-file and
multiple .dat-files.
My purpose is to write a .run-file that always uses the same .mod file, but
varies the .dat-file.

My question is:

How can I tell AMPL to solve the model for each .dat-file? I want AMPL to
change the path to the .dat-file automatically. Is this possible, so that I
don`t have change the path to the .dat-file manually everytime I want to
solve the model with another .dat-file?

I hope you understand my problem.

Thanks for your replies!!!
--
View this message in context: http://old.nabble.com/How-to-solve-one-model-with-multiple-.dat--files-with-help-of-a-.run-file--tp32503825p32503825.html
Sent from the AMPL mailing list archive at Nabble.com.

Paul

unread,
Sep 22, 2011, 5:23:08 PM9/22/11
to am...@googlegroups.com
This is a bit unclear.  Are you saying that you want the run file to run the model against a set of data files in one batch run, or are you saying that you want to run just a single data file and want to specify it to the run file in the command line (as an argument)?  Or is there a third interpretation I'm missing?

Paul

A-man

unread,
Sep 30, 2011, 5:32:39 AM9/30/11
to am...@googlegroups.com

Hi Paul!

Thanks for your answer. Your first interpretation is correct. I have
constructed a set of data files in excel and converted them into .dat.files.
Now I want the run file to run them against the model in one batch. Is there
a special command that makes this possible?

Greets

--
View this message in context: http://old.nabble.com/How-to-solve-one-model-with-multiple-.dat--files-with-help-of-a-.run-file--tp32503825p32557629.html

Robert Fourer

unread,
Sep 30, 2011, 8:39:37 AM9/30/11
to am...@googlegroups.com
The following example is copied from page 273 of the AMPL book. You can
adapt it to the names of your dat files. In place of the "display"
statement put whatever statements you want to execute each time a problem is
solved.

Bob Fourer
4...@ampl.com


String-valued expressions may appear in place of literal strings in
several contexts: in filenames that are part of commands, including model,
data, and commands, and in filenames following > or >> to specify
redirection of output; in values assigned to AMPL options by an option
command; and in the string-list and the database row and column names
specified in a table statement. In all such cases, the string expression
must be identified by enclosing it in parentheses.

Here is an example involving filenames. This script uses a string
expression to specify files for a data statement and for the redirection of
output from a display statement:

model diet.mod;
set CASES = 1 .. 3;
for {j in CASES} {
reset data;
data ("diet" & j & ".dat");
solve;
display Buy >("diet" & j & ".out");
}

The result is to solve diet.mod with a series of different data files
diet1.dat, diet2.dat, and diet3.dat, and to save the solution to files
diet1.out, diet2.out, and diet3.out. The value of the index j is converted
automatically from a number to a string as previously explained.

A-man

unread,
Oct 4, 2011, 11:15:23 AM10/4/11
to am...@googlegroups.com

Thank you very much!!
You really helped me out!!

> --
> You received this message because you are subscribed to the Google Groups
> "AMPL Modeling Language" group.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to
> ampl+uns...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ampl?hl=en.
>
>
>

--
View this message in context: http://old.nabble.com/How-to-solve-one-model-with-multiple-.dat--files-with-help-of-a-.run-file--tp32503825p32590062.html

Reply all
Reply to author
Forward
0 new messages