ampl
.
src="ampl.jpg"
You will then be able to enter AMPL commands at the AMPL prompt.
src="ampl_examples.jpg"
Return to top
;
.
Some examples include:
set INGREDIENTS;
data;
display {i in INGREDIENTS} Percentage[i];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.
Return to top
.mod
file. This file contains all set, variable, and parameter definitions, as well as all constraints and the objective function.
It should not contain any problem specific data or values relating to the actual real world problem you are solving.
The AMPL model is input after switching to the (default) model environment, by typing model;
and then using the include
command to import the model file, or else typing in the commands for the AMPL model directly at the ampl:
prompt.
src="model_include.jpg"
Alternatively, you can type model <filename>.mod;
.
src="model_file.jpg"
Return to top
data;
at the AMPL prompt ampl:
(and switches back to the model environment by typing model;
).
src="model_data.jpg"
As with entering the model formulation, it is common to store the data for a specific problem in a data file (<filename>.dat
). This data is then imported while in data mode by using the include
command, followed by the filename and a semicolon (or by typing the AMPL commands in directly).
src="data_include.jpg"
Again, one can use the alternative method of typing data <filename>.dat
(which does not require a switch from the model environment).
src="data_file.jpg"
Return to top
.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:
reset; model <modelname>.mod; data <dataname>.dat; . . .and you run this file using the
include
command.
src="script_file.jpg"
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).
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.