gecoder 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/specs/search.rb CHANGED
@@ -65,6 +65,12 @@ describe Gecode::Model, ' (with multiple solutions)' do
65
65
  s.var.should have_domain(@solved_domain)
66
66
  end
67
67
  end
68
+
69
+ it 'should update the search statistics before yielding to #solution' do
70
+ @model.solution do |s|
71
+ @model.search_stats.should_not be_nil
72
+ end
73
+ end
68
74
 
69
75
  it 'should only evaluate the block for one solution in #solution' do
70
76
  i = 0
@@ -83,6 +89,18 @@ describe Gecode::Model, ' (with multiple solutions)' do
83
89
  end
84
90
  Set.new(solutions).should == Set.new([2,3])
85
91
  end
92
+
93
+ it 'should update the search statistics before yielding to #each_solution' do
94
+ solutions = []
95
+ old_stats = @model.search_stats
96
+ old_stats.should be_nil
97
+ @model.each_solution do |s|
98
+ solutions << s.var.value
99
+ @model.search_stats.should_not == old_stats
100
+ @model.search_stats.should_not be_nil
101
+ old_stats = @model.search_stats
102
+ end
103
+ end
86
104
  end
87
105
 
88
106
  describe Gecode::Model, ' (after #solve!)' do
@@ -114,6 +132,15 @@ describe Gecode::Model, ' (after #solve!)' do
114
132
  enum[2].first.should have_domain(@solved_domain)
115
133
  enum[3][1][:b].should have_domain(@solved_domain)
116
134
  end
135
+
136
+ it 'should have updated the search statistics' do
137
+ stats = @model.search_stats
138
+ stats[:propagations].should == 0
139
+ stats[:failures].should == 0
140
+ stats[:clones].should_not be_nil
141
+ stats[:commits].should_not be_nil
142
+ stats[:memory].should > 0
143
+ end
117
144
  end
118
145
 
119
146
  describe 'reset model', :shared => true do
@@ -126,6 +153,10 @@ describe 'reset model', :shared => true do
126
153
  enum[2].first.should have_domain(@reset_domain)
127
154
  enum[3][1][:b].should have_domain(@reset_domain)
128
155
  end
156
+
157
+ it 'should have cleared the search statistics' do
158
+ @model.search_stats.should be_nil
159
+ end
129
160
  end
130
161
 
131
162
  describe Gecode::Model, ' (after #reset!)' do
@@ -205,66 +236,6 @@ describe Gecode::Model, '(optimization search)' do
205
236
  solution.z.value.should == 25
206
237
  end
207
238
 
208
- it 'should support maximizing singe variables given as symbols' do
209
- solution = SampleOptimizationProblem.new.maximize! :z
210
- solution.should_not be_nil
211
- solution.x.value.should == 5
212
- solution.y.value.should == 5
213
- solution.z.value.should == 25
214
- end
215
-
216
- it 'should support maximizing singe variables given as strings' do
217
- solution = SampleOptimizationProblem.new.maximize! 'z'
218
- solution.should_not be_nil
219
- solution.x.value.should == 5
220
- solution.y.value.should == 5
221
- solution.z.value.should == 25
222
- end
223
-
224
- it 'should raise error if maximize! is given a non-existing method' do
225
- lambda do
226
- SampleOptimizationProblem.new.maximize! :does_not_exist
227
- end.should raise_error(NameError)
228
- end
229
-
230
- it 'should raise error if maximize! is given a method that does not return an integer variable' do
231
- lambda do
232
- SampleOptimizationProblem.new.maximize! :object_id
233
- end.should raise_error(ArgumentError)
234
- end
235
-
236
- it 'should support minimizing singe variables given as symbols' do
237
- problem = SampleOptimizationProblem.new
238
- problem.z.must > 2
239
- solution = problem.minimize! :x
240
- solution.should_not be_nil
241
- solution.x.value.should == 1
242
- solution.y.value.should == 3
243
- solution.z.value.should == 3
244
- end
245
-
246
- it 'should support minimizing singe variables given as strings' do
247
- problem = SampleOptimizationProblem.new
248
- problem.z.must > 2
249
- solution = problem.minimize! 'x'
250
- solution.should_not be_nil
251
- solution.x.value.should == 1
252
- solution.y.value.should == 3
253
- solution.z.value.should == 3
254
- end
255
-
256
- it 'should raise error if minimize! is given a non-existing method' do
257
- lambda do
258
- SampleOptimizationProblem.new.minimize! :does_not_exist
259
- end.should raise_error(NameError)
260
- end
261
-
262
- it 'should raise error if minimize! is given a method that does not return an integer variable' do
263
- lambda do
264
- SampleOptimizationProblem.new.minimize! :object_id
265
- end.should raise_error(ArgumentError)
266
- end
267
-
268
239
  it 'should not be bothered by garbage collecting' do
269
240
  # This goes through 400+ spaces.
270
241
  solution = SampleOptimizationProblem2.new.optimize! do |model, best_so_far|
@@ -303,4 +274,91 @@ describe Gecode::Model, '(optimization search)' do
303
274
  solution.y.value.should == 5
304
275
  solution.z.value.should == 25
305
276
  end
306
- end
277
+
278
+ it 'should update the search statistics' do
279
+ model = SampleOptimizationProblem.new
280
+ solution = model.maximize! :z
281
+
282
+ stats = model.search_stats
283
+ stats.should_not be_nil
284
+ stats[:propagations].should be_between(1, 100)
285
+ stats[:failures].should be_between(1, 100)
286
+ stats[:clones].should_not be_nil
287
+ stats[:commits].should_not be_nil
288
+ stats[:memory].should > 0
289
+ end
290
+ end
291
+
292
+ describe 'single variable optimization', :shared => true do
293
+ it "should support #{@method_name} having the variable given as a symbol" do
294
+ solution = @model.method(@method_name).call(@variable_name.to_sym)
295
+ @expect_to_be_correct.call(solution)
296
+ end
297
+
298
+ it "should support #{@method_name} having the variable given as a string" do
299
+ solution = @model.method(@method_name).call(@variable_name.to_s)
300
+ @expect_to_be_correct.call(solution)
301
+ end
302
+
303
+ it "should raise error if #{@method_name} is given a non-existing method" do
304
+ lambda do
305
+ SampleOptimizationProblem.new.method(@method_name).call(:does_not_exist)
306
+ end.should raise_error(NameError)
307
+ end
308
+
309
+ it "should raise error if #{@method_name} is given a method that does not return an integer variable" do
310
+ lambda do
311
+ SampleOptimizationProblem.new.method(@method_name).call(:object_id)
312
+ end.should raise_error(ArgumentError)
313
+ end
314
+
315
+ it 'should update the search statistics' do
316
+ @model.method(@method_name).call(@variable_name.to_sym)
317
+
318
+ stats = @model.search_stats
319
+ stats.should_not be_nil
320
+ stats[:propagations].should be_between(1, 100)
321
+ stats[:failures].should be_between(1, 100)
322
+ stats[:clones].should_not be_nil
323
+ stats[:commits].should_not be_nil
324
+ stats[:memory].should > 0
325
+ end
326
+ end
327
+
328
+ describe Gecode::Model, '(single variable minimization)' do
329
+ before do
330
+ @method_name = 'minimize!'
331
+ @variable_name = 'x'
332
+
333
+ @model = SampleOptimizationProblem.new
334
+ @model.z.must > 2
335
+
336
+ @expect_to_be_correct = lambda do |solution|
337
+ solution.should_not be_nil
338
+ solution.x.value.should == 1
339
+ solution.y.value.should == 3
340
+ solution.z.value.should == 3
341
+ end
342
+ end
343
+
344
+ it_should_behave_like 'single variable optimization'
345
+ end
346
+
347
+ describe Gecode::Model, '(single variable maximization)' do
348
+ before do
349
+ @method_name = 'maximize!'
350
+ @variable_name = 'z'
351
+
352
+ @model = SampleOptimizationProblem.new
353
+
354
+ @expect_to_be_correct = lambda do |solution|
355
+ solution.should_not be_nil
356
+ solution.x.value.should == 5
357
+ solution.y.value.should == 5
358
+ solution.z.value.should == 25
359
+ end
360
+ end
361
+
362
+ it_should_behave_like 'single variable optimization'
363
+ end
364
+
data/specs/spec_helper.rb CHANGED
@@ -58,34 +58,6 @@ module CustomVarMatchers
58
58
  def have_bounds(expected_glb, expected_lub)
59
59
  HaveBounds.new(expected_glb, expected_lub)
60
60
  end
61
-
62
- class IsAlias
63
- def initialize(expected)
64
- @expected = expected.to_a
65
- end
66
-
67
- def matches?(target)
68
- @target = target
69
- return false unless @target.size == @expected.size
70
- @expected.each do |element|
71
- return false unless @target.in(element)
72
- end
73
- return true
74
- end
75
-
76
- def failure_message
77
- "expected #{@target.inspect} to be an alias of #{@expected.inspect}"
78
- end
79
-
80
- def negative_failure_message
81
- "expected #{@target.inspect} not to be an alias of #{@expected.inspect}"
82
- end
83
- end
84
-
85
- # Tests whether a method with a specified name is the alias of another.
86
- def is_alias_of(expected)
87
- HaveDomain.new(expected)
88
- end
89
61
  end
90
62
 
91
63
  Spec::Runner.configure do |config|
@@ -54,7 +54,7 @@ spec = Gem::Specification.new do |s|
54
54
  s.files = FileList[
55
55
  '[A-Z]*',
56
56
  'lib/**/*.rb',
57
- 'example/**/*',
57
+ 'example/**/*.rb',
58
58
  'src/**/*',
59
59
  'vendor/rust/**/*',
60
60
  'tasks/**/*',
@@ -144,9 +144,8 @@ vanilla_release_files = [
144
144
  "pkg/#{PKG_FILE_NAME}.tgz",
145
145
  "pkg/#{PKG_FILE_NAME}.zip"
146
146
  ]
147
-
148
147
  desc 'Publish Gecode/R packages on RubyForge'
149
- task :publish_gecoder_packages => [:verify_user].concat(vanilla_release_files) do
148
+ task :publish_gecoder_packages => [:verify_user] + vanilla_release_files do
150
149
  require 'meta_project'
151
150
  require 'rake/contrib/xforge'
152
151
 
@@ -161,14 +160,13 @@ end
161
160
  # Files included in the release with Gecode.
162
161
  gecode_release_files = [
163
162
  "pkg/#{PKG_FILE_NAME_WITH_GECODE}.gem",
164
- "pkg/#{PKG_FILE_NAME_WITH_GECODE}.tgz",
165
- "pkg/#{PKG_FILE_NAME_WITH_GECODE}.zip",
163
+ #"pkg/#{PKG_FILE_NAME_WITH_GECODE}.tgz",
164
+ #"pkg/#{PKG_FILE_NAME_WITH_GECODE}.zip",
166
165
  "pkg/#{PKG_FILE_NAME_WITH_GECODE}-mswin32.gem"
167
166
  ]
168
-
169
167
  desc 'Publish Gecode/R with Gecode packages on RubyForge'
170
168
  task :publish_gecoder_with_gecode_packages =>
171
- [:verify_user].concat(gecode_release_files) do
169
+ [:verify_user] + gecode_release_files do
172
170
  require 'meta_project'
173
171
  require 'rake/contrib/xforge'
174
172
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: gecoder
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.1
7
- date: 2008-04-20 00:00:00 +02:00
6
+ version: 0.8.2
7
+ date: 2008-05-08 00:00:00 +02:00
8
8
  summary: Ruby interface to Gecode, an environment for constraint programming.
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,7 @@ files:
34
34
  - COPYING
35
35
  - README
36
36
  - LGPL-LICENSE
37
+ - lib/gecoder/interface/constraints/bool_enum/channel.rb
37
38
  - lib/gecoder/interface/constraints/bool_enum/extensional.rb
38
39
  - lib/gecoder/interface/constraints/bool_enum/relation.rb
39
40
  - lib/gecoder/interface/constraints/set_enum/operation.rb
@@ -43,8 +44,10 @@ files:
43
44
  - lib/gecoder/interface/constraints/int/domain.rb
44
45
  - lib/gecoder/interface/constraints/int/arithmetic.rb
45
46
  - lib/gecoder/interface/constraints/int/linear.rb
47
+ - lib/gecoder/interface/constraints/int/channel.rb
46
48
  - lib/gecoder/interface/constraints/bool/boolean.rb
47
49
  - lib/gecoder/interface/constraints/bool/linear.rb
50
+ - lib/gecoder/interface/constraints/bool/channel.rb
48
51
  - lib/gecoder/interface/constraints/set/relation.rb
49
52
  - lib/gecoder/interface/constraints/set/connection.rb
50
53
  - lib/gecoder/interface/constraints/set/operation.rb
@@ -158,6 +161,7 @@ files:
158
161
  - tasks/dependencies.txt
159
162
  - specs/constraints
160
163
  - specs/constraints/boolean.rb
164
+ - specs/constraints/channel.rb
161
165
  - specs/constraints/int_domain.rb
162
166
  - specs/constraints/distinct.rb
163
167
  - specs/constraints/set_domain.rb
@@ -174,7 +178,6 @@ files:
174
178
  - specs/constraints/connection.rb
175
179
  - specs/constraints/cardinality.rb
176
180
  - specs/constraints/constraints.rb
177
- - specs/constraints/channel.rb
178
181
  - specs/constraints/linear.rb
179
182
  - specs/constraints/set_operation.rb
180
183
  - specs/constraints/extensional.rb
@@ -199,6 +202,7 @@ files:
199
202
  - ext/extconf.rb
200
203
  test_files:
201
204
  - specs/constraints/boolean.rb
205
+ - specs/constraints/channel.rb
202
206
  - specs/constraints/int_domain.rb
203
207
  - specs/constraints/distinct.rb
204
208
  - specs/constraints/set_domain.rb
@@ -215,7 +219,6 @@ test_files:
215
219
  - specs/constraints/connection.rb
216
220
  - specs/constraints/cardinality.rb
217
221
  - specs/constraints/constraints.rb
218
- - specs/constraints/channel.rb
219
222
  - specs/constraints/linear.rb
220
223
  - specs/constraints/set_operation.rb
221
224
  - specs/constraints/extensional.rb
@@ -246,6 +249,7 @@ extra_rdoc_files:
246
249
  - README
247
250
  - CHANGES
248
251
  - LGPL-LICENSE
252
+ - lib/gecoder/interface/constraints/bool_enum/channel.rb
249
253
  - lib/gecoder/interface/constraints/bool_enum/extensional.rb
250
254
  - lib/gecoder/interface/constraints/bool_enum/relation.rb
251
255
  - lib/gecoder/interface/constraints/set_enum/operation.rb
@@ -255,8 +259,10 @@ extra_rdoc_files:
255
259
  - lib/gecoder/interface/constraints/int/domain.rb
256
260
  - lib/gecoder/interface/constraints/int/arithmetic.rb
257
261
  - lib/gecoder/interface/constraints/int/linear.rb
262
+ - lib/gecoder/interface/constraints/int/channel.rb
258
263
  - lib/gecoder/interface/constraints/bool/boolean.rb
259
264
  - lib/gecoder/interface/constraints/bool/linear.rb
265
+ - lib/gecoder/interface/constraints/bool/channel.rb
260
266
  - lib/gecoder/interface/constraints/set/relation.rb
261
267
  - lib/gecoder/interface/constraints/set/connection.rb
262
268
  - lib/gecoder/interface/constraints/set/operation.rb