[math-fun] simple pleasures: subset-lex Gray code
I would like to do the following. GIven N items, each having a user-pre-specified positive integer "weight", I want to generate all subsets of the N items, whose sum-of-weights lies within a user-specified interval [Lo, Hi]. And I want to do it in some kind of low-change Gray-code-like order. The "weighted subset generation problem."
* Warren Smith <warren.wds@gmail.com> [Feb 07. 2012 19:53]:
I would like to do the following.
GIven N items, each having a user-pre-specified positive integer "weight", I want to generate all subsets of the N items, whose sum-of-weights lies within a user-specified interval [Lo, Hi]. And I want to do it in some kind of low-change Gray-code-like order.
The "weighted subset generation problem."
Interesting, thanks for the suggestion! (Sounds like knapsack related). I'll look into it (but not right away, there are approx 200 exams I have to correct and the deadline is, ahem, sortofish yesterday; that will be 4 thoroughly unpleasant days for me). Btw. I just did the set partition RGS in subset lex order, that one does 570M/sec and thus obliterates everything I have seen so far. 0: [ . . . . . ] 1: [ . 1 . . . ] 2: [ . 1 1 . . ] 3: [ . 1 2 . . ] 4: [ . 1 2 1 . ] 5: [ . 1 2 2 . ] 6: [ . 1 2 3 . ] 7: [ . 1 2 3 1 ] 8: [ . 1 2 3 2 ] 9: [ . 1 2 3 3 ] 10: [ . 1 2 3 4 ] 11: [ . 1 2 2 1 ] 12: [ . 1 2 2 2 ] 13: [ . 1 2 2 3 ] 14: [ . 1 2 1 1 ] 15: [ . 1 2 1 2 ] 16: [ . 1 2 1 3 ] 17: [ . 1 2 . 1 ] 18: [ . 1 2 . 2 ] 19: [ . 1 2 . 3 ] 20: [ . 1 1 1 . ] 21: [ . 1 1 2 . ] 22: [ . 1 1 2 1 ] 23: [ . 1 1 2 2 ] 24: [ . 1 1 2 3 ] 25: [ . 1 1 1 1 ] 26: [ . 1 1 1 2 ] 27: [ . 1 1 . 1 ] 28: [ . 1 1 . 2 ] 29: [ . 1 . 1 . ] 30: [ . 1 . 2 . ] 31: [ . 1 . 2 1 ] 32: [ . 1 . 2 2 ] 33: [ . 1 . 2 3 ] 34: [ . 1 . 1 1 ] 35: [ . 1 . 1 2 ] 36: [ . 1 . . 1 ] 37: [ . 1 . . 2 ] 38: [ . . 1 . . ] 39: [ . . 1 1 . ] 40: [ . . 1 2 . ] 41: [ . . 1 2 1 ] 42: [ . . 1 2 2 ] 43: [ . . 1 2 3 ] 44: [ . . 1 1 1 ] 45: [ . . 1 1 2 ] 46: [ . . 1 . 1 ] 47: [ . . 1 . 2 ] 48: [ . . . 1 . ] 49: [ . . . 1 1 ] 50: [ . . . 1 2 ] 51: [ . . . . 1 ] See everything *subset-lex* at http://www.jjj.de/fxt/demo/comb/ Simple. Fast. Good.
participants (2)
-
Joerg Arndt -
Warren Smith