AMPL's var commands do not have a feature for letting a string represent a variable's name. It is possible to get this effect, however, by writing a var command to a file and then reading it. For example,
set X = 1..5;
set Y = 1..3;
set Z = 1..25;
var v_bra_p_12 {x in X, y in Y, z in Z} := x + y + z;
param test symbolic default '';
let test := 'v_bra_p_12';
printf "display %s[1,1,23];\n", test >tempfile;
include tempfile;
When I put these statements in a file test.run and execute it, I get the desired result:
ampl: include ..\test.run;
v_bra_p_12[1,1,23] = 25
We're switching to a new, enhanced user forum.