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