gecoder 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/specs/set_var.rb CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe Gecode::FreeSetVar, '(not assigned)' do
4
4
  before do
5
5
  model = Gecode::Model.new
6
- @var = model.set_var(0..3, 0..4)
6
+ @var = model.set_var(1..3, 0..4)
7
7
  end
8
8
 
9
9
  it 'should not be assigned' do
@@ -14,6 +14,34 @@ describe Gecode::FreeSetVar, '(not assigned)' do
14
14
  @var.inspect.should include('lub-range')
15
15
  @var.inspect.should include('glb-range')
16
16
  end
17
+
18
+ it 'should report the correct bounds' do
19
+ @var.lower_bound.sort.to_a.should == (1..3).to_a
20
+ @var.upper_bound.sort.to_a.should == (0..4).to_a
21
+ end
22
+
23
+ it 'should report correct bounds on upper bound' do
24
+ @var.upper_bound.min.should == 0
25
+ @var.upper_bound.max.should == 4
26
+ end
27
+
28
+ it 'should report correct bounds on lower bound' do
29
+ @var.lower_bound.min.should == 1
30
+ @var.lower_bound.max.should == 3
31
+ end
32
+
33
+ it 'should raise error when trying to access assigned value' do
34
+ lambda{ @var.value }.should raise_error(RuntimeError)
35
+ end
36
+
37
+ it 'should not raise error when enumerating over bound multiple times' do
38
+ # For C0 coverage.
39
+ lower_bound = @var.lower_bound
40
+ lambda do
41
+ lower_bound.each{}
42
+ lower_bound.each{}
43
+ end.should_not raise_error
44
+ end
17
45
  end
18
46
 
19
47
  describe Gecode::FreeSetVar, '(assigned)' do
@@ -27,13 +55,14 @@ describe Gecode::FreeSetVar, '(assigned)' do
27
55
  @var.should be_assigned
28
56
  end
29
57
 
30
- it 'should include the assigned elements' do
31
- @var.should include(1)
32
- @var.should_not include(0)
33
- end
34
-
35
58
  it "should give it's value when inspecting" do
36
- @var.inspect.should include('1..1')
59
+ @var.inspect.should include('[1]')
37
60
  @var.inspect.should_not include('lub-range')
38
61
  end
62
+
63
+ it 'should report the correct bounds' do
64
+ @var.upper_bound.to_a.should == [1]
65
+ @var.lower_bound.to_a.should == [1]
66
+ @var.value.to_a.should == [1]
67
+ end
39
68
  end
data/specs/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ module CustomVarMatchers
10
10
  @target = target
11
11
  return false unless @target.size == @expected.size
12
12
  @expected.each do |element|
13
- return false unless @target.in(element)
13
+ return false unless @target.include? element
14
14
  end
15
15
  return true
16
16
  end
@@ -37,15 +37,8 @@ module CustomVarMatchers
37
37
 
38
38
  def matches?(target)
39
39
  @target = target
40
- return false unless @target.glb_size == @expected_glb.size and
41
- @target.lub_size == @expected_lub.size
42
- @expected_glb.each do |element|
43
- return false unless @target.include_glb?(element)
44
- end
45
- @expected_lub.each do |element|
46
- return false unless @target.include_lub?(element)
47
- end
48
- return true
40
+ return @target.lower_bound.to_a == @expected_glb &&
41
+ @target.upper_bound.to_a == @expected_lub
49
42
  end
50
43
 
51
44
  def failure_message
@@ -4,6 +4,6 @@
4
4
  !function_prototype! {
5
5
  !function_call!
6
6
 
7
- rb_raise(rb_eArgError, "Mantatory parameters missing"); // FIXME
7
+ rb_raise(rb_eArgError, "Mandatory parameters missing"); // FIXME
8
8
  return Qnil;
9
9
  }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: gecoder
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
7
- date: 2007-07-11 00:00:00 +02:00
6
+ version: 0.6.0
7
+ date: 2007-07-18 00:00:00 +02:00
8
8
  summary: Ruby interface to Gecode, an environment for constraint programming.
9
9
  require_paths:
10
10
  - lib
@@ -52,6 +52,7 @@ files:
52
52
  - lib/gecoder/interface/constraints/int_enum_constraints.rb
53
53
  - lib/gecoder/interface/constraints/bool_enum_constraints.rb
54
54
  - lib/gecoder/interface/constraints/set_var_constraints.rb
55
+ - lib/gecoder/interface/constraints/set_enum_constraints.rb
55
56
  - lib/gecoder/interface/constraints/bool/boolean.rb
56
57
  - lib/gecoder/interface/constraints/int/linear.rb
57
58
  - lib/gecoder/interface/constraints/int/domain.rb
@@ -66,7 +67,10 @@ files:
66
67
  - lib/gecoder/interface/constraints/bool_enum/boolean.rb
67
68
  - lib/gecoder/interface/constraints/set/domain.rb
68
69
  - lib/gecoder/interface/constraints/set/relation.rb
70
+ - lib/gecoder/interface/constraints/set/connection.rb
69
71
  - lib/gecoder/interface/constraints/set/cardinality.rb
72
+ - lib/gecoder/interface/constraints/set_enum/distinct.rb
73
+ - lib/gecoder/interface/constraints/set_enum/channel.rb
70
74
  - lib/gecoder/bindings/bindings.rb
71
75
  - example/example_helper.rb
72
76
  - example/raw_bindings.rb
@@ -145,7 +149,6 @@ files:
145
149
  - tasks/svn.rake
146
150
  - specs/search.rb
147
151
  - specs/model.rb
148
- - specs/tmp
149
152
  - specs/branch.rb
150
153
  - specs/binding_changes.rb
151
154
  - specs/spec_helper.rb
@@ -155,6 +158,7 @@ files:
155
158
  - specs/bool_var.rb
156
159
  - specs/enum_matrix.rb
157
160
  - specs/set_var.rb
161
+ - specs/logging.rb
158
162
  - specs/constraints/linear.rb
159
163
  - specs/constraints/set_relation.rb
160
164
  - specs/constraints/distinct.rb
@@ -172,6 +176,7 @@ files:
172
176
  - specs/constraints/int_domain.rb
173
177
  - specs/constraints/set_domain.rb
174
178
  - specs/constraints/int_relation.rb
179
+ - specs/constraints/connection.rb
175
180
  - specs/constraints/cardinality.rb
176
181
  - ext/missing.h
177
182
  - ext/extconf.rb
@@ -207,6 +212,7 @@ extra_rdoc_files:
207
212
  - lib/gecoder/interface/constraints/int_enum_constraints.rb
208
213
  - lib/gecoder/interface/constraints/bool_enum_constraints.rb
209
214
  - lib/gecoder/interface/constraints/set_var_constraints.rb
215
+ - lib/gecoder/interface/constraints/set_enum_constraints.rb
210
216
  - lib/gecoder/interface/constraints/bool/boolean.rb
211
217
  - lib/gecoder/interface/constraints/int/linear.rb
212
218
  - lib/gecoder/interface/constraints/int/domain.rb
@@ -221,7 +227,10 @@ extra_rdoc_files:
221
227
  - lib/gecoder/interface/constraints/bool_enum/boolean.rb
222
228
  - lib/gecoder/interface/constraints/set/domain.rb
223
229
  - lib/gecoder/interface/constraints/set/relation.rb
230
+ - lib/gecoder/interface/constraints/set/connection.rb
224
231
  - lib/gecoder/interface/constraints/set/cardinality.rb
232
+ - lib/gecoder/interface/constraints/set_enum/distinct.rb
233
+ - lib/gecoder/interface/constraints/set_enum/channel.rb
225
234
  - lib/gecoder/bindings/bindings.rb
226
235
  executables: []
227
236
 
data/specs/tmp DELETED
@@ -1,22 +0,0 @@
1
- Idea: Write constraints in separate modules and then include the modules in
2
- the respective place.
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
- =begin
11
- it 'should handle disjunction being constraint to be true' do
12
- @bools.disjunction.must_be.true
13
- @model.solve!
14
- @bools.any?{ |b| b.true? }.should be_true
15
- end
16
-
17
- it 'should handle disjunction being constraint to be false' do
18
- @bools.disjunction.must_be.false
19
- @model.solve!
20
- @bools.all?{ |b| b.false? }.should be_true
21
- end
22
- =end