Reputation: 2998
Is there a way in AMPL to declare and use temporary variables? What I mean by that is the "regular" variables used in programming (instead of model variables), especially in the .run
file, such as saving a string for repeated use in the .run
file:
some_file = sprintf(foo%u.txt, 3); # Temporary variable
print "Hello World" > some_file;
print "Hello again" > some_file;
Upvotes: 1
Views: 265
Reputation: 1573
If it's not variable within the optimisation that you're going to solve, then it's a parameter. You can change the parameter value with let
, like so:
reset;
param blah symbolic;
let blah := "hello world";
print blah;
let blah := "this parameter has changed";
print blah;
Parameters in AMPL are number by default; string params need to be explicitly declared as symbolic
.
Note that I've declared the param in a separate statement from the first assignment. If I were to assign a value in the declaration, like param blah symbolic := "hello world";
, then it would fail when I try to change the value.
Upvotes: 1