Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
<-- 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. | |||||||
![]() | ||||||||
Line: 55 to 67 | ||||||||
![]() | ||||||||
Changed: | ||||||||
< < | As with entering the model formulation, it is common to store the data for a specific problem in a data file (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 (include command, followed by the filename and a semicolon (or by typing in the AMPL commands in directly). | |||||||
![]() | ||||||||
Line: 68 to 80 | ||||||||
Scripting in AMPLA 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. | |||||||
![]() 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; | |||||||
![]() | ||||||||
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 | ||||||||
![]() | ||||||||
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. | |||||||
![]() Running AMPL filesOnce you have finished editing your AMPL files, you can run them by | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
|