gecoder 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/CHANGES +16 -3
  2. data/example/magic_sequence.rb +1 -1
  3. data/example/queens.rb +1 -1
  4. data/example/send_more_money.rb +1 -1
  5. data/example/sudoku.rb +1 -1
  6. data/ext/missing.cpp +18 -4
  7. data/ext/missing.h +8 -0
  8. data/lib/gecoder/bindings.rb +30 -3
  9. data/lib/gecoder/bindings/bindings.rb +22 -0
  10. data/lib/gecoder/interface/binding_changes.rb +81 -107
  11. data/lib/gecoder/interface/branch.rb +65 -14
  12. data/lib/gecoder/interface/constraints.rb +1 -0
  13. data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +16 -12
  14. data/lib/gecoder/interface/constraints/int/arithmetic.rb +7 -3
  15. data/lib/gecoder/interface/constraints/int/linear.rb +19 -16
  16. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +8 -4
  17. data/lib/gecoder/interface/constraints/int_enum/channel.rb +14 -6
  18. data/lib/gecoder/interface/constraints/int_enum/element.rb +7 -5
  19. data/lib/gecoder/interface/constraints/int_enum/sort.rb +1 -4
  20. data/lib/gecoder/interface/constraints/set/cardinality.rb +6 -3
  21. data/lib/gecoder/interface/constraints/set/connection.rb +136 -0
  22. data/lib/gecoder/interface/constraints/set_enum/channel.rb +18 -0
  23. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +61 -0
  24. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +32 -0
  25. data/lib/gecoder/interface/constraints/set_var_constraints.rb +1 -0
  26. data/lib/gecoder/interface/enum_wrapper.rb +12 -3
  27. data/lib/gecoder/interface/model.rb +77 -56
  28. data/lib/gecoder/interface/search.rb +74 -5
  29. data/lib/gecoder/interface/variables.rb +117 -15
  30. data/lib/gecoder/version.rb +1 -1
  31. data/specs/binding_changes.rb +9 -5
  32. data/specs/bool_var.rb +8 -12
  33. data/specs/branch.rb +85 -19
  34. data/specs/constraints/arithmetic.rb +99 -71
  35. data/specs/constraints/bool_enum.rb +26 -18
  36. data/specs/constraints/boolean.rb +53 -49
  37. data/specs/constraints/cardinality.rb +33 -26
  38. data/specs/constraints/channel.rb +77 -6
  39. data/specs/constraints/connection.rb +352 -0
  40. data/specs/constraints/constraints.rb +10 -1
  41. data/specs/constraints/count.rb +79 -39
  42. data/specs/constraints/distinct.rb +128 -9
  43. data/specs/constraints/element.rb +26 -19
  44. data/specs/constraints/equality.rb +2 -1
  45. data/specs/constraints/int_domain.rb +19 -12
  46. data/specs/constraints/int_relation.rb +12 -6
  47. data/specs/constraints/linear.rb +30 -30
  48. data/specs/constraints/reification_sugar.rb +8 -4
  49. data/specs/constraints/set_domain.rb +24 -18
  50. data/specs/constraints/set_relation.rb +38 -23
  51. data/specs/constraints/sort.rb +12 -10
  52. data/specs/enum_wrapper.rb +9 -3
  53. data/specs/int_var.rb +8 -4
  54. data/specs/logging.rb +24 -0
  55. data/specs/model.rb +25 -7
  56. data/specs/search.rb +41 -1
  57. data/specs/set_var.rb +36 -7
  58. data/specs/spec_helper.rb +3 -10
  59. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +1 -1
  60. metadata +12 -3
  61. data/specs/tmp +0 -22
@@ -1,4 +1,4 @@
1
1
  module GecodeR
2
2
  # A string representation of the Gecode/R version.
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe 'Space', :shared => true do
4
4
  it 'should give different indices when creating int variables' do
5
- @space.new_int_vars(0, 17).should_not equal(@space.new_int_vars(0, 17))
5
+ @space.new_int_vars([0, 17]).should_not equal(@space.new_int_vars([0, 17]))
6
6
  end
7
7
 
8
8
  it 'should give different indices when creating bool variables' do
@@ -10,7 +10,7 @@ describe 'Space', :shared => true do
10
10
  end
11
11
 
12
12
  it 'should give different indices when creating multiple int variables' do
13
- @space.new_int_vars(0, 17, 17).uniq.size.should equal(17)
13
+ @space.new_int_vars([0, 17], 17).uniq.size.should equal(17)
14
14
  end
15
15
 
16
16
  it 'should give different indices when creating multiple bool variables' do
@@ -18,7 +18,7 @@ describe 'Space', :shared => true do
18
18
  end
19
19
 
20
20
  it 'should not return nil for created int variables' do
21
- @space.new_int_vars(0, 17, 4).each do |i|
21
+ @space.new_int_vars([0, 17], 4).each do |i|
22
22
  @space.int_var(i).should_not be_nil
23
23
  end
24
24
  end
@@ -36,6 +36,10 @@ describe 'Space', :shared => true do
36
36
  it 'should return nil when requesting bool variables with negative indices' do
37
37
  @space.bool_var(-1).should be_nil
38
38
  end
39
+
40
+ it 'should raise an error if given a domain of incorrect type' do
41
+ lambda{ @space.new_int_vars(17) }.should raise_error(TypeError)
42
+ end
39
43
  end
40
44
 
41
45
  describe Gecode::Raw::Space, ' (new)' do
@@ -57,8 +61,8 @@ end
57
61
  describe Gecode::Raw::Space, ' (with items)' do
58
62
  before do
59
63
  @space = Gecode::Raw::Space.new
60
- @first = @space.new_int_vars(1, 4).first
61
- @second = @space.new_int_vars(-5, 5).first
64
+ @first = @space.new_int_vars([1, 4]).first
65
+ @second = @space.new_int_vars([-5, 5]).first
62
66
  end
63
67
 
64
68
  it_should_behave_like 'Space'
data/specs/bool_var.rb CHANGED
@@ -21,6 +21,10 @@ describe Gecode::FreeBoolVar, '(not assigned)' do
21
21
  it "should say that it's not assigned when inspecting" do
22
22
  @var.inspect.should include('unassigned')
23
23
  end
24
+
25
+ it 'should raise error when trying to access assigned value' do
26
+ lambda{ @var.value }.should raise_error(RuntimeError)
27
+ end
24
28
  end
25
29
 
26
30
  describe Gecode::FreeBoolVar, '(assigned true)' do
@@ -37,12 +41,8 @@ describe Gecode::FreeBoolVar, '(assigned true)' do
37
41
  @var.should be_assigned
38
42
  end
39
43
 
40
- it 'should respond true to true?' do
41
- @var.true?.should be_true
42
- end
43
-
44
- it 'should not respond true to false?' do
45
- @var.false?.should_not be_true
44
+ it 'should have valye true' do
45
+ @var.value.should be_true
46
46
  end
47
47
 
48
48
  it "should say that it's true when inspecting" do
@@ -64,12 +64,8 @@ describe Gecode::FreeBoolVar, '(assigned false)' do
64
64
  @var.should be_assigned
65
65
  end
66
66
 
67
- it 'should respond not true to true?' do
68
- @var.true?.should_not be_true
69
- end
70
-
71
- it 'should respond true to false?' do
72
- @var.false?.should be_true
67
+ it 'should have value false ' do
68
+ @var.value.should_not be_true
73
69
  end
74
70
 
75
71
  it "should say that it's false when inspecting" do
data/specs/branch.rb CHANGED
@@ -3,39 +3,28 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  class BranchSampleProblem < Gecode::Model
4
4
  attr :vars
5
5
  attr :bools
6
+ attr :sets
6
7
 
7
8
  def initialize
8
9
  @vars = int_var_array(2, 0..3)
10
+ @sets = set_var_array(2, [], 0..4)
9
11
  @bools = bool_var_array(2)
10
12
  end
11
13
  end
12
14
 
13
- describe Gecode::Model, ' (branch)' do
15
+ describe Gecode::Model, ' (integer branch)' do
14
16
  before do
15
17
  @model = BranchSampleProblem.new
16
18
  @vars = @model.vars
17
19
  @bools = @model.bools
18
20
  end
19
21
 
20
- it 'should pass the variables given in int arrays' do
21
- Gecode::Raw.should_receive(:branch).once.and_return{ |s, vars, x, y| vars }
22
- int_var_array = @model.branch_on @vars
23
- int_var_array.size.should equal(2)
24
- 2.times do |i|
25
- int_var_array.at(i).should have_domain(0..3)
26
- end
27
- end
28
-
29
- it 'should pass the variables given in bool arrays' do
30
- Gecode::Raw.should_receive(:branch).once.and_return{ |s, vars, x, y| vars }
31
- bool_var_array = @model.branch_on @bools
32
- bool_var_array.size.should equal(2)
33
- end
34
-
35
22
  it 'should default to :none and :min' do
36
- Gecode::Raw.should_receive(:branch).once.with(@model.active_space,
23
+ Gecode::Raw.should_receive(:branch).once.with(
24
+ an_instance_of(Gecode::Raw::Space),
37
25
  anything, Gecode::Raw::BVAR_NONE, Gecode::Raw::BVAL_MIN)
38
26
  @model.branch_on @vars
27
+ @model.solve!
39
28
  end
40
29
 
41
30
  it 'should ensure that branched int variables are assigned in a solution' do
@@ -64,9 +53,11 @@ describe Gecode::Model, ' (branch)' do
64
53
  :largest_max_regret => Gecode::Raw::BVAR_REGRET_MAX_MAX
65
54
  }.each_pair do |name, gecode_const|
66
55
  it "should support #{name} as variable selection strategy" do
67
- Gecode::Raw.should_receive(:branch).once.with(@model.active_space,
56
+ Gecode::Raw.should_receive(:branch).once.with(
57
+ an_instance_of(Gecode::Raw::Space),
68
58
  anything, gecode_const, an_instance_of(Numeric))
69
59
  @model.branch_on @vars, :variable => name
60
+ @model.solve!
70
61
  end
71
62
  end
72
63
 
@@ -78,9 +69,11 @@ describe Gecode::Model, ' (branch)' do
78
69
  :split_max => Gecode::Raw::BVAL_SPLIT_MAX
79
70
  }.each_pair do |name, gecode_const|
80
71
  it "should support #{name} as value selection strategy" do
81
- Gecode::Raw.should_receive(:branch).once.with(@model.active_space,
72
+ Gecode::Raw.should_receive(:branch).once.with(
73
+ an_instance_of(Gecode::Raw::Space),
82
74
  anything, an_instance_of(Numeric), gecode_const)
83
75
  @model.branch_on @vars, :value => name
76
+ @model.solve!
84
77
  end
85
78
  end
86
79
 
@@ -101,4 +94,77 @@ describe Gecode::Model, ' (branch)' do
101
94
  @model.branch_on @vars, :foo => 5
102
95
  end.should raise_error(ArgumentError)
103
96
  end
97
+
98
+ it 'should raise errors for unrecognized enumerations' do
99
+ lambda do
100
+ @model.branch_on [1,2,3]
101
+ end.should raise_error(TypeError)
102
+ end
103
+ end
104
+
105
+ describe Gecode::Model, ' (set branch)' do
106
+ before do
107
+ @model = BranchSampleProblem.new
108
+ @sets = @model.sets
109
+ end
110
+
111
+ it 'should default to :none and :min' do
112
+ Gecode::Raw.should_receive(:branch).once.with(
113
+ an_instance_of(Gecode::Raw::Space),
114
+ anything, Gecode::Raw::SETBVAR_NONE, Gecode::Raw::SETBVAL_MIN)
115
+ @model.branch_on @sets
116
+ @model.solve!
117
+ end
118
+
119
+ it 'should ensure that branched set variables are assigned in a solution' do
120
+ @model.branch_on @sets
121
+ @model.solve!.sets.each{ |var| var.should be_assigned }
122
+ end
123
+
124
+ supported_var_selectors = {
125
+ :none => Gecode::Raw::SETBVAR_NONE,
126
+ :smallest_cardinality => Gecode::Raw::SETBVAR_MIN_CARD,
127
+ :largest_cardinality => Gecode::Raw::SETBVAR_MAX_CARD,
128
+ :smallest_unknown => Gecode::Raw::SETBVAR_MIN_UNKNOWN_ELEM,
129
+ :largest_unknown => Gecode::Raw::SETBVAR_MAX_UNKNOWN_ELEM
130
+ }.each_pair do |name, gecode_const|
131
+ it "should support #{name} as variable selection strategy" do
132
+ Gecode::Raw.should_receive(:branch).once.with(
133
+ an_instance_of(Gecode::Raw::Space),
134
+ anything, gecode_const, an_instance_of(Numeric))
135
+ @model.branch_on @sets, :variable => name
136
+ @model.solve!
137
+ end
138
+ end
139
+
140
+ supported_val_selectors = {
141
+ :min => Gecode::Raw::SETBVAL_MIN,
142
+ :max => Gecode::Raw::SETBVAL_MAX
143
+ }.each_pair do |name, gecode_const|
144
+ it "should support #{name} as value selection strategy" do
145
+ Gecode::Raw.should_receive(:branch).once.with(
146
+ an_instance_of(Gecode::Raw::Space),
147
+ anything, an_instance_of(Numeric), gecode_const)
148
+ @model.branch_on @sets, :value => name
149
+ @model.solve!
150
+ end
151
+ end
152
+
153
+ it 'should raise errors for unrecognized var selection strategies' do
154
+ lambda do
155
+ @model.branch_on @sets, :variable => :foo
156
+ end.should raise_error(ArgumentError)
157
+ end
158
+
159
+ it 'should raise errors for unrecognized val selection strategies' do
160
+ lambda do
161
+ @model.branch_on @sets, :value => :foo
162
+ end.should raise_error(ArgumentError)
163
+ end
164
+
165
+ it 'should raise errors for unrecognized options' do
166
+ lambda do
167
+ @model.branch_on @sets, :foo => 5
168
+ end.should raise_error(ArgumentError)
169
+ end
104
170
  end
@@ -64,34 +64,41 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (max)' do
64
64
 
65
65
  # Creates an expectation corresponding to the specified input.
66
66
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
67
- rhs = rhs.bind if rhs.respond_to? :bind
68
- if reif_var.nil?
69
- if !negated and relation == Gecode::Raw::IRT_EQ and
70
- rhs.kind_of? Gecode::Raw::IntVar
71
- Gecode::Raw.should_receive(:max).once.with(@model.active_space,
72
- an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
73
- Gecode::Raw.should_receive(:rel).exactly(0).times
67
+ @model.allow_space_access do
68
+ rhs = rhs.bind if rhs.respond_to? :bind
69
+ if reif_var.nil?
70
+ if !negated and relation == Gecode::Raw::IRT_EQ and
71
+ rhs.kind_of? Gecode::Raw::IntVar
72
+ Gecode::Raw.should_receive(:max).once.with(
73
+ an_instance_of(Gecode::Raw::Space),
74
+ an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
75
+ Gecode::Raw.should_receive(:rel).exactly(0).times
76
+ else
77
+ Gecode::Raw.should_receive(:max).once.with(
78
+ an_instance_of(Gecode::Raw::Space),
79
+ an_instance_of(Gecode::Raw::IntVarArray),
80
+ an_instance_of(Gecode::Raw::IntVar), strength)
81
+ Gecode::Raw.should_receive(:rel).once.with(
82
+ an_instance_of(Gecode::Raw::Space),
83
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
84
+ end
74
85
  else
75
- Gecode::Raw.should_receive(:max).once.with(@model.active_space,
86
+ Gecode::Raw.should_receive(:max).once.with(
87
+ an_instance_of(Gecode::Raw::Space),
76
88
  an_instance_of(Gecode::Raw::IntVarArray),
77
89
  an_instance_of(Gecode::Raw::IntVar), strength)
78
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
79
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
90
+ Gecode::Raw.should_receive(:rel).once.with(
91
+ an_instance_of(Gecode::Raw::Space),
92
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
93
+ strength)
80
94
  end
81
- else
82
- Gecode::Raw.should_receive(:max).once.with(@model.active_space,
83
- an_instance_of(Gecode::Raw::IntVarArray),
84
- an_instance_of(Gecode::Raw::IntVar), strength)
85
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
86
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
87
- strength)
88
95
  end
89
96
  end
90
97
  end
91
98
 
92
99
  it 'should constrain the maximum value' do
93
100
  @numbers.max.must > 5
94
- @model.solve!.numbers.map{ |n| n.val }.max.should > 5
101
+ @model.solve!.numbers.values.max.should > 5
95
102
  end
96
103
 
97
104
  it_should_behave_like 'arithmetic constraint'
@@ -106,34 +113,41 @@ describe Gecode::Constraints::IntEnum::Arithmetic, ' (min)' do
106
113
 
107
114
  # Creates an expectation corresponding to the specified input.
108
115
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
109
- rhs = rhs.bind if rhs.respond_to? :bind
110
- if reif_var.nil?
111
- if !negated and relation == Gecode::Raw::IRT_EQ and
112
- rhs.kind_of? Gecode::Raw::IntVar
113
- Gecode::Raw.should_receive(:min).once.with(@model.active_space,
114
- an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
115
- Gecode::Raw.should_receive(:rel).exactly(0).times
116
+ @model.allow_space_access do
117
+ rhs = rhs.bind if rhs.respond_to? :bind
118
+ if reif_var.nil?
119
+ if !negated and relation == Gecode::Raw::IRT_EQ and
120
+ rhs.kind_of? Gecode::Raw::IntVar
121
+ Gecode::Raw.should_receive(:min).once.with(
122
+ an_instance_of(Gecode::Raw::Space),
123
+ an_instance_of(Gecode::Raw::IntVarArray), rhs, strength)
124
+ Gecode::Raw.should_receive(:rel).exactly(0).times
125
+ else
126
+ Gecode::Raw.should_receive(:min).once.with(
127
+ an_instance_of(Gecode::Raw::Space),
128
+ an_instance_of(Gecode::Raw::IntVarArray),
129
+ an_instance_of(Gecode::Raw::IntVar), strength)
130
+ Gecode::Raw.should_receive(:rel).once.with(
131
+ an_instance_of(Gecode::Raw::Space),
132
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
133
+ end
116
134
  else
117
- Gecode::Raw.should_receive(:min).once.with(@model.active_space,
135
+ Gecode::Raw.should_receive(:min).once.with(
136
+ an_instance_of(Gecode::Raw::Space),
118
137
  an_instance_of(Gecode::Raw::IntVarArray),
119
138
  an_instance_of(Gecode::Raw::IntVar), strength)
120
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
121
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
139
+ Gecode::Raw.should_receive(:rel).once.with(
140
+ an_instance_of(Gecode::Raw::Space),
141
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
142
+ strength)
122
143
  end
123
- else
124
- Gecode::Raw.should_receive(:min).once.with(@model.active_space,
125
- an_instance_of(Gecode::Raw::IntVarArray),
126
- an_instance_of(Gecode::Raw::IntVar), strength)
127
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
128
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
129
- strength)
130
144
  end
131
145
  end
132
146
  end
133
147
 
134
148
  it 'should constrain the minimum value' do
135
149
  @numbers.min.must > 5
136
- @model.solve!.numbers.map{ |n| n.val }.min.should > 5
150
+ @model.solve!.numbers.values.min.should > 5
137
151
  end
138
152
 
139
153
  it_should_behave_like 'arithmetic constraint'
@@ -148,25 +162,32 @@ describe Gecode::Constraints::Int::Arithmetic, ' (abs)' do
148
162
 
149
163
  # Creates an expectation corresponding to the specified input.
150
164
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
151
- rhs = rhs.bind if rhs.respond_to? :bind
152
- if reif_var.nil?
153
- if !negated and relation == Gecode::Raw::IRT_EQ and
154
- rhs.kind_of? Gecode::Raw::IntVar
155
- Gecode::Raw.should_receive(:abs).once.with(@model.active_space,
156
- @var.bind, rhs, strength)
157
- Gecode::Raw.should_receive(:rel).exactly(0).times
165
+ @model.allow_space_access do
166
+ rhs = rhs.bind if rhs.respond_to? :bind
167
+ if reif_var.nil?
168
+ if !negated and relation == Gecode::Raw::IRT_EQ and
169
+ rhs.kind_of? Gecode::Raw::IntVar
170
+ Gecode::Raw.should_receive(:abs).once.with(
171
+ an_instance_of(Gecode::Raw::Space),
172
+ @var.bind, rhs, strength)
173
+ Gecode::Raw.should_receive(:rel).exactly(0).times
174
+ else
175
+ Gecode::Raw.should_receive(:abs).once.with(
176
+ an_instance_of(Gecode::Raw::Space),
177
+ @var.bind, an_instance_of(Gecode::Raw::IntVar), strength)
178
+ Gecode::Raw.should_receive(:rel).once.with(
179
+ an_instance_of(Gecode::Raw::Space),
180
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
181
+ end
158
182
  else
159
- Gecode::Raw.should_receive(:abs).once.with(@model.active_space,
183
+ Gecode::Raw.should_receive(:abs).once.with(
184
+ an_instance_of(Gecode::Raw::Space),
160
185
  @var.bind, an_instance_of(Gecode::Raw::IntVar), strength)
161
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
162
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
186
+ Gecode::Raw.should_receive(:rel).once.with(
187
+ an_instance_of(Gecode::Raw::Space),
188
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
189
+ an_instance_of(Gecode::Raw::BoolVar), strength)
163
190
  end
164
- else
165
- Gecode::Raw.should_receive(:abs).once.with(@model.active_space,
166
- @var.bind, an_instance_of(Gecode::Raw::IntVar), strength)
167
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
168
- an_instance_of(Gecode::Raw::IntVar), relation, rhs,
169
- an_instance_of(Gecode::Raw::BoolVar), strength)
170
191
  end
171
192
  end
172
193
  end
@@ -174,7 +195,7 @@ describe Gecode::Constraints::Int::Arithmetic, ' (abs)' do
174
195
  it 'should constrain the absolute value' do
175
196
  @var.must < 0
176
197
  @var.abs.must == 5
177
- @model.solve!.var.val.should == -5
198
+ @model.solve!.var.value.should == -5
178
199
  end
179
200
 
180
201
  it_should_behave_like 'arithmetic constraint'
@@ -190,26 +211,33 @@ describe Gecode::Constraints::Int::Arithmetic, ' (multiplication)' do
190
211
 
191
212
  # Creates an expectation corresponding to the specified input.
192
213
  @expect = lambda do |relation, rhs, strength, reif_var, negated|
193
- rhs = rhs.bind if rhs.respond_to? :bind
194
- if reif_var.nil?
195
- if !negated and relation == Gecode::Raw::IRT_EQ and
196
- rhs.kind_of? Gecode::Raw::IntVar
197
- Gecode::Raw.should_receive(:mult).once.with(@model.active_space,
198
- @var.bind, @var2.bind, rhs, strength)
199
- Gecode::Raw.should_receive(:rel).exactly(0).times
214
+ @model.allow_space_access do
215
+ rhs = rhs.bind if rhs.respond_to? :bind
216
+ if reif_var.nil?
217
+ if !negated and relation == Gecode::Raw::IRT_EQ and
218
+ rhs.kind_of? Gecode::Raw::IntVar
219
+ Gecode::Raw.should_receive(:mult).once.with(
220
+ an_instance_of(Gecode::Raw::Space),
221
+ @var.bind, @var2.bind, rhs, strength)
222
+ Gecode::Raw.should_receive(:rel).exactly(0).times
223
+ else
224
+ Gecode::Raw.should_receive(:mult).once.with(
225
+ an_instance_of(Gecode::Raw::Space),
226
+ @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar),
227
+ strength)
228
+ Gecode::Raw.should_receive(:rel).once.with(
229
+ an_instance_of(Gecode::Raw::Space),
230
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
231
+ end
200
232
  else
201
- Gecode::Raw.should_receive(:mult).once.with(@model.active_space,
202
- @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar),
233
+ Gecode::Raw.should_receive(:mult).once.with(
234
+ an_instance_of(Gecode::Raw::Space),
235
+ @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar), strength)
236
+ Gecode::Raw.should_receive(:rel).once.with(
237
+ an_instance_of(Gecode::Raw::Space),
238
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
203
239
  strength)
204
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
205
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, strength)
206
240
  end
207
- else
208
- Gecode::Raw.should_receive(:mult).once.with(@model.active_space,
209
- @var.bind, @var2.bind, an_instance_of(Gecode::Raw::IntVar), strength)
210
- Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
211
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
212
- strength)
213
241
  end
214
242
  end
215
243
  end
@@ -217,7 +245,7 @@ describe Gecode::Constraints::Int::Arithmetic, ' (multiplication)' do
217
245
  it 'should constrain the value of the multiplication' do
218
246
  (@var * @var2).must == 56
219
247
  sol = @model.solve!
220
- [sol.var.val, sol.var2.val].sort.should == [7, 8]
248
+ [sol.var.value, sol.var2.value].sort.should == [7, 8]
221
249
  end
222
250
 
223
251
  it 'should not interfere with other defined multiplication methods' do