Difference: ParametersInAMPL (3 vs. 4)

Revision 42008-03-02 - MichaelOSullivan

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

Parameters in AMPL

Line: 8 to 8
 
  1. Parameter Bounds
  2. Default Values
  3. Defining a Parameter
Changed:
<
<
  1. Accessing a Parameter
>
>
  1. Accessing a Parameter
 

Description

Parameters hold "hard" values in AMPL. The values of parameters can be defined and changed in AMPL, but a solver will not change them while looking for an optimal solution.
Line: 174 to 174
 ... ;
Changed:
<
<
??? Up to here ???

Defining Multiple Parameters

Using the {\tt :} operator, multiple parameters may be defined at once. Simply state the names of the parameters and the {\tt :=} operator. Then list the set elements and values on the following rows.

\begin{verbatim} param: ... : <value1,1> <value1,2> ... <value2,1> <value2,2> ... ; \end{verbatim}

If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.

\begin{verbatim}

>
>

Defining Multiple Parameters

Using the : operator, multiple parameters may be defined at once. Simply state the names of the parameters and the := operator. Then list the set elements and values on the following rows.
param:     <name1>    <name2>    ... :
<element1> <value1,1> <value1,2> ...
<element2> <value2,1> <value2,2> ...
 ;
If a parameter is not defined or the default value is sufficient, use the . operator.

 model;

# The lower and upper bounds on the requirements

Line: 199 to 197
 FIBRE . 2.0 SALT . 0.4 ;
Changed:
<
<
\end{verbatim}

This approach also works for 2-dimensional parameters and lists, for the American Steel problem this allows us to "cut-and-paste" the list of arc properties

\begin{verbatim} From node To node Cost Minimum Maximum Youngstown Albany 500 - 1000 Youngstown Cincinnati 350 - 3000 Youngstown Kansas City 450 1000 5000 Youngstown Chicago 375 - 5000 etc \end{verbatim}

>
>
This approach also works for 2-dimensional parameters and lists, for the American Steel problem this allows us to "cut-and-paste" the list of arc properties

From node To node Cost Minimum Maximum
Youngstown Albany 500 - 1000
Youngstown Cincinnati 350 - 3000
Youngstown Kansas City 450 1000 5000
Youngstown Chicago 375 - 5000
etc
 becomes
Changed:
<
<

\begin{verbatim}

>
>

 param: Cost Min Max:= Youngstown Cincinnati 350 0 3000 Youngstown 'Kansas City' 450 1000 5000 ... Chicago Gary 120 0 4000 ;
Changed:
<
<
\end{verbatim}

>
>
 
Changed:
<
<

Accessing a Parameter

Parameter values are accessed by specifying the indices of the parameter you want to access within {\tt [} and {\tt ]}.

Examples

See {\tt Cost} and {\tt Contributes} below.

\begin{verbatim}

>
>
Return to top

Accessing a Parameter

Parameter values are accessed by specifying the indices of the parameter you want to access within [ and ].

Examples

See Cost and Contributes below.

 # Objective: minimise the cost per (100g) can
Changed:
<
<
minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];
>
>
minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Amount[i];
  # Constraints: Meet the nutritional requirements

subject to MeetRequirement {r in REQUIREMENTS}:

Changed:
<
<
Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i] <= Max[r]; \end{verbatim}

>
>
Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r];

Return to top

-- MichaelOSullivan - 02 Mar 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