Assign the specified values to a 2-d parameter, using the two dimensions
as two indices.
For example, the \(m \times n\) matrix:
\[\begin{split}`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)`\end{split}\]
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:
\[\begin{split}`A = \left( \begin{array}{cccc} 11 & 12 \\
21 & 22 \\ 31 & 32 \end{array} \right)`\end{split}\]
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[6];
double rows[3];
double cols[2];
for (int i = 0; i < 3; i++) {
rows[i] = i + 1;
for (int j = 0; j < 2; j++)
values[i * 2 + j] = (i + 1) * 10 + (j + 1);
}
for (int i = 0; i < 2; i++)
cols[i] = i + 1;
a.setValues(3, rows, 2, cols, values, false);
- Parameters
num_rows – Number of rows
row_indices – Indices of the rows
num_cols – Number of rows
col_indices – Indices of the rows
data – Values to be assigned
transpose – True to transpose the values in the matrix
- Throws
-