Parameter

public class Parameter extends BasicEntity<Object>

Represents an AMPL parameter. The values can be Double or String (in case of symbolic parameters).

Data can be assigned to the parameter using the methods set, setValues directly from objects of this class or using AMPL.setData and a DataFrame object.

Constructors

Parameter

public Parameter(Entity entity)

Constructor

Parameter

protected Parameter(ParameterBase impl)

Methods

get

public Object get()

Get the value of a scalar parameter.

Throws

get

public Object get(Object... key)

Get the value corresponding to key. The value will be a string or a double if the parameter is symbolic, a double otherwise. See Access to instances and values for further information on how the key can be specified.

Parameters
  • key – The key to be found

Throws
Returns

The value of the parameter for the corresponding key (String or double) or null if the specified key is not found

get

public Object get(Tuple key)

Get the value corresponding to key (passed as a Tuple). The value will be a string or a double if the parameter is symbolic, a double otherwise. See Access to instances and values for further information on how the key can be specified.

Parameters
  • key – The key (as a tuple) to be found

Throws
Returns

The value of the parameter for the corresponding key (String or double) or null if the specified key is not found

hasDefault

public boolean hasDefault()

Check if the parameter has a default initial value. In case of the following AMPL code:

param a;
param b default a;

the function will return true for parameter b.

Returns

True if the parameter has a default initial value. Please note that if the parameter has a default expression which refers to another parameter which value is not defined, this will return true.

impl

ParameterBase impl()

isSymbolic

public boolean isSymbolic()

Check if the parameter is symbolic (aka can store strings)

Returns

True if the parameter is symbolic

iterator

public Iterator<Object> iterator()

set

public void set(double index, double value)

Assign a value to the parameter at the specified index, equivalent to the AMPL code

let par[index] := value;
Parameters
  • index – Index (key) of instance to be set, can be a Tuple or an array for multidimensional parameters.

  • value – Value to set.

Throws

set

public void set(String index, double value)

set

public void set(Tuple index, double value)

set

public void set(double index, String value)

Assign a string to the parameter at the specified index, equivalent to the AMPL code:

let par[index] := value;
Parameters
  • index – Index (key) of instance to be set, can be a Tuple or an array for multidimensional parameters.

  • value – Value to set.

Throws

set

public void set(String index, String value)

set

public void set(Tuple index, String value)

set

public void set(double value)

Set the value of a scalar parameter.

Throws

set

public void set(String value)

Set the value of a scalar parameter.

Throws

setValues

public void setValues(Tuple[] indices, double[] values)

Assign the (double) values to the parameter instances with the specified indices, equivalent to the AMPL code:

let {i in indices} par[i] := values[i];
Parameters
  • indices – Index (key) of instance to be set. Each item in the array can be a Tuple or an array of objects, in case of multidimensional array.

  • values – Values to set.

Throws

setValues

public void setValues(Tuple[] indices, String[] values)

Assign the values (string or double) to the parameter instances with the specified indices, equivalent to the AMPL code:

let {i in indices} par[i] := values[i];
Parameters
  • indices – Index (key) of instance to be set. Each item in the array can be a Tuple or an array of objects, in case of multidimensional array.

  • values – Values to set.

Throws

setValues

public void setValues(double[] rowindices, double[] colindices, double[][] values, boolean transpose)

Assign the specified values to a 2-d parameter, using the two dimensions as two indices.

For example, the \(m \times n\) matrix: \(A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1n} \\ a_{21} & a_{22} & ... & a_{2n} \\ ... & ... & ... & ... \\ a_{m1} & a_{m2} & ... & a_{mn} \end{array} \right)\)

can be assigned to the AMPL parameter: param A {1..m, 1..n}; with the statement setValues(A, false).

As an example, to assign the matrix: \(A = \left( \begin{array}{cccc} 11 & 12 \\ 21 & 22 \\ 31 & 32 \end{array} \right)\)

to the AMPL paramater: param A{1..3, 1..2}; we can use the following code.

ampl.eval("param a{1..3, 1..2};");
Parameter a = ampl.getParameter("a");
double[][] values = new double[3][2];
for (int i = 0; i < 3; i++)
  for (int j = 0; j < 2; j++)
    values[i][j] = (i + 1) * 10 + (j + 1);
a.setValues(new double[] { 1, 2, 3 }, new double[] { 1, 2 }, values, false);
Parameters
  • values – Values to be assigned

  • transpose – True to transpose the values in the matrix

Throws
  • UnsupportedOperationException – If the method is called on a parameter which is not two-dimensional

  • IllegalArgumentException – If the passed array of values is not rectangular or if the sizes of ‘values’ do not correspond to the sizes of the underlying indices

setValues

public void setValues(String[] rowindices, String[] colindices, double[][] values, boolean transpose)

setValues

public void setValues(String... values)

Assign the specified values to this parameter, assigning them to the parameter in the same order as the indices in the entity.

The number of values in the array must be of the same size of the parameter, as this function will try to assign all values.

Parameters
  • values – Values to be assigned.

Throws
  • IllegalArgumentException – If multiple values are assigned to a scalar parameter, if the size of the values array is not equal to the size (number of instances) of the parameter or if trying to assign a string to a non symbolic parameter

setValues

public void setValues(double... values)

toString

public String toString()

Returns a string representation of this parameter. Equivalent to the AMPL statement:

show parameterName;