Hello there

Is it possible to convert strings for use in functions such as getsol()? I think that what I am looking for would be something comparable to INDIRECT() in Excel. I've read through the documentation on the procedures and functions for mmsystem, but I can't find anything that seems suitable. I attach a very simple demonstration of what I am trying to do, which when run produces the following error: "error 102: Incompatible types for parameters of `getsol'."

Any help on this would be greatly appreciated.

Thanks

----------------------------------------------------------------------

model Demo

uses "mmxprs"

declarations

PRINTLIST={"a","b"}

NUM=3

a:array(1..NUM) of mpvar

b:array(1..NUM) of mpvar

end-declarations

minimise(sum(i in 1..NUM)(a(i)+b(i))) ! This is simply to engage the solver

forall(i in 1..getsize(PRINTLIST)) do

forall(j in 1..NUM) do

writeln(getsol(PRINTLIST(i)+"("+j+")"))

end-do

end-do

end-model

It is not possible to retrieve variables via their name in "getsol". You could rewrite your model as follows:

declarations

PRINTSET: set of mpvar

NUM=3

R=1..NUM

a:array(R) of mpvar

b:array(R) of mpvar

end-declarations

minimise(sum(i in R)(a(i)+b(i)))

! Collect the variables to be printed

PRINTSET:= union(i in R) {a(i),b(i)}

forall(v in PRINTSET) writeln(getname(v), ": ", getsol(v))

or alternatively:

declarations

DESCR: array(PRINTSET: set of mpvar) of text

NUM=3

R=1..NUM

a:array(R) of mpvar

b:array(R) of mpvar

end-declarations

minimise(sum(i in R)(a(i)+b(i)))

! Build up your own descriptive texts for the variables to be printed:

forall(i in R) DESCR(a(i)):="Value of a("+i+")"

forall(i in R) DESCR(b(i)):="Value of b("+i+")"

forall(v in PRINTSET) writeln(DESCR(v), ": ", getsol(v))