Difference: AMPLProcess (1 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

Revision 92008-03-11 - MichaelOSullivan

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

The AMPL Process

Line: 10 to 10
 
Changed:
<
<

Starting AMPL Fix stacking on this page - Lauren

>
>

Starting AMPL

  AMPL is a command line environment, i.e., you enter commands at the AMPL prompt and AMPL will decipher these commands and perform the appropriate actions.
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]; 
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.
>
>
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
Line: 39 to 51
  It should not contain any problem specific data or values relating to the actual real world problem you are solving.
Changed:
<
<
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 by - Lauren typing in the commands for the AMPL model directly at the ampl: prompt.
>
>
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 by typing in the commands for the AMPL model directly at the ampl: prompt.
  model_include.jpg
Line: 55 to 67
  model_data.jpg
Changed:
<
<
As with entering the model formulation, it is common to store the data for a specific problem in a data file (.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 typing in - Lauren the AMPL commands in directly).
>
>
As with entering the model formulation, it is common to store the data for a specific problem in a data file (.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 in the AMPL commands in directly).
  data_include.jpg
Line: 68 to 80
 

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 .mod; data .dat; . . . 
and you run this file using the include command.
>
>
reset;
model <modelname>.mod;
data <dataname>.dat;
. . .
and you run this file using the include command.
  script_file.jpg

Setting Data Dynamically

Changed:
<
<
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 - Lauren 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; 
>
>
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,
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
Changed:
<
<
The previous example also showed how to use both the model and data Fix this link - Lauren environments in the same script file. Furthermore, rather than using 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 display command).
>
>
The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using 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 display command).
  Return to top
Line: 91 to 132
  run_wordpad.jpg
Changed:
<
<
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file comma here - Lauren NOT in Rich Text Format.
>
>
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file, NOT in Rich Text Format.
  save_ampl.jpg

Running AMPL files

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

Changed:
<
<
  1. Either starting a command line application or double-clicking on =setup_ampl.bat= this link not working - Lauren (if you are at home);
>
>
  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;
  2. Starting AMPL
  3. Typing AMPL commands, e.g., model .mod;, data .dat;, include .run;

Revision 82008-03-09 - LaurenJackson

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

The AMPL Process

Line: 10 to 10
 
Changed:
<
<

Starting AMPL

>
>

Starting AMPL Fix stacking on this page - Lauren

  AMPL is a command line environment, i.e., you enter commands at the AMPL prompt and AMPL will decipher these commands and perform the appropriate actions.

To start AMPL in Windows you simply start a command line application and type ampl.

Changed:
<
<
ampl.jpg
>
>
ampl.jpg
  You will then be able to enter AMPL commands at the AMPL prompt.
Changed:
<
<
ampl_examples.jpg
>
>
ampl_examples.jpg
  Return to top
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];
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.
>
>
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

The Model Environment

Changed:
<
<
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.
>
>
AMPL encourages a clean modelling 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.
  It should not contain any problem specific data or values relating to the actual real world problem you are solving.
Changed:
<
<
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.
>
>
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 by - Lauren typing in the commands for the AMPL model directly at the ampl: prompt.
 
Changed:
<
<
model_include.jpg
>
>
model_include.jpg
 
Changed:
<
<
Alternatively, you can type model <filename>.mod;.
>
>
Alternatively, you can type model .mod;.
 
Changed:
<
<
model_file.jpg
>
>
model_file.jpg
  Return to top
Line: 62 to 53
  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;).
Changed:
<
<
model_data.jpg
>
>
model_data.jpg
 
Changed:
<
<
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).
>
>
As with entering the model formulation, it is common to store the data for a specific problem in a data file (.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 typing in - Lauren the AMPL commands in directly).
 
Changed:
<
<
data_include.jpg
>
>
data_include.jpg
 
Changed:
<
<
Again, one can use the alternative method of typing data <filename>.dat (which does not require a switch from the model environment).
>
>
Again, one can use the alternative method of typing data .dat (which does not require a switch from the model environment).
 
Changed:
<
<
data_file.jpg
>
>
data_file.jpg
  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:

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.
 
Changed:
<
<
script_file.jpg
>
>
script_file.jpg
 

Setting Data Dynamically

Changed:
<
<
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;

>
>
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 - Lauren 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; 
 
Changed:
<
<
model;
>
>
dynamic_error.jpg
 
Changed:
<
<
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

The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using 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 display command).

>
>
The previous example also showed how to use both the model and data Fix this link - Lauren environments in the same script file. Furthermore, rather than using 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 display command).
  Return to top
Line: 124 to 87
 

Editing AMPL files in Windows

Changed:
<
<
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

run_wordpad.jpg

>
>
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.
 
Changed:
<
<
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file NOT in Rich Text Format.
>
>
run_wordpad.jpg
 
Changed:
<
<
save_ampl.jpg
>
>
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file comma here - Lauren NOT in Rich Text Format.
 
Added:
>
>
save_ampl.jpg
 

Running AMPL files

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

Changed:
<
<
  1. Either starting a command line application or double-clicking on =setup_ampl.bat= (if you are at home);
  2. Navigating to the directory where you saved the files;
  3. Starting AMPL
  4. Typing AMPL commands, e.g., model <modelname>.mod;, data <dataname>.dat;, include <runname>.run;
>
>
  1. Either starting a command line application or double-clicking on =setup_ampl.bat= this link not working - Lauren (if you are at home);
  2. Navigating to the directory where you saved the files;
  3. Starting AMPL
  4. Typing AMPL commands, e.g., model .mod;, data .dat;, include .run;
  Return to top

Revision 72008-03-02 - MichaelOSullivan

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

The AMPL Process

Line: 48 to 48
  It should not contain any problem specific data or values relating to the actual real world problem you are solving.
Changed:
<
<
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.
>
>
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.
  model_include.jpg

Revision 62008-02-27 - MichaelOSullivan

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

The AMPL Process

Line: 128 to 128
  run_wordpad.jpg
Changed:
<
<
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file *NOT* in Rich Text Format.
>
>
When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file NOT in Rich Text Format.
  save_ampl.jpg

Revision 52008-02-27 - MichaelOSullivan

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

The AMPL Process

Line: 15 to 16
  To start AMPL in Windows you simply start a command line application and type ampl.
Changed:
<
<
src="ampl.jpg"
>
>
ampl.jpg
  You will then be able to enter AMPL commands at the AMPL prompt.
Changed:
<
<
src="ampl_examples.jpg"
>
>
ampl_examples.jpg
  Return to top
Line: 49 to 50
  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.
Changed:
<
<
src="model_include.jpg"
>
>
model_include.jpg
  Alternatively, you can type model <filename>.mod;.
Changed:
<
<
src="model_file.jpg"
>
>
model_file.jpg
  Return to top
Line: 61 to 62
  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;).
Changed:
<
<
src="model_data.jpg"
>
>
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).
Changed:
<
<
src="data_include.jpg"
>
>
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).
Changed:
<
<
src="data_file.jpg"
>
>
data_file.jpg
  Return to top
Line: 86 to 87
  and you run this file using the include command.
Changed:
<
<
src="script_file.jpg"
>
>
script_file.jpg
 

Setting Data Dynamically

Line: 112 to 113
 let maxab := 4; # Syntax error, parameter defined by an expression display a, b, maxab;
Changed:
<
<
src="dynamic_error.jpg"
>
>
dynamic_error.jpg
  The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using 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 display command).
Line: 124 to 126
  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
Changed:
<
<
src="run_wordpad.jpg"
>
>
run_wordpad.jpg
  When you have finished editing, save the file in the appropriate directory. Be sure to save your file as a basic text file *NOT* in Rich Text Format.
Changed:
<
<
src="save_ampl.jpg"
>
>
save_ampl.jpg
 

Running AMPL files

Line: 136 to 139
 
  1. Either starting a command line application or double-clicking on =setup_ampl.bat= (if you are at home);
  2. Navigating to the directory where you saved the files;
  3. Starting AMPL
Changed:
<
<
  1. Typing AMPL commands, e.g., model <modelname>.mod;, data <dataname>.dat;, =include <runname>.run;
>
>
  1. Typing AMPL commands, e.g., model <modelname>.mod;, data <dataname>.dat;, include <runname>.run;
  Return to top

-- MichaelOSullivan - 25 Feb 2008

Deleted:
<
<
  • ampl.jpg:
    ampl.jpg

  • ampl_examples.jpg:
    ampl_examples.jpg

  • model_include.jpg:
    model_include.jpg

  • model_file.jpg:
    model_file.jpg

  • model_data.jpg:
    model_data.jpg

  • data_include.jpg:
    data_include.jpg

  • data_file.jpg:
    data_file.jpg

  • script_file.jpg:
    script_file.jpg

  • dynamic_error.jpg:
    dynamic_error.jpg

  • run_wordpad.jpg:
    run_wordpad.jpg

  • save_ampl.jpg:
    save_ampl.jpg

  • run_wordpad.jpg:
    run_wordpad.jpg

  • ampl.jpg:
    ampl.jpg
 
META FILEATTACHMENT attachment="ampl.jpg" attr="h" comment="" date="1204098473" name="ampl.jpg" path="ampl.jpg" size="21033" stream="ampl.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="ampl_examples.jpg" attr="h" comment="" date="1204098502" name="ampl_examples.jpg" path="ampl_examples.jpg" size="21186" stream="ampl_examples.jpg" tmpFilename="" user="MichaelOSullivan" version="1"

Revision 42008-02-27 - MichaelOSullivan

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

The AMPL Process

Line: 114 to 114
  src="dynamic_error.jpg"
Changed:
<
<
??? 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}
>
>
The previous example also showed how to use both the model and data environments in the same script file. Furthermore, rather than using 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 display command).

Return to top

Notes on AMPL Files

Editing AMPL files in Windows

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

src="run_wordpad.jpg"

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

src="save_ampl.jpg"

Running AMPL files

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);
  2. Navigating to the directory where you saved the files;
  3. Starting AMPL
  4. Typing AMPL commands, e.g., model <modelname>.mod;, data <dataname>.dat;, =include <runname>.run;

Return to top

  -- MichaelOSullivan - 25 Feb 2008 \ No newline at end of file
Added:
>
>
  • ampl.jpg:
    ampl.jpg

  • ampl_examples.jpg:
    ampl_examples.jpg

  • model_include.jpg:
    model_include.jpg

  • model_file.jpg:
    model_file.jpg

  • model_data.jpg:
    model_data.jpg

  • data_include.jpg:
    data_include.jpg

  • data_file.jpg:
    data_file.jpg

  • script_file.jpg:
    script_file.jpg

  • dynamic_error.jpg:
    dynamic_error.jpg

  • run_wordpad.jpg:
    run_wordpad.jpg

  • save_ampl.jpg:
    save_ampl.jpg

  • run_wordpad.jpg:
    run_wordpad.jpg

  • ampl.jpg:
    ampl.jpg

META FILEATTACHMENT attachment="ampl.jpg" attr="h" comment="" date="1204098473" name="ampl.jpg" path="ampl.jpg" size="21033" stream="ampl.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="ampl_examples.jpg" attr="h" comment="" date="1204098502" name="ampl_examples.jpg" path="ampl_examples.jpg" size="21186" stream="ampl_examples.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="model_include.jpg" attr="h" comment="" date="1204098531" name="model_include.jpg" path="model_include.jpg" size="13692" stream="model_include.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="model_file.jpg" attr="h" comment="" date="1204098552" name="model_file.jpg" path="model_file.jpg" size="11158" stream="model_file.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="model_data.jpg" attr="h" comment="" date="1204098578" name="model_data.jpg" path="model_data.jpg" size="11487" stream="model_data.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="data_include.jpg" attr="h" comment="" date="1204098599" name="data_include.jpg" path="data_include.jpg" size="12601" stream="data_include.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="data_file.jpg" attr="h" comment="" date="1204098620" name="data_file.jpg" path="data_file.jpg" size="12586" stream="data_file.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="script_file.jpg" attr="h" comment="" date="1204098649" name="script_file.jpg" path="script_file.jpg" size="22339" stream="script_file.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="dynamic_error.jpg" attr="h" comment="" date="1204098924" name="dynamic_error.jpg" path="dynamic_error.jpg" size="20744" stream="dynamic_error.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="run_wordpad.jpg" attr="h" comment="" date="1204098970" name="run_wordpad.jpg" path="run_wordpad.jpg" size="89746" stream="run_wordpad.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="save_ampl.jpg" attr="h" comment="" date="1204098999" name="save_ampl.jpg" path="save_ampl.jpg" size="30412" stream="save_ampl.jpg" tmpFilename="" user="MichaelOSullivan" version="1"

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

