Hello,
I have a problem for my PhD thesis in GAMS. The problem is I have a variable (not parameter) c(j) and I calculated it with my function. And after 5 indices the 6th indice value must be made by comparing the rest of 5 c(j) values, it is a condition. However, it has to be done by sorting as I guess. For example first five c(j) are 35, 48, 12, 45, 64 and 6th will be constrained by using the smallest of the rest of all. In that example, obviously it is 12, however I know it but the model doesnt know it, so I have to sort the c(j) in ascending, so in this way I hope I can compare by (k5) which compares c(6) and c(1) then c(7) and c(2) etc. Is there any idea how I can do it.
Thanks in advance.
sorting values in a variable
Re: sorting values in a variable
From how you describe it you seem to want this as part of an optimization model. In traditional optimization models "sorting" is not possible. You can try to reformulate this using traditional optimization techniques:
I am not sure if this is really what you want. Such a c sequence will be "boring" because all values after j=5 will be fixed at the smallest value of c(1)c(5).
Michael
 make a new variable c5min(j) with "c5min(j) = min(c(j5),c(j4),c(j3),c(j2),c(j1))"
 add constraint c(j) = c5min(j)
I am not sure if this is really what you want. Such a c sequence will be "boring" because all values after j=5 will be fixed at the smallest value of c(1)c(5).
Michael

 User
 Posts: 5
 Joined: 1 month ago
Re: sorting values in a variable
Actually, that is what I want to do below.
a(j) c(j)
1 60 72
2 64 95
3 66 38
4 68 65
5 ???
the last indice for a(j) must be under the value of c(j)  5, it may be good for all of them. but, there is also a constraint for a(j) like max or min value for a(j) as determined in parameters so not all c(j) can provide, model has to choose. I want to take smallest c(j) then I will compare it regarding the max and min value for a(j), if it is correct, I will count it in a summation of binary variable, so if there is correct at least 1 time it will be 385=33 for value of a(5) then it is not important that all c(j) provides the constraint or not because at least 1 is enough for that.
a(j) c(j)
1 60 72
2 64 95
3 66 38
4 68 65
5 ???
the last indice for a(j) must be under the value of c(j)  5, it may be good for all of them. but, there is also a constraint for a(j) like max or min value for a(j) as determined in parameters so not all c(j) can provide, model has to choose. I want to take smallest c(j) then I will compare it regarding the max and min value for a(j), if it is correct, I will count it in a summation of binary variable, so if there is correct at least 1 time it will be 385=33 for value of a(5) then it is not important that all c(j) provides the constraint or not because at least 1 is enough for that.
Re: sorting values in a variable
I am not sure I follow completely, but I think with the pointers I send earlier your should have enough information to implement this.
Michael
Michael

 User
 Posts: 5
 Joined: 1 month ago
Re: sorting values in a variable
Thank you very much again.