I wish to maximize a discrete function whose variable are array indices. Here's a toy version of it:
pselect[A_, lenA_, cindices_] :=
Product[A[[r, cindices[[r]]]], {r, 1, lenA}];
Here's an example instance of the problem:
myArray = {{37, 20, 27, 35, 39}, {36, 32, 35, 39}, {28, 36, 30,
28}, {33, 38, 25}};
myindices = {2, 4, 3, 1};
pselect[myArray, 4, myindices]
(* 772200 *)
I specified (apparently incorrectly) the maximization like this:
NMaximize[{pselect[myArray, 4, ci],
ci \[VectorLessEqual] {5, 4, 4, 3}},
ci \[Element] Vectors[4, PositiveIntegers]]
which complains bitterly
Part::partd: Part specification ci[[1]] is longer than depth of object.
Part::pkspec1: The expression ci[[1]] cannot be used as a part specification.
Part::partd: Part specification ci[[2]] is longer than depth of object.
Part::pkspec1: The expression ci[[2]] cannot be used as a part specification.
Part::partd: Part specification ci[[3]] is longer than depth of object.
General::stop: Further output of Part::partd will be suppressed during this calculation.
Part::pkspec1: The expression ci[[3]] cannot be used as a part specification.
General::stop: Further output of Part::pkspec1 will be suppressed during this calculation.
but followed by the correct solution:
{2.08073*10^6, {ci -> {5, 4, 2, 2}}}
How to specify the problem without generating errors?
Thank you!