## Summation Limits

Problems with syntax of GAMS
mamba
User Posts: 6
Joined: 1 month ago

### Summation Limits

Hello,

I was trying to implement my summation limits on my MIP model. but I have a problem.

My summation limits came from variables such as the sum of two variable, lower limit "x(i,k-1) + y(i)" and upper limit "x(i,k) + y(i)" and I want to use it these limits on another set such as let's say "j".
I try to write this as:
z=e=sum(i,j,k)\$((y(i)+x(i,k-1))<=ord(j),ord(j)<=(y(i)+x(i,k))),r(j)); and also tried to write this as:
z=e=sum((i,j,k)\$((y(i)+x(i,k-1))<=ord(j) and ord(j)<=(y(i)+x(i,k))),r(j));

but as a result I get errors in both alternative and I am not sure how to fix this, In the first alternative, I guess I am doing something wrong about using ord(j) and in the second alternative, I guess I cannot use "and" in MIP. What should I do? Anyone can help me about this?

Thank you for everything.
Best Regards,
Husam

abhosekar
Moderator Posts: 92
Joined: 3 months ago

### Re: Summation Limits

It does not make sense to have summation limits based on variable values. A constraint that changes based on variable values is not a well defined constraint and it is not allowed in optimization.

If you are sure there is no other way, then you have to use big-M formulation. i.e. declare a binary variable b(j) which will be 1 if the conditions are satisfied and 0 otherwise.

Atharv

mamba
User Posts: 6
Joined: 1 month ago

### Re: Summation Limits

Hello Dear Atharv,

First of all, thank you for your reply I understand of what you mean. I just need to ask you a quick question. My equation is actually an objective function is that make any difference? or it is still not allowed in optimization.

and again thank you for your answer. I will reconsider the equation.

Best Regards,
Husam

abhosekar
Moderator Posts: 92
Joined: 3 months ago

### Re: Summation Limits

It is not allowed even in the objective function. Also, and operator is not the problem.

Are x and y variables somehow related to ord of set j? What does set j look like? Do you define x and y using some other constraints?
If you can provide a small example, that would be great.

Atharv

mamba
User Posts: 6
Joined: 1 month ago

### Re: Summation Limits

Hello Again Dear Atharv,

I am sorry for my questions maybe it can be very basic but again I need to ask you that can i use parameter values for the summation limits? Is it possible? and I reviewed my model after your message and think about on my model. I tried to explain my model briefly. In this under conditions:
i,a truck
j store type
k time period
y(i) represents the first store to truck visit,
x(i,k) represents the number of stores truck i must visit at time k,
alpha(i) represents the last store to truck i visit,

x(i,k) depends on this equation x(i,k) = x(i,k-1)+new(i,k) - last(i,k)
x(i,k) bust be smaller or equal than "ma(i)", this represents a truck can visit at most ma(i) but truck i can visit less.
relation between alpha(i) and y(i)
y(i) < alpha(a) or y(a)<alpha(i) I use Big M method and boolean variables to satisfies that.
r(j) distance of stores from the distribution centre.

I need to calculate the minimum travel distance for the trucks.
Store j's are sorted so I want to ensure that truck i finds their own region such as 1-10 for truck 1 and 11-15 for truck2...

I hope I can explain what I wanted to do.

Thank you for everything. I wish all healthy days.
Best Regards,
Husam

abhosekar
Moderator Posts: 92
Joined: 3 months ago

### Re: Summation Limits

Husam,

It should be noted that x(i) and y(i) are general integer variables which makes this problem significantly challenging. I would suggest that you should consider a reformulation. It is often a best practice in such cases to find an existing formulation in the literature and then modifying it for your problem. One possible reformulation is as follows. This may not be the best way but just to make a point that alternative ways could be easier to model and solve.

In this case, we include binary variables such as y(j, i, k) which will be 1 if node j is visited by truck i in time period k. You can calculate the number of nodes that a truck should visit by using sum() instead of storing it in integer variables.

You can then define a positive variable d(i, j, k) which is 0 if y(i, j, k) is 0 and r(j) if y(i, j, k) is 1 using big-M formulation.
d(i, j,k) =l= M*y(i,j k);

You can then use d(i, j, k) to define your objective:
sum((i, j, k), d(i, j, k));

You can try to follow an existing formulation from the literature and then modify it for your case.

- Atharv

mamba
User Posts: 6
Joined: 1 month ago

### Re: Summation Limits

Hello Dear Atharv,
First of all, I would like to thank you for your reply.
I will try to reformulate this problem by following an existing formulation and modify for my problem.

Best Regards,
Semih