Guest User

Untitled

a guest
Jan 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. require 'rubygems'
  2. require 'gecoder'
  3.  
  4. class ArraySum
  5. include Gecode::Mixin
  6.  
  7. def initialize
  8. weights = [1,1,1,2,3,4,5,6,7,8,9,10]
  9. selected_weights_is_a set_var([], weights)
  10. selected_weights.sum.must == 14
  11. branch_on selected_weights
  12. end
  13. end
  14.  
  15. ArraySum.new.each_solution do |solution|
  16. p solution.selected_weights.value.map{ |x| x }
  17. end
  18.  
  19. [1, 2, 3, 8]
  20. [1, 2, 4, 7]
  21. [1, 2, 5, 6]
  22. [1, 3, 4, 6]
  23. [1, 3, 10]
  24. [1, 4, 9]
  25. [1, 5, 8]
  26. [1, 6, 7]
  27. [2, 3, 4, 5]
  28. [2, 3, 9]
  29. [2, 4, 8]
  30. [2, 5, 7]
  31. [3, 4, 7]
  32. [3, 5, 6]
  33. [4, 10]
  34. [5, 9]
  35. [6, 8]
  36.  
  37. [1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  38. [2,2,2,2,2,2,2]
  39. ... # and so on
Add Comment
Please, Sign In to add comment