I can't check your code without the initialization of your variables (the code to initialize the variable w for example).

Cheers

Renger

## Summation with parameter

### Re: Summation with parameter

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist

### Re: Summation with parameter

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.

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

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.

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

Hi

You can define a parameter like this:
and then rewrite the equation as
Same thing for the other equations.

Cheers

Renger

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)));
```

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 ;
```

Cheers

Renger

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist