Hello dear community,
I'm using F# (so my question could be understood and possibly easily answered by C# users), I'm looking for a way to extract the information on a list of elements of tuples sets, and use that information later. Ideally, I would like to end up with a sequence in F# to be able to do lazy evaluation (which translate on the C# side as a IEnumerable<T>).
Fortunately, OPL CPLEX API provides a "GetEnumerator" on tuplesets. This method works well when I iterate on the tupleset and act immediately on the tuple (e.g. : extract an integer value or set a bound of a variable).
Unfortunately, as soon as I extract the tuple object and record it in a data structure (list, sequence, dictionary,...), it seems it becomes messed up as soon as the "GetEnumerator" falls out of scope. The behavior seems as if the returned object gets invalidated, as if it is copied in a static structure, returned to be used, then immediately collected or reused and overwritten for the next element...
When I look at the MS .NET documentation, it says the enumerator usually becomes invalidated as soon as you do such operations as adding or removing items of the collection (understandably), but I don't do such a thing, and I haven't find any specification on the element of the enumeration itself.
So now my question :
1) is this behavior of GetEnumerator normal and intended ? If so, I suggest enhancing the API documentation to avoid surprises of future developers.
2) ...otherwise, I'm I doing something wrong ? Should I try to "pin" the underlaying CPLEX object ? Or is it garbage collected as soon as GetEnumerator falls out of scope ?
3) ...or should I find another way (not using the GetEnumerator()) to end up with a clean IEnumerable<> ? Said otherwise, is there another method of another class I missed which would be better to record some specific tuples to be reused later ?
And I know I could extract all information of the tuple, instantiate it on the F# side, but this would mean duplicating all of the model elements on the F# side and I would rather aim to use the lazy evaluation for performance.
Thanks !
------------------------------
Luc Charest
------------------------------
#DecisionOptimization