Hello Andrew,

>> In principle, you might create a numeric set, say, {1, 2, 3}, and
>> then use its elements as indices to a symbolic parameter.
The symbolic values in my case will be read from a SQL table.

Your solution would require a function to determine the index of a value in a (symbolic) set:

set S;
table ts IN 'MySQL' dsn table : S <- [S];
set N := setof{s in S} index(s, S);

If such a function existed I could change my example to:

set J;
set B := setof{j1 in J, j2 in J : index(j1, J) < index(j2, J)} (j1, j2);
display B;
data;
set J := 'A' 'B';

I would prefer to be able to directly compare symbols.

Please, find my implementation as:
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.28-strcmp/src/glpmpl01.c
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.28-strcmp/src/glpmpl03.c
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.28-strcmp/examples/strcmp.mod

Patches are available as:
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.28-strcmp/src/glpmpl01.c?r1=228&r2=202&view=patch
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.28-strcmp/src/glpmpl03.c?r1=228&r2=202&view=patch

>> Yes, I think it would be useful to add some built-in functions to
>> perform operations on symbolic values.

AMPL provides the following functions for symbols:

length(symbol) returns the number of characters,
match(symbol, regexp) returns the first match for the regular expression regexp in symbol,
symbol1 & symbols2 returns the concatenation of the strings,
sprintf("format", arg1, ...) uses the C sprintf function to create a formatted string, sub(symbol1, regexp, symbol2) returns a string where the first match of the regular expression is replaced by symbol2, gsub(symbol1, regexp, symbol2) returns a string where the all matches of the regular expression is replaced by symbol2, substr(symbol, pos) returns the subtring of symbol starting with character position pos, substr(symbol, pos, len) returns the subtring of lenght len of symbol starting with character position pos,

Best regards

Xypron
_______________________________________________
Help-glpk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-glpk

Reply via email to