Difference: AMPLProcess (2 vs. 3)

Revision 32008-02-26 - TWikiAdminUser

Line: 1 to 1
 
META TOPICPARENT name="AMPLGuide"

The AMPL Process

Line: 39 to 39
  If you forget the ;, then the ampl: prompt will be replaced by the ampl? prompt, indicating that your AMPL command has not been finished. You can finish your command or, if you are not sure how to finish it, type ;. AMPL will then interpret your AMPL command and display any problems.
Added:
>
>
Return to top
 

The Model Environment

AMPL encourages a clean modeling style by explicitly separating the model formulation from the particular problem data. The model formulation, as written in the AMPL syntax, can be saved as a .mod file. This file contains all set, variable, and parameter definitions, as well as all constraints and the objective function.

Line: 53 to 55
  src="model_file.jpg"
Added:
>
>
Return to top
 

The Data Environment

All data and values specific to the problem instance you are solving are separated from the model formulation when using AMPL. This is enforced by the method used to input the problem details into AMPL - the model formulation is entered in the model environment, the problem specific data is entered in the data environment. To switch from the model environment to the data environment one types data; at the AMPL prompt ampl: (and switches back to the model environment by typing model;).

Line: 67 to 71
  src="data_file.jpg"
Added:
>
>
Return to top
 

Scripting in AMPL

A script is a text file used to run a number of AMPL commands. It is useful when you may wish to run the same commands multiple times, possibly with slight editing changes. It is also useful for keeping track of what you have done, or if you may wish to rerun your models at a later date. Script files run in the model environment, and are usually named with a .run extension. It is good practice to get into the habit of using script files for your AMPL sessions. A typical script file should begin:

Line: 84 to 90
 

Setting Data Dynamically

Changed:
<
<
??? Up to here ??? Put Return to top everywhere AMPL allows you to set data "on the fly" using the {\tt let} keyword. If you have a set, parameter or variable as part of your model and defined it using a data file (i.e., you DID NOT USE AN EXPRESSION to set a value for it), then you can change that structure on the fly with let. For example,

\begin{verbatim}
reset;

model;

param a; param b;
param maxab := max(a, b);

data;

param a := 1;
param b := 2; # Sets maxab = 2

display a, b, maxab; # Shifts AMPL back to the
# model environment

let a := 3; # Sets a and maxab = 3
display a, b, maxab;

let maxab := 4; # Syntax error, parameter defined by an
# expression
display a, b, maxab;
\end{verbatim}



The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using {\tt model;} to enter the model environment (and leave the data environment), it jumps from the data environment to the model environment by using a command that is not valid in the data environment (the {\tt display} command).

Notes on AMPL Files<br />

Editing AMPL files


The easiest way to edit AMPL files is using a text editor such as Wordpad. To open Wordpad go to the start menu, select Programs, then Accessories and finally Wordpad.




When you have finished editing, save the file in the appropriate directory. Be sure to save them as a basic text file NOT in Rich Text Format.



Running AMPL files


Once you have finished editing your AMPL files, you can run them by

  1. Either starting a command line application or Starting AMPL;
  2. Typing AMPL commands, e.g.,
    \begin{verbatim}
    model .mod;
    \end{verbatim}
    \begin{verbatim}
    data .dat;
    \end{verbatim}
    \begin{verbatim}
    include .run;
    \end{verbatim}
>
>
AMPL allows you to set data "on the fly" using the let keyword. If you have a set, parameter or variable as part of your model and defined it using a data file (i.e., you did not use an expression to set a value for it), then you can change that structure on the fly with let. For example,
reset;

model;

param a; param b;
param maxab := max(a, b);

data;

param a := 1;
param b := 2;  # Sets maxab = 2

display a, b, maxab; # Shifts AMPL back to the model environment

let a := 3;    # Sets a and maxab = 3
display a, b, maxab;

let maxab := 4; # Syntax error, parameter defined by an expression
display a, b, maxab;
src="dynamic_error.jpg"

??? Up to here??? The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using {\tt model;} to enter the model environment (and leave the data environment), it jumps from the data environment to the model environment by using a command that is not valid in the data environment (the {\tt display} command).

Notes on AMPL Files<br />

Editing AMPL files


The easiest way to edit AMPL files is using a text editor such as Wordpad. To open Wordpad go to the start menu, select Programs, then Accessories and finally Wordpad.




When you have finished editing, save the file in the appropriate directory. Be sure to save them as a basic text file NOT in Rich Text Format.



Running AMPL files


Once you have finished editing your AMPL files, you can run them by

  1. Either starting a command line application or Starting AMPL;
  2. Typing AMPL commands, e.g.,
    \begin{verbatim}
    model .mod;
    \end{verbatim}
    \begin{verbatim}
    data .dat;
    \end{verbatim}
    \begin{verbatim}
    include .run;
    \end{verbatim}
  -- MichaelOSullivan - 25 Feb 2008
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback