Page 2 of 2
Re: Summation with parameter
Posted: Mon Jul 15, 2019 7:06 am
by Renger
I can't check your code without the initialization of your variables (the code to initialize the variable w for example).
Cheers
Renger
Re: Summation with parameter
Posted: Mon Jul 15, 2019 11:11 pm
by mrv_ce
Hi Renger,
I sent my code to you in DM. Could you check it? I tried different index values (for k=1 and k=3) to check the generated constraints but they gave different results. Therefore I could not understand the problem in code and constraints. And also I can not understand the division by zero error. It should not give such an error.
I hope you can understand the problem of code. Please help me.
Thanks a lot again.
Re: Summation with parameter
Posted: Tue Jul 16, 2019 1:41 am
by mrv_ce
Hello again,
I worked on the code again. And I noticed while checking all indices in a constraint; which is j and s; the constraint generates denominator as 0. Therefore, the code gives error of division by zero . To get rid of this problem, I should write the denominator part not equal to zero as a condition. But, I could not write this condition.
I think, the condition should be " aa(j,s)$(ord(s)=(r(k,j)-1))-aa(j,s)$(ord(s)=r(k,j)) " part is not equal to zero.
And also this condition will be in below constraint. But I can not place it.
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 ;
How can I write such a condition and where this condition should be in the constraint?
Please, can you help me for this conditional code part?
Thanks a lot.
Re: Summation with parameter
Posted: Tue Jul 16, 2019 7:34 am
by Renger
Hi
You can define a parameter like this:
Code: Select all
parameter cond(k,j,s);
cond(k,j,s)= (aa(j,s)$(ord(s)=(r(k
,j)-1))-aa(j,s)$(ord(s)=r(k,j)));
and then rewrite the equation as
Code: Select all
class1(k)$(mapK_I(k,'1')).. sum(j, sum(s$(ord(s)<=r(k,j)-1), w(j,s))) + sum((j,s)$cond(k,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 ;
Same thing for the other equations.
Cheers
Renger