gecoder 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGES +9 -1
  2. data/Rakefile +3 -0
  3. data/example/send_most_money.rb +58 -0
  4. data/ext/missing.cpp +26 -1
  5. data/ext/missing.h +2 -0
  6. data/ext/vararray.cpp +31 -11
  7. data/ext/vararray.h +6 -0
  8. data/lib/gecoder/bindings.rb +5 -5
  9. data/lib/gecoder/bindings/bindings.rb +52 -0
  10. data/lib/gecoder/interface/binding_changes.rb +16 -11
  11. data/lib/gecoder/interface/constraints.rb +28 -15
  12. data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +8 -17
  13. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +8 -3
  14. data/lib/gecoder/interface/constraints/int/arithmetic.rb +10 -15
  15. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +10 -16
  16. data/lib/gecoder/interface/constraints/int_enum/element.rb +6 -11
  17. data/lib/gecoder/interface/constraints/int_var_constraints.rb +2 -1
  18. data/lib/gecoder/interface/constraints/set/cardinality.rb +4 -7
  19. data/lib/gecoder/interface/constraints/set/connection.rb +13 -22
  20. data/lib/gecoder/interface/model.rb +52 -41
  21. data/lib/gecoder/interface/search.rb +29 -24
  22. data/lib/gecoder/interface/variables.rb +27 -15
  23. data/lib/gecoder/version.rb +1 -1
  24. data/specs/constraints/arithmetic.rb +27 -17
  25. data/specs/constraints/bool_enum.rb +4 -2
  26. data/specs/constraints/boolean.rb +5 -2
  27. data/specs/constraints/cardinality.rb +28 -8
  28. data/specs/constraints/connection.rb +58 -37
  29. data/specs/constraints/constraints.rb +2 -2
  30. data/specs/constraints/count.rb +3 -3
  31. data/specs/constraints/element.rb +5 -5
  32. data/specs/constraints/int_domain.rb +4 -2
  33. data/specs/constraints/set_domain.rb +8 -4
  34. data/specs/constraints/set_relation.rb +10 -5
  35. data/specs/int_var.rb +3 -3
  36. data/specs/model.rb +10 -9
  37. data/specs/search.rb +54 -5
  38. data/specs/spec_helper.rb +2 -0
  39. data/tasks/distribution.rake +8 -1
  40. data/tasks/specs.rake +0 -1
  41. data/vendor/rust/rust/class.rb +6 -1
  42. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +3 -3
  43. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +15 -1
  44. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +2 -0
  45. metadata +51 -21
@@ -4,7 +4,9 @@ module Gecode
4
4
  # to that solution. Returns the model if a solution was found, nil
5
5
  # otherwise.
6
6
  def solve!
7
+ GC.disable
7
8
  space = dfs_engine.next
9
+ GC.enable
8
10
  return nil if space.nil?
9
11
  @active_space = space
10
12
  return self
@@ -30,9 +32,11 @@ module Gecode
30
32
  # Yields each solution that the model has.
31
33
  def each_solution(&block)
32
34
  dfs = dfs_engine
35
+ GC.disable
33
36
  while not (@active_space = dfs.next).nil?
34
37
  yield self
35
38
  end
39
+ GC.enable
36
40
  self.reset!
37
41
  end
38
42
 
@@ -49,30 +53,46 @@ module Gecode
49
53
  #
50
54
  # Returns nil if there is no solution.
51
55
  def optimize!(&block)
52
- next_space = nil
53
- best_space = nil
54
- bab = bab_engine
55
-
56
+ # Execute constraints.
57
+ perform_queued_gecode_interactions
58
+
59
+ # Set the method used for constrain calls by the BAB-search.
56
60
  Model.constrain_proc = lambda do |home_space, best_space|
57
61
  @active_space = best_space
62
+ @variable_creation_space = home_space
58
63
  yield(self, self)
59
64
  @active_space = home_space
65
+ @variable_creation_space = nil
66
+
60
67
  perform_queued_gecode_interactions
61
68
  end
69
+
70
+ # Perform the search.
71
+ GC.disable
72
+ result = Gecode::Raw::bab(selected_space,
73
+ Gecode::Raw::Search::Config::MINIMAL_DISTANCE,
74
+ Gecode::Raw::Search::Config::ADAPTIVE_DISTANCE,
75
+ nil)
76
+ GC.enable
62
77
 
63
- while not (next_space = bab.next).nil?
64
- best_space = next_space
65
- end
78
+ # Reset the method used constrain calls and return the result.
66
79
  Model.constrain_proc = nil
67
- return nil if best_space.nil?
80
+ return nil if result.nil?
81
+
82
+ # Refresh the solution.
83
+ result.refresh
84
+ refresh_variables
85
+ @active_space = result
68
86
  return self
69
87
  end
70
88
 
71
89
  class <<self
90
+ # Sets the proc that should be used to handle constrain requests.
72
91
  def constrain_proc=(proc)
73
92
  @constrain_proc = proc
74
93
  end
75
94
 
95
+ # Called by spaces when they want to constrain as part of BAB-search.
76
96
  def constrain(home, best)
77
97
  if @constrain_proc.nil?
78
98
  raise NotImplementedError, 'Constrain method not implemented.'
@@ -91,25 +111,10 @@ module Gecode
91
111
  perform_queued_gecode_interactions
92
112
 
93
113
  # Construct the engine.
94
- stop = Gecode::Raw::Search::Stop.new
95
114
  Gecode::Raw::DFS.new(selected_space,
96
115
  Gecode::Raw::Search::Config::MINIMAL_DISTANCE,
97
116
  Gecode::Raw::Search::Config::ADAPTIVE_DISTANCE,
98
- stop)
99
- end
100
-
101
- # Creates a branch and bound engine for optimization search, executing any
102
- # unexecuted constraints first.
103
- def bab_engine
104
- # Execute constraints.
105
- perform_queued_gecode_interactions
106
-
107
- # Construct the engine.
108
- stop = Gecode::Raw::Search::Stop.new
109
- Gecode::Raw::BAB.new(selected_space,
110
- Gecode::Raw::Search::Config::MINIMAL_DISTANCE,
111
- Gecode::Raw::Search::Config::ADAPTIVE_DISTANCE,
112
- stop)
117
+ nil)
113
118
  end
114
119
 
115
120
  # Executes any interactions with Gecode still waiting in the queue
@@ -8,6 +8,26 @@ module Gecode
8
8
  @model = model
9
9
  @index = index
10
10
  @bound_space = @bound_var = nil
11
+ model.track_variable(self)
12
+ end
13
+
14
+ # Checks whether the variable is cached, i.e. whether it needs to be
15
+ # rebound after changes to a space.
16
+ def cached?
17
+ not @bound_space.nil?
18
+ end
19
+
20
+ # Forces the variable to refresh itself.
21
+ def refresh
22
+ @bound_space = nil
23
+ end
24
+
25
+ def inspect
26
+ if assigned?
27
+ "#<#{self.class} #{domain}>"
28
+ else
29
+ "#<#{self.class} #{domain}>"
30
+ end
11
31
  end
12
32
 
13
33
  private
@@ -16,6 +36,13 @@ module Gecode
16
36
  def active_space
17
37
  @model.active_space
18
38
  end
39
+
40
+ # Sends the specified method name and arguments to the bound variable.
41
+ def send_bound(method_name, *args)
42
+ @model.allow_space_access do
43
+ bind.send(method_name, *args)
44
+ end
45
+ end
19
46
  end
20
47
 
21
48
  # Creates a class for a free variable that can be bound into the specified
@@ -35,14 +62,6 @@ module Gecode
35
62
  return @bound
36
63
  end
37
64
 
38
- def inspect
39
- if assigned?
40
- "#<\#{self.class} \#{domain}>"
41
- else
42
- "#<\#{self.class} \#{domain}>"
43
- end
44
- end
45
-
46
65
  private
47
66
 
48
67
  # Delegates the method with the specified name to a method with the
@@ -58,13 +77,6 @@ module Gecode
58
77
  end
59
78
  end_code
60
79
  end
61
-
62
- # Sends the specified method name and arguments to the bound variable.
63
- def send_bound(method_name, *args)
64
- @model.allow_space_access do
65
- bind.send(method_name, *args)
66
- end
67
- end
68
80
  end_method_definitions
69
81
  return clazz
70
82
  end
@@ -1,4 +1,4 @@
1
1
  module GecodeR
2
2
  # A string representation of the Gecode/R version.
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
@@ -65,10 +65,10 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (max)' do
65
65
  # Creates an expectation corresponding to the specified input.
66
66
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
67
67
  @model.allow_space_access do
68
- rhs = rhs.bind if rhs.respond_to? :bind
68
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
69
69
  if reif_var.nil?
70
70
  if !negated and relation == Gecode::Raw::IRT_EQ and
71
- rhs.kind_of? Gecode::Raw::IntVar
71
+ !rhs.kind_of? Fixnum
72
72
  Gecode::Raw.should_receive(:max).once.with(
73
73
  an_instance_of(Gecode::Raw::Space),
74
74
  an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
@@ -89,7 +89,8 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (max)' do
89
89
  an_instance_of(Gecode::Raw::IntVar), strength)
90
90
  Gecode::Raw.should_receive(:rel).once.with(
91
91
  an_instance_of(Gecode::Raw::Space),
92
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
92
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
93
+ an_instance_of(Gecode::Raw::BoolVar),
93
94
  strength)
94
95
  end
95
96
  end
@@ -114,10 +115,10 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (min)' do
114
115
  # Creates an expectation corresponding to the specified input.
115
116
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
116
117
  @model.allow_space_access do
117
- rhs = rhs.bind if rhs.respond_to? :bind
118
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
118
119
  if reif_var.nil?
119
120
  if !negated and relation == Gecode::Raw::IRT_EQ and
120
- rhs.kind_of? Gecode::Raw::IntVar
121
+ !rhs.kind_of? Fixnum
121
122
  Gecode::Raw.should_receive(:min).once.with(
122
123
  an_instance_of(Gecode::Raw::Space),
123
124
  an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
@@ -138,7 +139,8 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (min)' do
138
139
  an_instance_of(Gecode::Raw::IntVar), strength)
139
140
  Gecode::Raw.should_receive(:rel).once.with(
140
141
  an_instance_of(Gecode::Raw::Space),
141
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
142
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
143
+ an_instance_of(Gecode::Raw::BoolVar),
142
144
  strength)
143
145
  end
144
146
  end
@@ -163,18 +165,19 @@ describe Gecode::Constraints::Int::Arithmetic, ' (abs)' do
163
165
  # Creates an expectation corresponding to the specified input.
164
166
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
165
167
  @model.allow_space_access do
166
- rhs = rhs.bind if rhs.respond_to? :bind
168
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
167
169
  if reif_var.nil?
168
170
  if !negated and relation == Gecode::Raw::IRT_EQ and
169
- rhs.kind_of? Gecode::Raw::IntVar
171
+ !rhs.kind_of? Fixnum
170
172
  Gecode::Raw.should_receive(:abs).once.with(
171
173
  an_instance_of(Gecode::Raw::Space),
172
- @var.bind, rhs, strength)
174
+ an_instance_of(Gecode::Raw::IntVar), rhs, strength)
173
175
  Gecode::Raw.should_receive(:rel).exactly(0).times
174
176
  else
175
177
  Gecode::Raw.should_receive(:abs).once.with(
176
178
  an_instance_of(Gecode::Raw::Space),
177
- @var.bind, an_instance_of(Gecode::Raw::IntVar), strength)
179
+ an_instance_of(Gecode::Raw::IntVar),
180
+ an_instance_of(Gecode::Raw::IntVar), strength)
178
181
  Gecode::Raw.should_receive(:rel).once.with(
179
182
  an_instance_of(Gecode::Raw::Space),
180
183
  an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
@@ -182,7 +185,8 @@ describe Gecode::Constraints::Int::Arithmetic, ' (abs)' do
182
185
  else
183
186
  Gecode::Raw.should_receive(:abs).once.with(
184
187
  an_instance_of(Gecode::Raw::Space),
185
- @var.bind, an_instance_of(Gecode::Raw::IntVar), strength)
188
+ an_instance_of(Gecode::Raw::IntVar),
189
+ an_instance_of(Gecode::Raw::IntVar), strength)
186
190
  Gecode::Raw.should_receive(:rel).once.with(
187
191
  an_instance_of(Gecode::Raw::Space),
188
192
  an_instance_of(Gecode::Raw::IntVar), relation, rhs,
@@ -212,18 +216,21 @@ describe Gecode::Constraints::Int::Arithmetic, ' (multiplication)' do
212
216
  # Creates an expectation corresponding to the specified input.
213
217
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
214
218
  @model.allow_space_access do
215
- rhs = rhs.bind if rhs.respond_to? :bind
219
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
216
220
  if reif_var.nil?
217
221
  if !negated and relation == Gecode::Raw::IRT_EQ and
218
- rhs.kind_of? Gecode::Raw::IntVar
222
+ !rhs.kind_of? Fixnum
219
223
  Gecode::Raw.should_receive(:mult).once.with(
220
224
  an_instance_of(Gecode::Raw::Space),
221
- @var.bind, @var2.bind, rhs, strength)
225
+ an_instance_of(Gecode::Raw::IntVar),
226
+ an_instance_of(Gecode::Raw::IntVar), rhs, strength)
222
227
  Gecode::Raw.should_receive(:rel).exactly(0).times
223
228
  else
224
229
  Gecode::Raw.should_receive(:mult).once.with(
225
230
  an_instance_of(Gecode::Raw::Space),
226
- @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar),
231
+ an_instance_of(Gecode::Raw::IntVar),
232
+ an_instance_of(Gecode::Raw::IntVar),
233
+ an_instance_of(Gecode::Raw::IntVar),
227
234
  strength)
228
235
  Gecode::Raw.should_receive(:rel).once.with(
229
236
  an_instance_of(Gecode::Raw::Space),
@@ -232,10 +239,13 @@ describe Gecode::Constraints::Int::Arithmetic, ' (multiplication)' do
232
239
  else
233
240
  Gecode::Raw.should_receive(:mult).once.with(
234
241
  an_instance_of(Gecode::Raw::Space),
235
- @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar), strength)
242
+ an_instance_of(Gecode::Raw::IntVar),
243
+ an_instance_of(Gecode::Raw::IntVar),
244
+ an_instance_of(Gecode::Raw::IntVar), strength)
236
245
  Gecode::Raw.should_receive(:rel).once.with(
237
246
  an_instance_of(Gecode::Raw::Space),
238
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
247
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
248
+ an_instance_of(Gecode::Raw::BoolVar),
239
249
  strength)
240
250
  end
241
251
  end
@@ -88,7 +88,8 @@ describe Gecode::Constraints::BoolEnum, ' (conjunction)' do
88
88
  unless reif_var.nil?
89
89
  Gecode::Raw.should_receive(:bool_eqv).once.with(
90
90
  an_instance_of(Gecode::Raw::Space),
91
- an_instance_of(Gecode::Raw::BoolVar), reif_var.bind, true, strength)
91
+ an_instance_of(Gecode::Raw::BoolVar),
92
+ an_instance_of(Gecode::Raw::BoolVar), true, strength)
92
93
  end
93
94
  end
94
95
  end
@@ -123,7 +124,8 @@ describe Gecode::Constraints::BoolEnum, ' (disjunction)' do
123
124
  unless reif_var.nil?
124
125
  Gecode::Raw.should_receive(:bool_eqv).once.with(
125
126
  an_instance_of(Gecode::Raw::Space),
126
- an_instance_of(Gecode::Raw::BoolVar), reif_var.bind, true, strength)
127
+ an_instance_of(Gecode::Raw::BoolVar),
128
+ an_instance_of(Gecode::Raw::BoolVar), true, strength)
127
129
  end
128
130
  end
129
131
  end
@@ -29,12 +29,15 @@ describe Gecode::Constraints::Bool do
29
29
  @model.allow_space_access do
30
30
  Gecode::Raw.should_receive(:bool_or).once.with(
31
31
  an_instance_of(Gecode::Raw::Space),
32
- @b1.bind, @b2.bind, an_instance_of(Gecode::Raw::BoolVar),
32
+ an_instance_of(Gecode::Raw::BoolVar),
33
+ an_instance_of(Gecode::Raw::BoolVar),
34
+ an_instance_of(Gecode::Raw::BoolVar),
33
35
  Gecode::Raw::ICL_DEF)
34
36
  unless reif_var.nil?
35
37
  Gecode::Raw.should_receive(:bool_eqv).once.with(
36
38
  an_instance_of(Gecode::Raw::Space),
37
- an_instance_of(Gecode::Raw::BoolVar), reif_var.bind, true, strength)
39
+ an_instance_of(Gecode::Raw::BoolVar),
40
+ an_instance_of(Gecode::Raw::BoolVar), true, strength)
38
41
  end
39
42
  end
40
43
  end
@@ -21,7 +21,7 @@ describe Gecode::Constraints::Set::Cardinality, ' (range)' do
21
21
  @model.allow_space_access do
22
22
  Gecode::Raw.should_receive(:cardinality).once.with(
23
23
  an_instance_of(Gecode::Raw::Space),
24
- @set.bind, rhs.first, rhs.last)
24
+ an_instance_of(Gecode::Raw::SetVar), rhs.first, rhs.last)
25
25
  end
26
26
  end
27
27
  end
@@ -47,7 +47,10 @@ describe Gecode::Constraints::Set::Cardinality, ' (range)' do
47
47
  end
48
48
 
49
49
  it 'should not shadow the integer variable domain constrain' do
50
- Gecode::Raw.should_receive(:dom).once.with(
50
+ Gecode::Raw.should_receive(:dom).with(
51
+ an_instance_of(Gecode::Raw::Space),
52
+ an_instance_of(Gecode::Raw::IntVar), 0, 11, Gecode::Raw::ICL_DEF)
53
+ Gecode::Raw.should_receive(:dom).with(
51
54
  an_instance_of(Gecode::Raw::Space),
52
55
  an_instance_of(Gecode::Raw::IntVar), an_instance_of(Gecode::Raw::IntSet),
53
56
  an_instance_of(Gecode::Raw::BoolVar), Gecode::Raw::ICL_DEF)
@@ -72,16 +75,18 @@ describe Gecode::Constraints::Set::Cardinality, ' (composite)' do
72
75
  end
73
76
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
74
77
  @model.allow_space_access do
75
- rhs = rhs.bind if rhs.respond_to? :bind
78
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
76
79
  if reif_var.nil?
77
80
  if !negated and relation == Gecode::Raw::IRT_EQ and
78
- rhs.kind_of? Gecode::Raw::IntVar
81
+ !rhs.kind_of? Fixnum
79
82
  Gecode::Raw.should_receive(:cardinality).once.with(
80
- an_instance_of(Gecode::Raw::Space), @set.bind, rhs)
83
+ an_instance_of(Gecode::Raw::Space),
84
+ an_instance_of(Gecode::Raw::SetVar), rhs)
81
85
  Gecode::Raw.should_receive(:rel).exactly(0).times
82
86
  else
83
87
  Gecode::Raw.should_receive(:cardinality).once.with(
84
- an_instance_of(Gecode::Raw::Space), @set.bind,
88
+ an_instance_of(Gecode::Raw::Space),
89
+ an_instance_of(Gecode::Raw::SetVar),
85
90
  an_instance_of(Gecode::Raw::IntVar))
86
91
  Gecode::Raw.should_receive(:rel).once.with(
87
92
  an_instance_of(Gecode::Raw::Space),
@@ -91,10 +96,12 @@ describe Gecode::Constraints::Set::Cardinality, ' (composite)' do
91
96
  else
92
97
  Gecode::Raw.should_receive(:cardinality).once.with(
93
98
  an_instance_of(Gecode::Raw::Space),
94
- @set.bind, an_instance_of(Gecode::Raw::IntVar))
99
+ an_instance_of(Gecode::Raw::SetVar),
100
+ an_instance_of(Gecode::Raw::IntVar))
95
101
  Gecode::Raw.should_receive(:rel).once.with(
96
102
  an_instance_of(Gecode::Raw::Space),
97
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
103
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
104
+ an_instance_of(Gecode::Raw::BoolVar),
98
105
  strength)
99
106
  end
100
107
  end
@@ -129,6 +136,19 @@ describe Gecode::Constraints::Set::Cardinality, ' (composite)' do
129
136
  @set.value.size.should == @var.value
130
137
  end
131
138
 
139
+ it 'should constrain the cardinality of a set (2)' do
140
+ @set.size.must == 2
141
+ @model.solve!.should_not be_nil
142
+ @set.value.size.should == 2
143
+ end
144
+
145
+ it 'should constrain the cardinality of a set (3)' do
146
+ @set.size.must == @var
147
+ @var.must == 2
148
+ @model.solve!
149
+ @set.value.size.should == 2
150
+ end
151
+
132
152
  it_should_behave_like 'constraint with options'
133
153
  it_should_behave_like 'composite constraint'
134
154
  end
@@ -46,16 +46,18 @@ describe Gecode::Constraints::Set::Connection, ' (min)' do
46
46
 
47
47
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
48
48
  @model.allow_space_access do
49
- rhs = rhs.bind if rhs.respond_to? :bind
49
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
50
50
  if reif_var.nil?
51
51
  if !negated and relation == Gecode::Raw::IRT_EQ and
52
- rhs.kind_of? Gecode::Raw::IntVar
52
+ !rhs.kind_of? Fixnum
53
53
  Gecode::Raw.should_receive(:min).once.with(
54
- an_instance_of(Gecode::Raw::Space), @set.bind, rhs)
54
+ an_instance_of(Gecode::Raw::Space),
55
+ an_instance_of(Gecode::Raw::SetVar), rhs)
55
56
  Gecode::Raw.should_receive(:rel).exactly(0).times
56
57
  else
57
58
  Gecode::Raw.should_receive(:min).once.with(
58
- an_instance_of(Gecode::Raw::Space), @set.bind,
59
+ an_instance_of(Gecode::Raw::Space),
60
+ an_instance_of(Gecode::Raw::SetVar),
59
61
  an_instance_of(Gecode::Raw::IntVar))
60
62
  Gecode::Raw.should_receive(:rel).once.with(
61
63
  an_instance_of(Gecode::Raw::Space),
@@ -65,10 +67,12 @@ describe Gecode::Constraints::Set::Connection, ' (min)' do
65
67
  else
66
68
  Gecode::Raw.should_receive(:min).once.with(
67
69
  an_instance_of(Gecode::Raw::Space),
68
- @set.bind, an_instance_of(Gecode::Raw::IntVar))
70
+ an_instance_of(Gecode::Raw::SetVar),
71
+ an_instance_of(Gecode::Raw::IntVar))
69
72
  Gecode::Raw.should_receive(:rel).once.with(
70
73
  an_instance_of(Gecode::Raw::Space),
71
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
74
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
75
+ an_instance_of(Gecode::Raw::BoolVar),
72
76
  strength)
73
77
  end
74
78
  end
@@ -76,9 +80,9 @@ describe Gecode::Constraints::Set::Connection, ' (min)' do
76
80
  end
77
81
 
78
82
  it 'should constrain the min of a set' do
79
- @set.min.must == @var
83
+ @set.min.must == 3
80
84
  @model.solve!
81
- @set.lower_bound.min.should == @var.value
85
+ @set.lower_bound.min.should == 3
82
86
  end
83
87
 
84
88
  it_should_behave_like 'connection constraint'
@@ -94,16 +98,18 @@ describe Gecode::Constraints::Set::Connection, ' (max)' do
94
98
 
95
99
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
96
100
  @model.allow_space_access do
97
- rhs = rhs.bind if rhs.respond_to? :bind
101
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
98
102
  if reif_var.nil?
99
103
  if !negated and relation == Gecode::Raw::IRT_EQ and
100
- rhs.kind_of? Gecode::Raw::IntVar
104
+ !rhs.kind_of? Fixnum
101
105
  Gecode::Raw.should_receive(:max).once.with(
102
- an_instance_of(Gecode::Raw::Space), @set.bind, rhs)
106
+ an_instance_of(Gecode::Raw::Space),
107
+ an_instance_of(Gecode::Raw::SetVar), rhs)
103
108
  Gecode::Raw.should_receive(:rel).exactly(0).times
104
109
  else
105
110
  Gecode::Raw.should_receive(:max).once.with(
106
- an_instance_of(Gecode::Raw::Space), @set.bind,
111
+ an_instance_of(Gecode::Raw::Space),
112
+ an_instance_of(Gecode::Raw::SetVar),
107
113
  an_instance_of(Gecode::Raw::IntVar))
108
114
  Gecode::Raw.should_receive(:rel).once.with(
109
115
  an_instance_of(Gecode::Raw::Space),
@@ -113,10 +119,12 @@ describe Gecode::Constraints::Set::Connection, ' (max)' do
113
119
  else
114
120
  Gecode::Raw.should_receive(:max).once.with(
115
121
  an_instance_of(Gecode::Raw::Space),
116
- @set.bind, an_instance_of(Gecode::Raw::IntVar))
122
+ an_instance_of(Gecode::Raw::SetVar),
123
+ an_instance_of(Gecode::Raw::IntVar))
117
124
  Gecode::Raw.should_receive(:rel).once.with(
118
125
  an_instance_of(Gecode::Raw::Space),
119
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
126
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
127
+ an_instance_of(Gecode::Raw::BoolVar),
120
128
  strength)
121
129
  end
122
130
  end
@@ -124,9 +132,9 @@ describe Gecode::Constraints::Set::Connection, ' (max)' do
124
132
  end
125
133
 
126
134
  it 'should constrain the max of a set' do
127
- @set.max.must == @var
135
+ @set.max.must == 3
128
136
  @model.solve!
129
- @set.lower_bound.max.should == @var.value
137
+ @set.lower_bound.max.should == 3
130
138
  end
131
139
 
132
140
  it_should_behave_like 'connection constraint'
@@ -142,17 +150,19 @@ describe Gecode::Constraints::Set::Connection, ' (sum)' do
142
150
 
143
151
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
144
152
  @model.allow_space_access do
145
- rhs = rhs.bind if rhs.respond_to? :bind
153
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
146
154
  if reif_var.nil?
147
155
  if !negated and relation == Gecode::Raw::IRT_EQ and
148
- rhs.kind_of? Gecode::Raw::IntVar
156
+ !rhs.kind_of? Fixnum
149
157
  Gecode::Raw.should_receive(:weights).once.with(
150
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind,
158
+ an_instance_of(Gecode::Raw::Space), anything, anything,
159
+ an_instance_of(Gecode::Raw::SetVar),
151
160
  rhs)
152
161
  Gecode::Raw.should_receive(:rel).exactly(0).times
153
162
  else
154
163
  Gecode::Raw.should_receive(:weights).once.with(
155
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind,
164
+ an_instance_of(Gecode::Raw::Space), anything, anything,
165
+ an_instance_of(Gecode::Raw::SetVar),
156
166
  an_instance_of(Gecode::Raw::IntVar))
157
167
  Gecode::Raw.should_receive(:rel).once.with(
158
168
  an_instance_of(Gecode::Raw::Space),
@@ -162,10 +172,12 @@ describe Gecode::Constraints::Set::Connection, ' (sum)' do
162
172
  else
163
173
  Gecode::Raw.should_receive(:weights).once.with(
164
174
  an_instance_of(Gecode::Raw::Space),
165
- anything, anything, @set.bind, an_instance_of(Gecode::Raw::IntVar))
175
+ anything, anything, an_instance_of(Gecode::Raw::SetVar),
176
+ an_instance_of(Gecode::Raw::IntVar))
166
177
  Gecode::Raw.should_receive(:rel).once.with(
167
178
  an_instance_of(Gecode::Raw::Space),
168
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
179
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
180
+ an_instance_of(Gecode::Raw::BoolVar),
169
181
  strength)
170
182
  end
171
183
  end
@@ -173,9 +185,9 @@ describe Gecode::Constraints::Set::Connection, ' (sum)' do
173
185
  end
174
186
 
175
187
  it 'should constrain the sum of a set' do
176
- @set.sum.must == @var
188
+ @set.sum.must == 7
177
189
  @model.solve!.should_not be_nil
178
- @set.value.inject(0){ |x, y| x + y }.should == @var.value
190
+ @set.value.inject(0){ |x, y| x + y }.should == 7
179
191
  end
180
192
 
181
193
  it 'should raise error if unsupported options is given' do
@@ -204,16 +216,18 @@ describe Gecode::Constraints::Set::Connection, ' (sum with weights)' do
204
216
 
205
217
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
206
218
  @model.allow_space_access do
207
- rhs = rhs.bind if rhs.respond_to? :bind
219
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
208
220
  if reif_var.nil?
209
221
  if !negated and relation == Gecode::Raw::IRT_EQ and
210
- rhs.kind_of? Gecode::Raw::IntVar
222
+ !rhs.kind_of? Fixnum
211
223
  Gecode::Raw.should_receive(:weights).once.with(
212
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind, rhs)
224
+ an_instance_of(Gecode::Raw::Space), anything, anything,
225
+ an_instance_of(Gecode::Raw::SetVar), rhs)
213
226
  Gecode::Raw.should_receive(:rel).exactly(0).times
214
227
  else
215
228
  Gecode::Raw.should_receive(:weights).once.with(
216
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind,
229
+ an_instance_of(Gecode::Raw::Space), anything, anything,
230
+ an_instance_of(Gecode::Raw::SetVar),
217
231
  an_instance_of(Gecode::Raw::IntVar))
218
232
  Gecode::Raw.should_receive(:rel).once.with(
219
233
  an_instance_of(Gecode::Raw::Space),
@@ -223,10 +237,12 @@ describe Gecode::Constraints::Set::Connection, ' (sum with weights)' do
223
237
  else
224
238
  Gecode::Raw.should_receive(:weights).once.with(
225
239
  an_instance_of(Gecode::Raw::Space),
226
- anything, anything, @set.bind, an_instance_of(Gecode::Raw::IntVar))
240
+ anything, anything, an_instance_of(Gecode::Raw::SetVar),
241
+ an_instance_of(Gecode::Raw::IntVar))
227
242
  Gecode::Raw.should_receive(:rel).once.with(
228
243
  an_instance_of(Gecode::Raw::Space),
229
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
244
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
245
+ an_instance_of(Gecode::Raw::BoolVar),
230
246
  strength)
231
247
  end
232
248
  end
@@ -261,16 +277,18 @@ describe Gecode::Constraints::Set::Connection, ' (sum with substitutions)' do
261
277
 
262
278
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
263
279
  @model.allow_space_access do
264
- rhs = rhs.bind if rhs.respond_to? :bind
280
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
265
281
  if reif_var.nil?
266
282
  if !negated and relation == Gecode::Raw::IRT_EQ and
267
- rhs.kind_of? Gecode::Raw::IntVar
283
+ !rhs.kind_of? Fixnum
268
284
  Gecode::Raw.should_receive(:weights).once.with(
269
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind, rhs)
285
+ an_instance_of(Gecode::Raw::Space), anything, anything,
286
+ an_instance_of(Gecode::Raw::SetVar), rhs)
270
287
  Gecode::Raw.should_receive(:rel).exactly(0).times
271
288
  else
272
289
  Gecode::Raw.should_receive(:weights).once.with(
273
- an_instance_of(Gecode::Raw::Space), anything, anything, @set.bind,
290
+ an_instance_of(Gecode::Raw::Space), anything, anything,
291
+ an_instance_of(Gecode::Raw::SetVar),
274
292
  an_instance_of(Gecode::Raw::IntVar))
275
293
  Gecode::Raw.should_receive(:rel).once.with(
276
294
  an_instance_of(Gecode::Raw::Space),
@@ -280,10 +298,12 @@ describe Gecode::Constraints::Set::Connection, ' (sum with substitutions)' do
280
298
  else
281
299
  Gecode::Raw.should_receive(:weights).once.with(
282
300
  an_instance_of(Gecode::Raw::Space),
283
- anything, anything, @set.bind, an_instance_of(Gecode::Raw::IntVar))
301
+ anything, anything, an_instance_of(Gecode::Raw::SetVar),
302
+ an_instance_of(Gecode::Raw::IntVar))
284
303
  Gecode::Raw.should_receive(:rel).once.with(
285
304
  an_instance_of(Gecode::Raw::Space),
286
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
305
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
306
+ an_instance_of(Gecode::Raw::BoolVar),
287
307
  strength)
288
308
  end
289
309
  end
@@ -314,7 +334,8 @@ describe Gecode::Constraints::Set::Connection, ' (include)' do
314
334
  @model.allow_space_access do
315
335
  Gecode::Raw.should_receive(:match).once.with(
316
336
  an_instance_of(Gecode::Raw::Space),
317
- @set.bind, an_instance_of(Gecode::Raw::IntVarArray))
337
+ an_instance_of(Gecode::Raw::SetVar),
338
+ an_instance_of(Gecode::Raw::IntVarArray))
318
339
  end
319
340
  end
320
341