Difference: AMPLProcess (9 vs. 10)

Revision 102009-07-23 - CameronWalker

Line: 1 to 1
 
META TOPICPARENT name="AMPLGuide"
<-- Ready to Review - done - Lauren-->

The AMPL Process

Line: 29 to 29
 AMPL commands consist of statements in the AMPL syntax terminated with a ;.

Some examples include:

Changed:
<
<
set INGREDIENTS;

data;

display {i in INGREDIENTS} Percentage[i];
>
>
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.
Line: 80 to 74
 

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:

Changed:
<
<
reset;
model <modelname>.mod;
data <dataname>.dat;
. . .
and you run this file using the include command.
>
>
reset; model .mod; data .dat; . . . 
and you run this file using the include command.
  script_file.jpg

Setting Data Dynamically

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 have 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,

Changed:
<
<
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;
>
>
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; 
  dynamic_error.jpg
Line: 138 to 103
 

Running AMPL files

Changed:
<
<
Once you have finished editing your AMPL files, you can run them by
  1. Either starting a command line application or double-clicking on setup_ampl.bat (if you are at home);
>
>
Once you have finished editing your AMPL files, you can run them by:
  1. Either starting a command line application or double-clicking on setup_ampl.bat (if you are at home);
 
  1. Navigating to the directory where you saved the files;
Changed:
<
<
  1. Starting AMPL
  2. Typing AMPL commands, e.g., model .mod;, data .dat;, include .run;
>
>
  1. Starting AMPL;
  2. Typing AMPL commands, e.g., model .mod;, data .dat;, include .run.
  Return to top
 
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