Hi,
is there any possibility to use a string (stored as a parameter) as a variable name?
As an example:
var v_bra_p_12 {x,y,z}; # ← variable defined using three subscripts
param test symbolic default ‘’;
let test := ‘v_bra_p_12’;
display (test)[1,1,23]; # ← 1st try to access v_bra_p_12[1,1,23]
display ($test)[1,1,23]; # ← 2nd try to access v_bra_p_12[1,1,23]
Best regards,
Lothar
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
Ok, that’s at least a workaround. I will think about it. Again, than’s a lot Robert for the fast reply!
Bestr regards,
Lothar