# How to set scopes of multiple indices from one set in one constraint?

• 2 replies
• 320 views

• Newcomer
• 6 replies

Hi dear all,

I have one of my constraints in AIMMS as this:

sum[k1|k1<>l,y(k1,l)] = sum[k2|k2<>l, y(l,k2)], in which k1, k2, l are all from same set and y(k,l) as binary.

For the right hand side of this constraints, I also want to add k2<>k1, but AIMMS gives error as “The scope of index "k1" has not been specified.”

I tried to run the model without k2<>k1 but the solution gives y(k1,l)=y(l,k1)=1, which is not what I want here. So is there any way to add this k2<>k1 in this constraint?

### 2 replies

Userlevel 4 +3

I don’t quite get how you can have k2<>k1 on this particular constraint, since k1 is already a running index on the left hand side, you cannot get a specific k1 outside the sum. For example, if the set contains 4 elements:{ s1,s2,s3,s4}, and  l=s4, so on the left you have

y(s1,s4)+y(s2,s4)+y(s3,s4)

what do you want the right side to be?

Hi @deannezhang

This is for a routing problem like TSP, y(k,l) is binary indicating whether location l will be visited immediately after location k.

So what I want from this constraint is to make sure the input degree must be equal to the output degree. But without setting k1<>k2, the solution will return a loop between two locations as y(s1,s4)=y(s4,s1), which is not what I’m looking for (and I couldn’t directly set y(k,l)|l>k since it will set the model to infeasible).

Now I got what you are saying. So on my right side, the value of k2 actually depends on the running result of k1 of the left side.That’s why I couldn’t add it.

So if I couldn’t directly set k1<>k2 here, is there any other way to get this done? Like using a subset or something?  Or will this be solved after I add the subtour elimination? I’m sorry I’m really new to AIMMS and a little bit lost. Any help will be appreciated! Thanks!