Difference: AMPLSyntax (2 vs. 3)

Revision 32008-02-27 - MichaelOSullivan

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

The AMPL Syntax Guide

Changed:
<
<
Disclaimer This is a guide to the AMPL syntax only. For a comprehensive reference to the AMPL language see AMPL: A Modeling Language for Mathematical Programming.
>
>
Disclaimer This is a guide to the AMPL syntax only. For a comprehensive reference to the AMPL language see AMPL: A Modeling Language for Mathematical Programming.
 
  1. Commenting
  2. Using symbolic
Changed:
<
<
  1. Sets
  2. Variables
  3. Parameters
  4. Expressions
  5. Objective Functions
  6. Constraints
  7. Logical Statements
  8. Looping Statements
  9. Displaying and Printing
>
>
  1. Sets
  2. Variables
  3. Parameters
  4. Expressions
  5. Objective Functions
  6. Constraints
  7. Logical Statements
  8. Looping Statements
  9. Displaying and Printing
 
  1. Miscellaneous AMPL Commands

Commenting

Line: 22 to 23
 The # is used for commenting, any characters on a line after the # are ignored by AMPL.

Examples

Changed:
<
<
The Whiskas Cat Food Problem
# The set of all possible ingredients for the cat food set INGREDIENTS; 
The Surfboard Production Problem
param Resin {SURFBOARDS} >= 0; # Amount of resin (in kilos) needed for a board param TotalResin >= 0; # Total amount of resin available 
>
>
The Whiskas Cat Food Problem
# The set of all possible ingredients for the cat food
set INGREDIENTS;

The Surfboard Production Problem

param Resin {SURFBOARDS} >= 0; # Amount of resin (in kilos) needed for a board
param TotalResin >= 0; # Total amount of resin available
 

Using =symbolic

The symbolic keyword is used to create parameters that represent character strings. Usually they are used to represent members of 1-dimensional sets or part of a tuple for multi-dimensional sets. However, they can also be used to represent file names or to automatically build labels (for entry in a set, for example).

Example. Searching a 1-Dimensional set

Changed:
<
<
param gotcha symbolic within SET; for {s in SET} {   if  then     let gotcha := s; } # gotcha now contains the (last) element in SET that satisfies the condition 
>
>
param gotcha symbolic within SET;
for {s in SET} {
  if  then
    let gotcha := s;
}
# gotcha now contains the (last) element in SET that satisfies the condition
 

Example. Searching a 2-Dimensional Set

Changed:
<
<
set SET1; set SET2;  set TWO_D_SET within SET1 cross SET2;  param got_one symbolic within SET1; param got_two symbolic within SET2;  for {(s, t)  in TWO_D_SET} {   if  then {     let got_one := s;     let got_two := t;   } } # (got_one, got_two) now contains the (last) element in TWO_D_SET # that satisfies the condition 
>
>
set SET1;
set SET2;

set TWO_D_SET within SET1 cross SET2;

param got_one symbolic within SET1;
param got_two symbolic within SET2;

for {(s, t)  in TWO_D_SET} {
  if  then {
    let got_one := s;
    let got_two := t;
  }
}
# (got_one, got_two) now contains the (last) element in TWO_D_SET
# that satisfies the condition
 
Changed:
<
<
To build labels for set elements you need a symbolic parameter and the parts of the label. You can then "glue" the parts of the label together by enclosing the label within ( and ) and joining the parts with &. The parts can be set elements, strings or numbers. Numbers are converted to strings using the =%g= format from =printf= .
>
>
To build labels for set elements you need a symbolic parameter and the parts of the label. You can then "glue" the parts of the label together by enclosing the label within ( and ) and joining the parts with &. The parts can be set elements, strings or numbers. Numbers are converted to strings using the %g format from printf .
 

Example. Dynamically Building a Set

Changed:
<
<
param name symbolic;  let SUPPLY_NODES := {}; for {s in SUPPLY_LOCATIONS} {   let name := (s & '-Woodchips');   let SUPPLY_NODES := SUPPLY_NODES union {name};   let Supply[name] := MaterialSupply[s, 'Woodchips'];   let {d in DEMAND_NODES} Cost[name, d] := TransportationCost[s, d];   let dummyDemandCost[name] := DisposalCost['Woodchips']; } 
>
>
param name symbolic;

 
Changed:
<
<

Sets in AMPL

Variables

Parameters

Expressions

Objective Function

Constraints

Logical Statements

Looping Statements

Displaying and Printing

Miscellaneous AMPL Commands

>
>
let SUPPLY_NODES := {}; for {s in SUPPLY_LOCATIONS} { let name := (s & '-Woodchips'); let SUPPLY_NODES := SUPPLY_NODES union {name}; let Supply[name] := MaterialSupply[s, 'Woodchips']; let {d in DEMAND_NODES} Cost[name, d] := TransportationCost[s, d]; let dummyDemandCost[name] := DisposalCost['Woodchips']; }
  -- MichaelOSullivan - 27 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