Hello Andrew,
Moreover, probably it would be reasonable to have a function, say,
sprintf, to convert one or several values to a character string to be
assigned to a symbolic parameter or used in symbolic computations.
in AMPL such a function is defined:
sprintf(fmt, exprlist ) - format arguments according to format string fmt,
exprlist is optional
The string fmt uses the same format as printf.
Example:
param T := 4;
set W := setof{t in 1..T} sprintf("W%3.1f", 0.1*t);
display W;
The information is extracted from the book
Robert Fourer, "AMPL - A modeling Language for mathematical programming", 2003
Such function would be especially useful in the context of the table statement.
Currently properly formatting fields for SQL, CSV, ... is not possible in GLPK.
It is not sufficient, because there should be a check that the
character string to be converted is correct. In glpk there are two
routines str2int and str2num intended to perform such conversion.
You are right, str2num (defined in glplib11.c) could be used instead of atof
for automatic conversion of symbols to numeric. Atof is less restrictive, it
converts a string starting with a number followed by text to a numeric
representation of the number. It simply returns 0 if the string does not start
with a number:
double a = atof(" 13 eggs"); // a is set to 13
double a = atof("eggs: 13"); // a is set to 0
Best regards
Xypron
_______________________________________________
Help-glpk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-glpk