|
From: | Xypron |
Subject: | Re: [Help-glpk] GLPK cannot compare to symbols: s1 < s2 |
Date: | Sat, 17 May 2008 10:46:53 +0200 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 (Ubuntu-1.1.9+nobinonly-0ubuntu1) |
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 |
[Prev in Thread] | Current Thread | [Next in Thread] |