Hello everybody,
I am trying to write the code of UTADIS method. In this code I could not write a summation function.
In the function I have an index s for the summation. However the upper bound of the summation depends on a parameter which is r(j,k). And, I sum w(j,s). Related mathematical formulation can be seen in the red part of the pictiure.
In this formulation, s represent the intervals and r(j,k) represents the interval that alternative k belongs to criterion j. Also w(j,s) is utility value corresponding to interval s and criterion j.
How can write such a summation expression?
Please help me.
Thank a lot
Summation with parameter
Summation with parameter
 Attachments

 image.png (8.77 KiB) Viewed 206 times
Re: Summation with parameter
Hi
You can use the dollar sign to restrict the summation:
If this is not what you are looking for, please send your code with the summation, parameter and the sets defined, even if it doesn't work, so it is easier for us to help you.
Cheers
Renger
You can use the dollar sign to restrict the summation:
Code: Select all
sum((i,j,k)$r(j,k), ...
Cheers
Renger
____________________________________
Enjoy modeling even more: The lazy economist
Enjoy modeling even more: The lazy economist
Re: Summation with parameter
Hi,
Thanks for your answer. I will use it in another part of my code.
In my problem:
Indexes:
s intervals for each criteria (1,2,..,pp(j)) > [I write this part as " s /1*pp(j)/ " it gives error 764 ]
j number of criteria
k training data set elements
Parameters:
p(j) number of breakpoints
pp(j) number of intervals for criterion j which is (p(j)1)
r(j,k) interval for alternative k in criteria j
a(j,k) value for alternative k on criteria j
Decision Variable:
w(j,s) utility value for interval s and criterion j
s is an index but its upper bound is depend on parameter pp(j) and r(j,k). Both pp(j) and r(j,k) give interval value which is actually s. But the representation does not contain each other. Therefore I could not write the summation.
I have same problem in the below constraint also. If j changes, the upper bound of the summation also changes. But I can not write the relateed code for this problem. (Note: In the picture upper bound is p(j)1, but I write it with another parameter pp(j).)
Thanks for your answer. I will use it in another part of my code.
In my problem:
Indexes:
s intervals for each criteria (1,2,..,pp(j)) > [I write this part as " s /1*pp(j)/ " it gives error 764 ]
j number of criteria
k training data set elements
Parameters:
p(j) number of breakpoints
pp(j) number of intervals for criterion j which is (p(j)1)
r(j,k) interval for alternative k in criteria j
a(j,k) value for alternative k on criteria j
Decision Variable:
w(j,s) utility value for interval s and criterion j
s is an index but its upper bound is depend on parameter pp(j) and r(j,k). Both pp(j) and r(j,k) give interval value which is actually s. But the representation does not contain each other. Therefore I could not write the summation.
I have same problem in the below constraint also. If j changes, the upper bound of the summation also changes. But I can not write the relateed code for this problem. (Note: In the picture upper bound is p(j)1, but I write it with another parameter pp(j).)
 Attachments

 image.png (3.88 KiB) Viewed 146 times
Re: Summation with parameter
Hi
I am not sure if you really need to have s defined as a set based on pp(j). If you define s over all possible intervals and use the $conditions in the summation, all should be fine.
However, you could also use an explicit mapping (look for mapping in the Gams documentation)
Now you can use the mapping in the sums sum(mapS_J, ....).
Hope this helps
Cheers
Renger
Code: Select all
sum(j$(ord(j) q), sum(s$(ord(s) < pp(j)1), ...
However, you could also use an explicit mapping (look for mapping in the Gams documentation)
Code: Select all
set mapS_J(s,j) Mapping from intervals s to condition j
/1.1, 2.1
* map for criterion 1 the intervals 1 and 2
1.2, 2.2, 3.2
...;
/
Hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: The lazy economist
Enjoy modeling even more: The lazy economist
Re: Summation with parameter
Hi,
First of all , thanks a lot for your answers.
In my code, I defined map like below:
mapK_J_S(k,j,s) Allowed combinations of k and j and s /1.1.0 , 1.2.0 , 1.3.0 , 1.4.1 ,2.1.0 , 2.2.0 , 2.3.1 , 2.4.1 , 3.1.0 , 3.2.1 , 3.3.0 , 3.4.0 , 4.1.0 , 4.2.1 , 4.3.0 , 4.4.1 , 5.1.1 , 5.2.0 , 5.3.1 , 5.4.1 , 6.1.1 , 6.2.1 , 6.3.1 , 6.4.0 , 7.1.2 , 7.2.0 , 7.3.0 , 7.4.0 , 8.1.2 , 8.2.0 , 8.3.1 , 8.4.1 ,9.1.2 , 9.2.1 , 9.3.0 , 9.4.1 /
In the mapping s is the r(j,k) values.
And I use the mapping in equation like below:
class1(k).. sum((j,s)$(mapK_J_S(k,j,s)),w(j,s))  u('1')+ epsplus(k) =g= sigma1;
However, code generates the w(j,s) values for only the specific s value which is defined in map.
For example:
For k= 9 the equation should be w(1,1)+w(1,2)+w(2,1)+w(4,1)  u('1')+ epsplus(k) =g= sigma1;
However the code gives only w(1,2)+w(2,1)+w(4,1)  u('1')+ epsplus(k) =g= sigma1. It did not sum s values from 1 to 2 for j=1.
How can I fix my code? Do you have any idea?
First of all , thanks a lot for your answers.
In my code, I defined map like below:
mapK_J_S(k,j,s) Allowed combinations of k and j and s /1.1.0 , 1.2.0 , 1.3.0 , 1.4.1 ,2.1.0 , 2.2.0 , 2.3.1 , 2.4.1 , 3.1.0 , 3.2.1 , 3.3.0 , 3.4.0 , 4.1.0 , 4.2.1 , 4.3.0 , 4.4.1 , 5.1.1 , 5.2.0 , 5.3.1 , 5.4.1 , 6.1.1 , 6.2.1 , 6.3.1 , 6.4.0 , 7.1.2 , 7.2.0 , 7.3.0 , 7.4.0 , 8.1.2 , 8.2.0 , 8.3.1 , 8.4.1 ,9.1.2 , 9.2.1 , 9.3.0 , 9.4.1 /
In the mapping s is the r(j,k) values.
And I use the mapping in equation like below:
class1(k).. sum((j,s)$(mapK_J_S(k,j,s)),w(j,s))  u('1')+ epsplus(k) =g= sigma1;
However, code generates the w(j,s) values for only the specific s value which is defined in map.
For example:
For k= 9 the equation should be w(1,1)+w(1,2)+w(2,1)+w(4,1)  u('1')+ epsplus(k) =g= sigma1;
However the code gives only w(1,2)+w(2,1)+w(4,1)  u('1')+ epsplus(k) =g= sigma1. It did not sum s values from 1 to 2 for j=1.
How can I fix my code? Do you have any idea?
Re: Summation with parameter
Hi
The element 9.1.1 is not a member of the mapping, so it is not accounted for. You only have 9.1.2 , 9.2.1 , 9.3.0 , 9.4.1, so you should get w(1,2)+w(2,1)+ w(3,0) + w(4,1). It looks like w(3,0) is zero, so it drops out in the listing.
Cheers
Renger
The element 9.1.1 is not a member of the mapping, so it is not accounted for. You only have 9.1.2 , 9.2.1 , 9.3.0 , 9.4.1, so you should get w(1,2)+w(2,1)+ w(3,0) + w(4,1). It looks like w(3,0) is zero, so it drops out in the listing.
Cheers
Renger
____________________________________
Enjoy modeling even more: The lazy economist
Enjoy modeling even more: The lazy economist
Re: Summation with parameter
Hi,
The first code is worked Thanks a lot for your help
And I have one more question. I hope it will be the last one.
For the whole constraint in the picture I write the below code part however for the red squared part give errors.
In this case, I am trying to restict the index (s) of a parameter (w(j,s)) with another parameter (r(j,k))
And also s and t are aliased indexes.
Do you have any idea how can I solve this problem?
class1(k).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum(j,w(j,s)$(ord(s)=r(k,j))*((a(j,k)aa(j,t)$(ord(t)=r(j,k)))/(aa(j,t)$(ord(t)=r(j,k)1)aa(j,t)$(ord(t)=r(j,k)))))  u('1') + epsplus(k) =g= sigma1;
Thanks a lot again
The first code is worked Thanks a lot for your help
And I have one more question. I hope it will be the last one.
For the whole constraint in the picture I write the below code part however for the red squared part give errors.
In this case, I am trying to restict the index (s) of a parameter (w(j,s)) with another parameter (r(j,k))
And also s and t are aliased indexes.
Do you have any idea how can I solve this problem?
class1(k).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum(j,w(j,s)$(ord(s)=r(k,j))*((a(j,k)aa(j,t)$(ord(t)=r(j,k)))/(aa(j,t)$(ord(t)=r(j,k)1)aa(j,t)$(ord(t)=r(j,k)))))  u('1') + epsplus(k) =g= sigma1;
Thanks a lot again
Re: Summation with parameter
Hi
Could you post the code or send it tome, so I can reproduce the error and debug it?
Cheers
Renger
Could you post the code or send it tome, so I can reproduce the error and debug it?
Cheers
Renger
____________________________________
Enjoy modeling even more: The lazy economist
Enjoy modeling even more: The lazy economist
Re: Summation with parameter
Hi
You are on the right track:
however, you get an error "Uncontrolled set entered as constant" below sum(j,w(j,s)$(ord(s). You should not only sum over j, but also over s, e.g.
There remain errors (for example, you use a(k,j) although it is declared as a(j,k), but I leave them to you.
Cheers
Renger
Enjoy modeling even more: The lazy economist
You are on the right track:
Code: Select all
sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum(j,w(j,s)$(ord(s)=r(k,j))*((a(j,k)aa(j,t)$(ord(t)=r(j,k)))/(aa(j,t)$(ord(t)=r(j,k)1)aa(j,t)$(ord(t)=r(j,k)))))  u('1') + epsplus(k) =g= sigma1;
Code: Select all
sum((j,s), w(j,s)$(ord(s).
Cheers
Renger
Enjoy modeling even more: The lazy economist
____________________________________
Enjoy modeling even more: The lazy economist
Enjoy modeling even more: The lazy economist
Re: Summation with parameter
Hi Renger,
Thanks a lot for your answer. The model did not give any syntax error after your correction.
But now, the code exits with code 3 which is error for division by 0. However, I checked whole code, the paranthesis, defined parameters and their values many times. Any of them should not cause such a division. And also I write constraints for k=1 and k=3 by hand. The constraint for k=1 is generated properly, while the constraint for k=3, is not generated properly. In the previous answer, you stated there exist some additional error. I think I corrected them, but may be I missed one error. And that error causes wrong constraint generations. The final version of the constraints is below. The only part I changed in the previous code is these constraints.
Could you check them? Is there any other error which I could not recognize?
Thanks a lot again and again.
class1(k)$(mapK_I(k,'1')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('1') + epsplus(k) =g= 0.0001 ;
class2plus(k)$(mapK_I(k,'2')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('2') + epsplus(k) =g= 0.0001 ;
class2minus(k)$(mapK_I(k,'2')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('1')  epsminus(k) =l= 0.0001 ;
class3(k)$(mapK_I(k,'3')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('2')  epsminus(k) =l= 0.0001 ;
Thanks a lot for your answer. The model did not give any syntax error after your correction.
But now, the code exits with code 3 which is error for division by 0. However, I checked whole code, the paranthesis, defined parameters and their values many times. Any of them should not cause such a division. And also I write constraints for k=1 and k=3 by hand. The constraint for k=1 is generated properly, while the constraint for k=3, is not generated properly. In the previous answer, you stated there exist some additional error. I think I corrected them, but may be I missed one error. And that error causes wrong constraint generations. The final version of the constraints is below. The only part I changed in the previous code is these constraints.
Could you check them? Is there any other error which I could not recognize?
Thanks a lot again and again.
class1(k)$(mapK_I(k,'1')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('1') + epsplus(k) =g= 0.0001 ;
class2plus(k)$(mapK_I(k,'2')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('2') + epsplus(k) =g= 0.0001 ;
class2minus(k)$(mapK_I(k,'2')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('1')  epsminus(k) =l= 0.0001 ;
class3(k)$(mapK_I(k,'3')).. sum(j, sum(s$(ord(s)<=r(k,j)1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)1))aa(j,s)$(ord(s)=r(k,j)))))  u('2')  epsminus(k) =l= 0.0001 ;