Revision 22008-02-26 - TWikiAdminUser

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

The AMPL Process

>
>

The AMPL Process

 
Changed:
<
<
>
>
 
Line: 21 to 21
  src="ampl_examples.jpg"
Added:
>
>
Return to top
 

AMPL Commands

AMPL commands consist of statements in the AMPL syntax terminated with a ;.

Line: 32 to 34
 
data;
Changed:
<
<
??? Up to here ???

\begin{verbatim}
display {i in INGREDIENTS} Percentage[i];
\end{verbatim}


If you forget the {\tt ;}, then the {\tt ampl:} prompt will be replaced by the {\tt 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 {\tt ;}. AMPL will then interpret you AMPL command and display any problems.

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 {\tt .mod} file. This file contains all set, variable, and parameter definitions,
as well as all constraints and the objective function. It contains no 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 {\tt model;}
and then using the {\tt include} command to import the model file, or else
typing in the commands for the AMPL model directly at the {\tt ampl:} prompt.


Alternatively, you can type {\tt model <filename>.mod;}.



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 {\tt data;}
at the AMPL prompt {\tt ampl:} (and switches back to the model environment by typing {\tt model;}).


As with entering the model formulation, it is common to store the data in a data file ({\tt <filename>.dat}). This data is then imported using the {\tt include} command, followed by the filename and a semicolon
(or by typing the AMPL commands in directly).


Again, one can use the alternative method of typing {\tt data <filename>.dat}
(which does not require a switch from the model environment).



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 {\tt .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:

\begin{verbatim}
reset;
model .mod;
data .dat;
.
.
.
\end{verbatim}

and you run this file using the {\tt include} command.



Setting Data Dynamically


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}
>
>
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.

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.

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"

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;).

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"

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:

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

src="script_file.jpg"

Setting Data Dynamically

??? 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}
  -- MichaelOSullivan - 25 Feb 2008

Revision 12008-02-25 - MichaelOSullivan

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

The AMPL Process

Starting AMPL

AMPL is a command line environment, i.e., you enter commands at the AMPL prompt and AMPL will decipher these commands and perform the appropriate actions.

To start AMPL in Windows you simply start a command line application and type ampl.

src="ampl.jpg"

You will then be able to enter AMPL commands at the AMPL prompt.

src="ampl_examples.jpg"

AMPL Commands

AMPL commands consist of statements in the AMPL syntax terminated with a ;.

Some examples include:

set INGREDIENTS;
data;
??? Up to here ???

\begin{verbatim}
display {i in INGREDIENTS} Percentage[i];
\end{verbatim}


If you forget the {\tt ;}, then the {\tt ampl:} prompt will be replaced by the {\tt 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 {\tt ;}. AMPL will then interpret you AMPL command and display any problems.

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 {\tt .mod} file. This file contains all set, variable, and parameter definitions,
as well as all constraints and the objective function. It contains no 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 {\tt model;}
and then using the {\tt include} command to import the model file, or else
typing in the commands for the AMPL model directly at the {\tt ampl:} prompt.


Alternatively, you can type {\tt model <filename>.mod;}.



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 {\tt data;}
at the AMPL prompt {\tt ampl:} (and switches back to the model environment by typing {\tt model;}).


As with entering the model formulation, it is common to store the data in a data file ({\tt <filename>.dat}). This data is then imported using the {\tt include} command, followed by the filename and a semicolon
(or by typing the AMPL commands in directly).


Again, one can use the alternative method of typing {\tt data <filename>.dat}
(which does not require a switch from the model environment).



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 {\tt .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:

\begin{verbatim}
reset;
model .mod;
data .dat;
.
.
.
\end{verbatim}

and you run this file using the {\tt include} command.



Setting Data Dynamically


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}

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