Skip to main content

In my application, I need to do some stuff with subsets of different sizes of some superset. So I created a set containing the sizes of the subsets and loop over this set of sizes. In each iteration, I extract the subset from the big set using NBest procedure.

The sizes of the subsets are ordered in descending order. The use of NBest raises the warning “The local index "_i_SizeOfSubset" is modified inside the for loop.  The condition of the for loop will be re-evaluated, which can be time consuming.  For details on this warning message see the help of the option warning_time_consuming_for_threshold.”.

I don’t understand why _i_SizeOfSubset needs to be modified if I pass it to NBest. Using val(_i_SizeOfSubset) does not help either.

Could somebody explain to me please, why the warning is issued, and how this could be formulated without modification of _i_SizeOfSubset inside the loop?

Procedure PR_SampleLoop {
Body: {
_S_SizeOfSubset := {1 .. card(S_BigSet)};

for (_i_SizeOfSubset) do

!Raises "Warning: The local index "_i_SizeOfSubset" is modified inside the for loop.
! The condition of the for loop will be re-evaluated, which can be time consuming.
! For details on this warning message see the help of the option warning_time_consuming_for_threshold."
_S_SmallSubset := NBest(i_ElementOfBigSet,
ord(i_ElementOfBigSet),
_i_SizeOfSubset);

!Do some stuff with _S_SmallSubset
endfor;
}
Set _S_SmallSubset {
SubsetOf: S_BigSet;
Index: _i_SmallElement;
OrderBy: User;
}
Set _S_SizeOfSubset {
SubsetOf: Integers;
Index: _i_SizeOfSubset;
Property: ElementsAreNumerical;
OrderBy: -_i_SizeOfSubset;
}
}


DeclarationSection __unnamed {
Set S_BigSet {
Index: i_ElementOfBigSet;
Definition: {
ElementRange(From : 1,
To : 1000,
Prefix : "Element_");
}
}
}

 

Hi, @Benedikt.

I don’t understand why _i_SizeOfSubset needs to be modified if I pass it to NBest

I think, it doesn’t matter to AIMMS if you call other procedure/function (NBest) to change _S_SizeOfSubset (_i_SizeOfSubset), you are still doing it inside its own “for” loop, hence it can lead to strange behaviors. That’s why AIMMS is reevaluating the elements that it can go through.

 

I needed to understand better you code, but when you face problems like this (recursive-style), you can create an auxiliary local set to map the elements that you already considered.


Other idea is to use while (condition) instead of for…


@Benedikt , this warning seems to be popping up only when these sets are locally declared. If you declare s_SizeOfSubset globally, there’s no warning. We will investigate this further.

 

Modifying the for loop with a keyword as suggested in the description of the warning also returns same results. 

 

ordered for _i_SizeOfSubset do

endfor

 

If you are using ord(_i_SizeOfSubset), I wonder what is the need to order this set in a decreasing manner ? 


@mateusarakawa :

I think, it doesn’t matter to AIMMS if you call other procedure/function (NBest) to change _S_SizeOfSubset (_i_SizeOfSubset), you are still doing it inside its own “for” loop, hence it can lead to strange behaviors. That’s why AIMMS is reevaluating the elements that it can go through.

From my point of view, passing _i_SizeOfSubset as the third(!) argument to NBest, does not modify the contents of _S_SizeOfSubset. Please note that I’m getting the n best elements of S_BigSet and store them in _S_SmallSet, which are both unrelated to _S_SizeOfSubset.

@mohansx : In NBest, I used ord(i_ElementOfBigSet) as the expression to order S_BigSet, not ord(_i_SizeOfSubset). In my real application, I order S_BigSet based on a more complicated criteria, which I left out for the simplicity of the example.

I would like to order _S_SizeOfSubset in decreasing order, because the “do some stuff with _S_SmallSubset” depends on that we start with the subset of highest cardinality and continue with smaller and smaller subsets of S_BigSet.

Thank you both for your help. I’ll probably follow your suggestion, @mohansx , and declare S_SizeOfSubset globally, until this get’s fixed.

 


@Benedikt , a fix for this has been released in version 4.73 earlier today !


Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator