gecoder 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGES +15 -0
  2. data/README +6 -2
  3. data/example/equation_system.rb +15 -0
  4. data/example/magic_sequence.rb +7 -7
  5. data/example/money.rb +36 -0
  6. data/example/queens.rb +7 -8
  7. data/example/send_most_money.rb +1 -1
  8. data/example/square_tiling.rb +2 -2
  9. data/example/sudoku-set.rb +11 -12
  10. data/example/sudoku.rb +40 -45
  11. data/ext/extconf.rb +0 -0
  12. data/lib/gecoder/bindings.rb +42 -0
  13. data/lib/gecoder/bindings/bindings.rb +16 -0
  14. data/lib/gecoder/interface.rb +2 -1
  15. data/lib/gecoder/interface/branch.rb +16 -9
  16. data/lib/gecoder/interface/constraints.rb +410 -451
  17. data/lib/gecoder/interface/constraints/bool/boolean.rb +205 -213
  18. data/lib/gecoder/interface/constraints/bool/channel.rb +4 -5
  19. data/lib/gecoder/interface/constraints/bool/linear.rb +192 -21
  20. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +43 -39
  21. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +43 -49
  22. data/lib/gecoder/interface/constraints/bool_enum/relation.rb +38 -71
  23. data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +73 -22
  24. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +140 -61
  25. data/lib/gecoder/interface/constraints/extensional_regexp.rb +4 -4
  26. data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
  27. data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
  28. data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
  29. data/lib/gecoder/interface/constraints/int/arithmetic.rb +131 -130
  30. data/lib/gecoder/interface/constraints/int/channel.rb +21 -31
  31. data/lib/gecoder/interface/constraints/int/domain.rb +45 -42
  32. data/lib/gecoder/interface/constraints/int/linear.rb +85 -239
  33. data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
  34. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +55 -64
  35. data/lib/gecoder/interface/constraints/int_enum/channel.rb +35 -37
  36. data/lib/gecoder/interface/constraints/int_enum/count.rb +53 -78
  37. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +36 -46
  38. data/lib/gecoder/interface/constraints/int_enum/element.rb +39 -57
  39. data/lib/gecoder/interface/constraints/int_enum/equality.rb +15 -19
  40. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +65 -72
  41. data/lib/gecoder/interface/constraints/int_enum/sort.rb +42 -45
  42. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +79 -22
  43. data/lib/gecoder/interface/constraints/int_var_constraints.rb +215 -44
  44. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +14 -14
  45. data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
  46. data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
  47. data/lib/gecoder/interface/constraints/set/cardinality.rb +43 -53
  48. data/lib/gecoder/interface/constraints/set/channel.rb +26 -29
  49. data/lib/gecoder/interface/constraints/set/connection.rb +89 -152
  50. data/lib/gecoder/interface/constraints/set/domain.rb +112 -65
  51. data/lib/gecoder/interface/constraints/set/include.rb +36 -0
  52. data/lib/gecoder/interface/constraints/set/operation.rb +96 -110
  53. data/lib/gecoder/interface/constraints/set/relation.rb +114 -137
  54. data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
  55. data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
  56. data/lib/gecoder/interface/constraints/set_enum/channel.rb +23 -27
  57. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +18 -19
  58. data/lib/gecoder/interface/constraints/set_enum/operation.rb +62 -53
  59. data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
  60. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +73 -23
  61. data/lib/gecoder/interface/constraints/set_var_constraints.rb +222 -57
  62. data/lib/gecoder/interface/enum_matrix.rb +4 -4
  63. data/lib/gecoder/interface/enum_wrapper.rb +71 -22
  64. data/lib/gecoder/interface/model.rb +167 -12
  65. data/lib/gecoder/interface/model_sugar.rb +84 -0
  66. data/lib/gecoder/interface/search.rb +30 -18
  67. data/lib/gecoder/interface/variables.rb +103 -33
  68. data/lib/gecoder/version.rb +2 -2
  69. data/specs/bool_var.rb +19 -12
  70. data/specs/constraints/{boolean.rb → bool/boolean.rb} +103 -28
  71. data/specs/constraints/bool/boolean_properties.rb +51 -0
  72. data/specs/constraints/bool/linear.rb +213 -0
  73. data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
  74. data/specs/constraints/bool_enum/channel.rb +102 -0
  75. data/specs/constraints/{extensional.rb → bool_enum/extensional.rb} +32 -101
  76. data/specs/constraints/constraint_helper.rb +149 -179
  77. data/specs/constraints/constraint_receivers.rb +103 -0
  78. data/specs/constraints/constraints.rb +6 -63
  79. data/specs/constraints/fixnum_enum/element.rb +58 -0
  80. data/specs/constraints/fixnum_enum/operation.rb +67 -0
  81. data/specs/constraints/int/arithmetic.rb +149 -0
  82. data/specs/constraints/int/channel.rb +101 -0
  83. data/specs/constraints/int/domain.rb +106 -0
  84. data/specs/constraints/int/linear.rb +183 -0
  85. data/specs/constraints/int/linear_properties.rb +97 -0
  86. data/specs/constraints/int/relation.rb +84 -0
  87. data/specs/constraints/int_enum/arithmetic.rb +72 -0
  88. data/specs/constraints/int_enum/channel.rb +57 -0
  89. data/specs/constraints/int_enum/count.rb +72 -0
  90. data/specs/constraints/int_enum/distinct.rb +80 -0
  91. data/specs/constraints/int_enum/element.rb +61 -0
  92. data/specs/constraints/int_enum/equality.rb +29 -0
  93. data/specs/constraints/int_enum/extensional.rb +224 -0
  94. data/specs/constraints/int_enum/sort.rb +167 -0
  95. data/specs/constraints/operands.rb +264 -0
  96. data/specs/constraints/property_helper.rb +443 -0
  97. data/specs/constraints/reification_sugar.rb +4 -5
  98. data/specs/constraints/selected_set/select.rb +56 -0
  99. data/specs/constraints/selected_set/select_properties.rb +157 -0
  100. data/specs/constraints/set/cardinality.rb +58 -0
  101. data/specs/constraints/set/cardinality_properties.rb +46 -0
  102. data/specs/constraints/set/channel.rb +77 -0
  103. data/specs/constraints/set/connection.rb +176 -0
  104. data/specs/constraints/set/domain.rb +197 -0
  105. data/specs/constraints/set/include.rb +36 -0
  106. data/specs/constraints/set/operation.rb +132 -0
  107. data/specs/constraints/set/relation.rb +117 -0
  108. data/specs/constraints/set_elements/relation.rb +84 -0
  109. data/specs/constraints/set_enum/channel.rb +80 -0
  110. data/specs/constraints/set_enum/distinct.rb +59 -0
  111. data/specs/constraints/set_enum/operation.rb +111 -0
  112. data/specs/constraints/set_enum/select.rb +73 -0
  113. data/specs/enum_wrapper.rb +53 -3
  114. data/specs/int_var.rb +44 -25
  115. data/specs/model.rb +58 -1
  116. data/specs/model_sugar.rb +30 -0
  117. data/specs/search.rb +24 -5
  118. data/specs/selected_set.rb +39 -0
  119. data/specs/set_elements.rb +34 -0
  120. data/specs/set_var.rb +22 -8
  121. data/specs/spec_helper.rb +206 -6
  122. data/tasks/distribution.rake +22 -7
  123. data/tasks/svn.rake +3 -1
  124. metadata +218 -134
  125. data/lib/gecoder/interface/constraints/set_enum/selection.rb +0 -217
  126. data/specs/constraints/arithmetic.rb +0 -351
  127. data/specs/constraints/bool_enum_relation.rb +0 -160
  128. data/specs/constraints/cardinality.rb +0 -157
  129. data/specs/constraints/channel.rb +0 -454
  130. data/specs/constraints/connection.rb +0 -369
  131. data/specs/constraints/count.rb +0 -146
  132. data/specs/constraints/distinct.rb +0 -164
  133. data/specs/constraints/element.rb +0 -108
  134. data/specs/constraints/equality.rb +0 -31
  135. data/specs/constraints/int_domain.rb +0 -70
  136. data/specs/constraints/int_relation.rb +0 -82
  137. data/specs/constraints/linear.rb +0 -340
  138. data/specs/constraints/selection.rb +0 -292
  139. data/specs/constraints/set_domain.rb +0 -185
  140. data/specs/constraints/set_operation.rb +0 -285
  141. data/specs/constraints/set_relation.rb +0 -197
  142. data/specs/constraints/sort.rb +0 -179
@@ -1,164 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- class DistinctSampleProblem < Gecode::Model
5
- attr :vars
6
- attr :sets
7
-
8
- def initialize
9
- @vars = int_var_array(2, 1)
10
- @sets = set_var_array(2, [], 0..2)
11
- branch_on @sets
12
- end
13
- end
14
-
15
- describe Gecode::Constraints::IntEnum::Distinct do
16
- before do
17
- @model = DistinctSampleProblem.new
18
- @invoke_options = lambda do |hash|
19
- @model.vars.must_be.distinct(hash)
20
- @model.solve!
21
- end
22
- @expect_options = option_expectation do |strength, kind, reif_var|
23
- Gecode::Raw.should_receive(:distinct).once.with(
24
- an_instance_of(Gecode::Raw::Space),
25
- an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
26
- end
27
- end
28
-
29
- it 'should translate into a distinct constraint' do
30
- Gecode::Raw.should_receive(:distinct).once.with(
31
- an_instance_of(Gecode::Raw::Space),
32
- anything, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
33
- @invoke_options.call({})
34
- end
35
-
36
- it 'should constrain variables to be distinct' do
37
- # This won't work well without branching or propagation strengths. So this
38
- # just shows that the distinct constraint will cause trivially unsolvable
39
- # problems to directly fail.
40
- @model.vars.must_be.distinct
41
- @model.solve!.should be_nil
42
- end
43
-
44
- it 'should not allow negation' do
45
- lambda{ @model.vars.must_not_be.distinct }.should raise_error(
46
- Gecode::MissingConstraintError)
47
- end
48
-
49
- it_should_behave_like 'non-reifiable constraint'
50
- end
51
-
52
- describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
53
- before do
54
- @model = DistinctSampleProblem.new
55
- @invoke_options = lambda do |hash|
56
- @model.vars.with_offsets(1,2).must_be.distinct(hash)
57
- @model.solve!
58
- end
59
- @expect_options = option_expectation do |strength, kind, reif_var|
60
- if reif_var.nil?
61
- Gecode::Raw.should_receive(:distinct).once.with(
62
- an_instance_of(Gecode::Raw::Space),
63
- anything, an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
64
- else
65
- Gecode::Raw.should_receive(:distinct).once.with(
66
- an_instance_of(Gecode::Raw::Space),
67
- anything, an_instance_of(Gecode::Raw::IntVarArray),
68
- strength, kind, reif_var)
69
- end
70
- end
71
- end
72
-
73
- it 'should translate into a distinct constraint with offsets' do
74
- Gecode::Raw.should_receive(:distinct).once.with(
75
- an_instance_of(Gecode::Raw::Space),
76
- anything, anything, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
77
- @invoke_options.call({})
78
- end
79
-
80
- it 'should consider offsets when making variables distinct' do
81
- @model.vars.with_offsets(-1,0).must_be.distinct
82
- x,y = @model.solve!.vars
83
- x.value.should equal(1)
84
- y.value.should equal(1)
85
- end
86
-
87
- # This tests two distinct in conjunction. It's here because of a bug found.
88
- it 'should play nice with normal distinct' do
89
- @model.vars.with_offsets(-1,0).must_be.distinct
90
- @model.vars.must_be.distinct
91
- @model.solve!.should be_nil
92
- end
93
-
94
- it 'should accept an array as offsets' do
95
- @model.vars.with_offsets([-1,0]).must_be.distinct
96
- x,y = @model.solve!.vars
97
- x.value.should equal(1)
98
- y.value.should equal(1)
99
- end
100
-
101
- it 'should not allow negation' do
102
- lambda{ @model.vars.with_offsets(1,2).must_not_be.distinct }.should
103
- raise_error(Gecode::MissingConstraintError)
104
- end
105
-
106
- it_should_behave_like 'non-reifiable constraint'
107
- end
108
-
109
- describe Gecode::Constraints::SetEnum::Distinct, ' (at most one)' do
110
- before do
111
- @model = DistinctSampleProblem.new
112
- @sets = @model.sets
113
- @size = 2
114
-
115
- @invoke_options = lambda do |hash|
116
- @sets.must.at_most_share_one_element hash.update(:size => @size)
117
- @model.solve!
118
- end
119
- @expect_options = lambda do |strength, reif_var|
120
- Gecode::Raw.should_receive(:atmostOne).once.with(
121
- an_instance_of(Gecode::Raw::Space),
122
- an_instance_of(Gecode::Raw::SetVarArray), @size)
123
- end
124
- end
125
-
126
- it 'should translate into a atmostOne constraint' do
127
- Gecode::Raw.should_receive(:atmostOne).once.with(
128
- an_instance_of(Gecode::Raw::Space),
129
- an_instance_of(Gecode::Raw::SetVarArray), @size)
130
- @sets.must.at_most_share_one_element(:size => @size)
131
- @model.solve!
132
- end
133
-
134
- it 'should constrain sets to have at most one element in common' do
135
- @sets.must.at_most_share_one_element(:size => @size)
136
- @sets[0].must_not_be.superset_of 0
137
- solution = @model.solve!
138
- solution.should_not be_nil
139
- set1, set2 = solution.sets
140
- set1.value.size.should == @size
141
- set2.value.size.should == @size
142
- (set1.value.to_a & set2.value.to_a).size.should <= 1
143
- end
144
-
145
- it 'should not allow negation' do
146
- lambda do
147
- @sets.must_not.at_most_share_one_element(:size => @size)
148
- end.should raise_error(Gecode::MissingConstraintError)
149
- end
150
-
151
- it 'should not allow options other than :size' do
152
- lambda do
153
- @sets.must.at_most_share_one_element(:size => @size, :foo => 17)
154
- end.should raise_error(ArgumentError)
155
- end
156
-
157
- it 'should raise error if :size is not specified' do
158
- lambda do
159
- @sets.must.at_most_share_one_element
160
- end.should raise_error(ArgumentError)
161
- end
162
-
163
- it_should_behave_like 'non-reifiable set constraint'
164
- end
@@ -1,108 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- class ElementSampleProblem < Gecode::Model
5
- attr :prices
6
- attr :store
7
- attr :price
8
- attr :fixnum_prices
9
-
10
- def initialize
11
- prices = [17, 63, 45, 63]
12
- @fixnum_prices = wrap_enum(prices)
13
- @prices = int_var_array(4, prices)
14
- @store = int_var(0...prices.size)
15
- @price = int_var(prices)
16
- branch_on wrap_enum([@store])
17
- end
18
- end
19
-
20
- describe Gecode::Constraints::IntEnum::Element do
21
- before do
22
- @model = ElementSampleProblem.new
23
- @prices = @model.prices
24
- @target = @price = @model.price
25
- @store = @model.store
26
- @fixnum_prices = @model.fixnum_prices
27
-
28
- # Creates an expectation corresponding to the specified input.
29
- @expect = lambda do |element, relation, target, strength, kind, reif_var, negated|
30
- @model.allow_space_access do
31
- target = an_instance_of(Gecode::Raw::IntVar) if target.respond_to? :bind
32
- element = an_instance_of(Gecode::Raw::IntVar) if element.respond_to? :bind
33
- if reif_var.nil?
34
- if !negated and relation == Gecode::Raw::IRT_EQ and
35
- !target.kind_of? Fixnum
36
- Gecode::Raw.should_receive(:element).once.with(
37
- an_instance_of(Gecode::Raw::Space),
38
- an_instance_of(Gecode::Raw::IntVarArray),
39
- element, target, strength, kind)
40
- else
41
- Gecode::Raw.should_receive(:element).once.with(
42
- an_instance_of(Gecode::Raw::Space),
43
- an_instance_of(Gecode::Raw::IntVarArray),
44
- element, an_instance_of(Gecode::Raw::IntVar), strength, kind)
45
- Gecode::Raw.should_receive(:rel).once.with(
46
- an_instance_of(Gecode::Raw::Space),
47
- an_instance_of(Gecode::Raw::IntVar),
48
- relation, target, strength, kind)
49
- end
50
- else
51
- Gecode::Raw.should_receive(:element).once.with(
52
- an_instance_of(Gecode::Raw::Space),
53
- an_instance_of(Gecode::Raw::IntVarArray),
54
- element, an_instance_of(Gecode::Raw::IntVar), strength, kind)
55
- Gecode::Raw.should_receive(:rel).once.with(
56
- an_instance_of(Gecode::Raw::Space),
57
- an_instance_of(Gecode::Raw::IntVar), relation, target,
58
- an_instance_of(Gecode::Raw::BoolVar), strength, kind)
59
- end
60
- end
61
- end
62
-
63
- # For constraint option spec.
64
- @invoke_options = lambda do |hash|
65
- @prices[@store].must_be.greater_than(@price, hash)
66
- @model.solve!
67
- end
68
- @expect_options = option_expectation do |strength, kind, reif_var|
69
- @expect.call(@store, Gecode::Raw::IRT_GR, @price, strength, kind,
70
- reif_var, false)
71
- end
72
-
73
- # For composite spec.
74
- @invoke_relation = lambda do |relation, target, negated|
75
- if negated
76
- @prices[@store].must_not.send(relation, target)
77
- else
78
- @prices[@store].must.send(relation, target)
79
- end
80
- @model.solve!
81
- end
82
- @expect_relation = lambda do |relation, target, negated|
83
- @expect.call(@store, relation, target, Gecode::Raw::ICL_DEF,
84
- Gecode::Raw::PK_DEF, nil, negated)
85
- end
86
- end
87
-
88
- it 'should not disturb normal array access' do
89
- @fixnum_prices[2].should_not be_nil
90
- @prices[2].should_not be_nil
91
- end
92
-
93
- it 'should handle fixnum enums as enumeration' do
94
- @fixnum_prices[@store].must == @fixnum_prices[2]
95
- @model.solve!.store.value.should equal(2)
96
- end
97
-
98
- it 'should translate reification when using equality' do
99
- bool_var = @model.bool_var
100
- @expect.call(@store, Gecode::Raw::IRT_EQ, @target, Gecode::Raw::ICL_DEF,
101
- Gecode::Raw::PK_DEF, bool_var, false)
102
- @prices[@store].must_be.equal_to(@target, :reify => bool_var)
103
- @model.solve!
104
- end
105
-
106
- it_should_behave_like 'composite constraint'
107
- it_should_behave_like 'reifiable constraint'
108
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- describe Gecode::Constraints::IntEnum::Equality do
5
- before do
6
- @model = Gecode::Model.new
7
- @vars = @model.int_var_array(4, -2..2)
8
- @invoke_options = lambda do |hash|
9
- @vars.must_be.equal(hash)
10
- @model.solve!
11
- end
12
- @expect_options = option_expectation do |strength, kind, reif_var|
13
- Gecode::Raw.should_receive(:eq).once.with(
14
- an_instance_of(Gecode::Raw::Space),
15
- anything, strength, kind)
16
- end
17
- end
18
-
19
- it 'should translate equality constraints' do
20
- @expect_options.call({})
21
- @invoke_options.call({})
22
- @vars.must_be.equal
23
- end
24
-
25
- it 'should not allow negation' do
26
- lambda{ @vars.must_not_be.equal }.should raise_error(
27
- Gecode::MissingConstraintError)
28
- end
29
-
30
- it_should_behave_like 'non-reifiable constraint'
31
- end
@@ -1,70 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- describe Gecode::Constraints::Int::Domain do
5
- before do
6
- @model = Gecode::Model.new
7
- @domain = 0..3
8
- @x = @model.int_var(@domain)
9
- @range_domain = 1..2
10
- @three_dot_range_domain = 1...2
11
- @non_range_domain = [1, 3]
12
-
13
- @invoke_options = lambda do |hash|
14
- @x.must_be.in(@non_range_domain, hash)
15
- @model.solve!
16
- end
17
- @expect_options = option_expectation do |strength, kind, reif_var|
18
- @model.allow_space_access do
19
- if reif_var.nil?
20
- Gecode::Raw.should_receive(:dom).once.with(
21
- an_instance_of(Gecode::Raw::Space),
22
- an_instance_of(Gecode::Raw::IntVar),
23
- an_instance_of(Gecode::Raw::IntSet),
24
- strength, kind)
25
- else
26
- Gecode::Raw.should_receive(:dom).once.with(
27
- an_instance_of(Gecode::Raw::Space),
28
- an_instance_of(Gecode::Raw::IntVar),
29
- an_instance_of(Gecode::Raw::IntSet),
30
- reif_var, strength, kind)
31
- end
32
- end
33
- end
34
- end
35
-
36
- it 'should translate domain constraints with range domains' do
37
- Gecode::Raw.should_receive(:dom).once.with(
38
- an_instance_of(Gecode::Raw::Space),
39
- an_instance_of(Gecode::Raw::IntVar), @range_domain.first,
40
- @range_domain.last, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
41
- @x.must_be.in @range_domain
42
- @model.solve!
43
- end
44
-
45
- it 'should translate domain constraints with three dot range domains' do
46
- Gecode::Raw.should_receive(:dom).once.with(
47
- an_instance_of(Gecode::Raw::Space),
48
- an_instance_of(Gecode::Raw::IntVar), @three_dot_range_domain.first,
49
- @three_dot_range_domain.last, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
50
- @x.must_be.in @three_dot_range_domain
51
- @model.solve!
52
- end
53
-
54
- it 'should translate domain constraints with non-range domains' do
55
- @expect_options.call({})
56
- @invoke_options.call({})
57
- end
58
-
59
- it 'should handle negation' do
60
- @x.must_not_be.in @range_domain
61
- @model.solve!
62
- @x.should have_domain(@domain.to_a - @range_domain.to_a)
63
- end
64
-
65
- it 'should raise error if the right hand side is not an enumeration' do
66
- lambda{ @x.must_be.in 'hello' }.should raise_error(TypeError)
67
- end
68
-
69
- it_should_behave_like 'reifiable constraint'
70
- end
@@ -1,82 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
5
- before do
6
- @model = Gecode::Model.new
7
- @x = @model.int_var(1..2)
8
- @int = 4
9
- @y = @model.int_var(1..2)
10
-
11
- # For constraint option spec.
12
- @invoke_options = lambda do |hash|
13
- @x.must_be.greater_than(3, hash)
14
- @model.solve!
15
- end
16
- @expect_options = option_expectation do |strength, kind, reif_var|
17
- if reif_var.nil?
18
- Gecode::Raw.should_receive(:rel).once.with(
19
- an_instance_of(Gecode::Raw::Space),
20
- anything, Gecode::Raw::IRT_GR, anything,
21
- strength, kind)
22
- else
23
- Gecode::Raw.should_receive(:rel).once.with(
24
- an_instance_of(Gecode::Raw::Space),
25
- an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_GR, anything,
26
- reif_var, strength, kind)
27
- end
28
- end
29
- end
30
-
31
- Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
32
- it "should translate #{relation} with constant to simple relation" do
33
- Gecode::Raw.should_receive(:rel).once.with(
34
- an_instance_of(Gecode::Raw::Space),
35
- an_instance_of(Gecode::Raw::IntVar),
36
- type, @int, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
37
- @x.must.send(relation, @int)
38
- @model.solve!
39
- end
40
- end
41
-
42
- Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
43
- it "should translate negated #{relation} with constant to simple relation" do
44
- Gecode::Raw.should_receive(:rel).once.with(
45
- an_instance_of(Gecode::Raw::Space),
46
- an_instance_of(Gecode::Raw::IntVar),
47
- type, @int, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
48
- @x.must_not.send(relation, @int)
49
- @model.solve!
50
- end
51
- end
52
-
53
- Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
54
- it "should translate #{relation} with variables to simple relation" do
55
- Gecode::Raw.should_receive(:rel).once.with(
56
- an_instance_of(Gecode::Raw::Space),
57
- an_instance_of(Gecode::Raw::IntVar), type,
58
- an_instance_of(Gecode::Raw::IntVar),
59
- Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
60
- @x.must.send(relation, @y)
61
- @model.solve!
62
- end
63
- end
64
-
65
- Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
66
- it "should translate negated #{relation} with variable to simple relation" do
67
- Gecode::Raw.should_receive(:rel).once.with(
68
- an_instance_of(Gecode::Raw::Space),
69
- an_instance_of(Gecode::Raw::IntVar), type,
70
- an_instance_of(Gecode::Raw::IntVar),
71
- Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
72
- @x.must_not.send(relation, @y)
73
- @model.solve!
74
- end
75
- end
76
-
77
- it 'should raise error on arguments of the wrong type' do
78
- lambda{ @x.must == 'hello' }.should raise_error(TypeError)
79
- end
80
-
81
- it_should_behave_like 'reifiable constraint'
82
- end