A function returning linctr cannot be used in place of a linctr variable. Is that correct? It does not give any compile error or warning when I use it to invoke a procedure e.g. settype. Please help me understand what is the usage of such a function that returns a linctr?

Sample:

function testReturnCtr (s: string) : linctr

returned := carrtest(s)

end-function

declarations

carrrng : set of string

carrtest : dynamic array(carrrng) of linctr

end-declarations

create (carrtest('1'))

settype(testReturnCtr('1'), CT_GEQ)

Completing your example to a runnable model as follows:

model "test ctr in subr"

declarations

carrrng : set of string

carrtest : dynamic array(carrrng) of linctr

R = 1..5

x: array(R) of mpvar

end-declarations

function testReturnCtr (s: string) : linctr

returned := carrtest(s)

end-function

create (carrtest('1'))

carrtest('1'):= sum(i in R) x(i) <= 10

settype(testReturnCtr('1'), CT_GEQ)

exportprob

end-model

results in this output:

Subject To

_R1: x(1) + x(2) + x(3) + x(4) + x(5) >= 10

carrtest(1): x(1) + x(2) + x(3) + x(4) + x(5) <= 10

The function 'testReturnCtr' returns a copy of your constraint that then gets modified by 'settype'.

If you want to modify/retrieve the constraint itself you would have to pass it as an argument into the subroutine (such as is the case in mmxprs subroutines like 'getiis', 'getinfcause' or 'getloadedlinctrs'). Only if you wish to create a new constraint then you might consider using such a function (similarly to the mmxprs subroutines 'indicator', 'implies' or 'xor').