Hello!
Apologies if there is another topic that addresses this, I was unable to find one that helped me fix this problem. I'm relatively new to AMPL and am trying to do a sensitivity analysis on an AMPL problem.
To find the sensitivity of a parameter, I am using the let function in a for loop to first compute all the values I want to try as a fraction of the original value of the parameter. I then use another for loop with the let function to use those values in the solver. This works well for parameters that are single values, however I am having difficulty with writing a script that will do this for parameters that are indexed over multiple sets.
In the simplified problem I have attached to this message, I would like to test values of the cost of one index value of a set (here it is 'Contour_Farming' in Set ag_bmp) over all of the indexes of another set (c in comid). To do this I am trying this:
set Sens;
let Sens := {0.01, 0.1, 0.5, 1, 5, 10, 100};
param SENSVALS {Sens, comid};
param frac;
for {s in Sens} {
let frac := s;
for {c in comid} {
let SENSVALS[s,c] := frac * ag_costs['Contour_Farming', c];
}
}
;
for {s in Sens} {
let frac := s;
for {c in comid} {
let ag_costs['Contour_Farming', c] := SENSVALS[s,c];
}
;
solve;
}
CPLEX gives an error that there is an invalid subscript ag_costs['Contour_Farming', '4594081'], and I don't know why this is the case. It is defined in the model.
How can I format this problem correctly? I think maybe I don't understand how CPLEX is calling and assigning parameters, or maybe there is a glaringly obvious syntax error that I am missing?
Thanks!
Cathy