choco-solver icon indicating copy to clipboard operation
choco-solver copied to clipboard

After removing of methods like size() I see no way how to iterate over values in StateIntVector

Open gregy4 opened this issue 6 years ago • 5 comments

Problem is in choco4 after commit on 1.5.2017 named 'remove deprecated code from memory'. Since I use StateIntVector in my propagator it is a problem for me.

gregy4 avatar May 25 '18 11:05 gregy4

I created pull request with the fix.

gregy4 avatar Jun 01 '18 21:06 gregy4

Can you be more about what you are using this structure for ? Because, as said in #585 , the code is buggy and does not support both addition and deletion. Using a BipartiteSet with a backtrackable index is most of the time a good practice. See for instance: http://www.cril.univ-artois.fr/~lecoutre/papers/TRICS13_sparse.pdf

Let us know before doing anything

cprudhom avatar Jun 05 '18 14:06 cprudhom

In a propagator I use it to record indexes of some instantiated tasks to not find them again since the propagator is called very often. Indexes are only added in the propagator. On iteration over structure I want to get all added indexes over all calls of the propagator except indexes removed by backtrack so the result is same as a result generated from currently instantiated tasks on a node.

If I understand it right you recommend to use ISet set = SetFactory.makeStoredSet(SetType.BIPARTITESET, tasks.length, model) instead of StateIntVector.

From first try it seems that there's no difference between BipartiteSet and StateIntVector in performance or results. What is interesting that in class comments of BipartiteSet implementation (Set_Std_Swap) is also mentioned that it does not support both addition and deletion.

gregy4 avatar Jun 05 '18 21:06 gregy4

It's a tough task to ensure that both addition and deletion are safe. But in your case, you declare a list made of all tasks at the beginning and remove some of them while going deeper in the tree search. On backtrack, removed elements will be restored.

If that's what you need, you can consider using StoredIndexedBipartiteSet or adapt it to your usage: it is simply an array of elements with a backtrackable int as index. On removal, the last element before the index is swapped with the element to remove (which should be before the index value) and the index is decreased.

Best,

cprudhom avatar Jun 06 '18 08:06 cprudhom

Thanks. Opposite direction - adding through changing a size - should be probably better in my case. It seems that it should not be problem when I looked at StoredIndexedBipartiteSet.

gregy4 avatar Jun 06 '18 09:06 gregy4