gecoder-with-gecode 0.9.0-x86-mswin32-60
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.
- data/CHANGES +137 -0
- data/COPYING +17 -0
- data/LGPL-LICENSE +458 -0
- data/README +58 -0
- data/Rakefile +14 -0
- data/example/equation_system.rb +15 -0
- data/example/example_helper.rb +1 -0
- data/example/magic_sequence.rb +43 -0
- data/example/money.rb +36 -0
- data/example/queens.rb +42 -0
- data/example/send_more_money.rb +43 -0
- data/example/send_most_money.rb +58 -0
- data/example/square_tiling.rb +84 -0
- data/example/sudoku-set.rb +106 -0
- data/example/sudoku.rb +56 -0
- data/lib/gecode.dll +0 -0
- data/lib/gecoder.rb +5 -0
- data/lib/gecoder/bindings.rb +96 -0
- data/lib/gecoder/bindings/bindings.rb +2029 -0
- data/lib/gecoder/interface.rb +9 -0
- data/lib/gecoder/interface/binding_changes.rb +9 -0
- data/lib/gecoder/interface/branch.rb +163 -0
- data/lib/gecoder/interface/constraints.rb +471 -0
- data/lib/gecoder/interface/constraints/bool/boolean.rb +251 -0
- data/lib/gecoder/interface/constraints/bool/channel.rb +7 -0
- data/lib/gecoder/interface/constraints/bool/linear.rb +200 -0
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +68 -0
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +106 -0
- data/lib/gecoder/interface/constraints/bool_enum/relation.rb +55 -0
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +84 -0
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +155 -0
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
- data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
- data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
- data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +150 -0
- data/lib/gecoder/interface/constraints/int/channel.rb +51 -0
- data/lib/gecoder/interface/constraints/int/domain.rb +80 -0
- data/lib/gecoder/interface/constraints/int/linear.rb +143 -0
- data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +63 -0
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +86 -0
- data/lib/gecoder/interface/constraints/int_enum/count.rb +66 -0
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +64 -0
- data/lib/gecoder/interface/constraints/int_enum/element.rb +64 -0
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +37 -0
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +187 -0
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +135 -0
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +95 -0
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +230 -0
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
- data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
- data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +65 -0
- data/lib/gecoder/interface/constraints/set/channel.rb +51 -0
- data/lib/gecoder/interface/constraints/set/connection.rb +130 -0
- data/lib/gecoder/interface/constraints/set/domain.rb +156 -0
- data/lib/gecoder/interface/constraints/set/include.rb +36 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +118 -0
- data/lib/gecoder/interface/constraints/set/relation.rb +155 -0
- data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
- data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +45 -0
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +43 -0
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +69 -0
- data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +84 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +243 -0
- data/lib/gecoder/interface/enum_matrix.rb +64 -0
- data/lib/gecoder/interface/enum_wrapper.rb +205 -0
- data/lib/gecoder/interface/model.rb +453 -0
- data/lib/gecoder/interface/model_sugar.rb +84 -0
- data/lib/gecoder/interface/search.rb +197 -0
- data/lib/gecoder/interface/variables.rb +306 -0
- data/lib/gecoder/version.rb +4 -0
- data/specs/bool_var.rb +81 -0
- data/specs/branch.rb +185 -0
- data/specs/constraints/bool/boolean.rb +317 -0
- data/specs/constraints/bool/boolean_properties.rb +51 -0
- data/specs/constraints/bool/linear.rb +213 -0
- data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
- data/specs/constraints/bool_enum/channel.rb +102 -0
- data/specs/constraints/bool_enum/extensional.rb +225 -0
- data/specs/constraints/constraint_helper.rb +234 -0
- data/specs/constraints/constraint_receivers.rb +103 -0
- data/specs/constraints/constraints.rb +26 -0
- data/specs/constraints/fixnum_enum/element.rb +58 -0
- data/specs/constraints/fixnum_enum/operation.rb +67 -0
- data/specs/constraints/int/arithmetic.rb +149 -0
- data/specs/constraints/int/channel.rb +101 -0
- data/specs/constraints/int/domain.rb +106 -0
- data/specs/constraints/int/linear.rb +183 -0
- data/specs/constraints/int/linear_properties.rb +97 -0
- data/specs/constraints/int/relation.rb +84 -0
- data/specs/constraints/int_enum/arithmetic.rb +72 -0
- data/specs/constraints/int_enum/channel.rb +57 -0
- data/specs/constraints/int_enum/count.rb +72 -0
- data/specs/constraints/int_enum/distinct.rb +80 -0
- data/specs/constraints/int_enum/element.rb +61 -0
- data/specs/constraints/int_enum/equality.rb +29 -0
- data/specs/constraints/int_enum/extensional.rb +224 -0
- data/specs/constraints/int_enum/sort.rb +167 -0
- data/specs/constraints/operands.rb +264 -0
- data/specs/constraints/property_helper.rb +443 -0
- data/specs/constraints/reification_sugar.rb +69 -0
- data/specs/constraints/selected_set/select.rb +56 -0
- data/specs/constraints/selected_set/select_properties.rb +157 -0
- data/specs/constraints/set/cardinality.rb +58 -0
- data/specs/constraints/set/cardinality_properties.rb +46 -0
- data/specs/constraints/set/channel.rb +77 -0
- data/specs/constraints/set/connection.rb +176 -0
- data/specs/constraints/set/domain.rb +197 -0
- data/specs/constraints/set/include.rb +36 -0
- data/specs/constraints/set/operation.rb +132 -0
- data/specs/constraints/set/relation.rb +117 -0
- data/specs/constraints/set_elements/relation.rb +84 -0
- data/specs/constraints/set_enum/channel.rb +80 -0
- data/specs/constraints/set_enum/distinct.rb +59 -0
- data/specs/constraints/set_enum/operation.rb +111 -0
- data/specs/constraints/set_enum/select.rb +73 -0
- data/specs/distribution.rb +14 -0
- data/specs/enum_matrix.rb +43 -0
- data/specs/enum_wrapper.rb +179 -0
- data/specs/examples.rb +17 -0
- data/specs/int_var.rb +163 -0
- data/specs/logging.rb +24 -0
- data/specs/model.rb +325 -0
- data/specs/model_sugar.rb +30 -0
- data/specs/search.rb +383 -0
- data/specs/selected_set.rb +39 -0
- data/specs/set_elements.rb +34 -0
- data/specs/set_var.rb +82 -0
- data/specs/spec_helper.rb +265 -0
- data/tasks/all_tasks.rb +1 -0
- data/tasks/dependencies.txt +22 -0
- data/tasks/distribution.rake +194 -0
- data/tasks/rcov.rake +18 -0
- data/tasks/specs.rake +21 -0
- data/tasks/svn.rake +16 -0
- data/tasks/website.rake +51 -0
- data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesupport.dll +0 -0
- data/vendor/rust/README +28 -0
- data/vendor/rust/bin/cxxgenerator.rb +93 -0
- data/vendor/rust/include/rust_checks.hh +116 -0
- data/vendor/rust/include/rust_conversions.hh +102 -0
- data/vendor/rust/rust.rb +67 -0
- data/vendor/rust/rust/attribute.rb +51 -0
- data/vendor/rust/rust/bindings.rb +172 -0
- data/vendor/rust/rust/class.rb +337 -0
- data/vendor/rust/rust/constants.rb +48 -0
- data/vendor/rust/rust/container.rb +110 -0
- data/vendor/rust/rust/cppifaceparser.rb +129 -0
- data/vendor/rust/rust/cwrapper.rb +72 -0
- data/vendor/rust/rust/cxxclass.rb +96 -0
- data/vendor/rust/rust/element.rb +81 -0
- data/vendor/rust/rust/enum.rb +63 -0
- data/vendor/rust/rust/function.rb +407 -0
- data/vendor/rust/rust/namespace.rb +61 -0
- data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
- data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
- data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
- data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
- data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
- data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +100 -0
- data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
- data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
- data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
- data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
- data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
- data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
- data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
- data/vendor/rust/rust/type.rb +98 -0
- data/vendor/rust/test/Makefile +4 -0
- data/vendor/rust/test/constants.rb +36 -0
- data/vendor/rust/test/cppclass.cc +45 -0
- data/vendor/rust/test/cppclass.hh +67 -0
- data/vendor/rust/test/cppclass.rb +59 -0
- data/vendor/rust/test/cwrapper.c +74 -0
- data/vendor/rust/test/cwrapper.h +41 -0
- data/vendor/rust/test/cwrapper.rb +56 -0
- data/vendor/rust/test/dummyclass.hh +31 -0
- data/vendor/rust/test/lib/extension-test.rb +98 -0
- data/vendor/rust/test/operators.cc +41 -0
- data/vendor/rust/test/operators.hh +39 -0
- data/vendor/rust/test/operators.rb +39 -0
- data/vendor/rust/test/test-constants.rb +43 -0
- data/vendor/rust/test/test-cppclass.rb +82 -0
- data/vendor/rust/test/test-cwrapper.rb +80 -0
- data/vendor/rust/test/test-operators.rb +42 -0
- metadata +393 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class ReifSugarSampleProblem < Gecode::Model
|
4
|
+
attr :x
|
5
|
+
attr :y
|
6
|
+
attr :z
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@x = int_var(0..1)
|
10
|
+
@y = int_var(1..2)
|
11
|
+
@z = int_var(3..4)
|
12
|
+
branch_on wrap_enum([@x, @y, @z])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Gecode::ReifiableConstraint do
|
17
|
+
before do
|
18
|
+
@model = ReifSugarSampleProblem.new
|
19
|
+
@x = @model.x
|
20
|
+
@y = @model.y
|
21
|
+
@z = @model.z
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should fail disjunctions if neither side can be satisfied' do
|
25
|
+
(@x.must == 3) | (@y.must == 3)
|
26
|
+
lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should solve disjunctions' do
|
30
|
+
(@x.must > 0) | (@y.must == 3)
|
31
|
+
sol = @model.solve!
|
32
|
+
sol.should_not be_nil
|
33
|
+
sol.x.should have_domain([1])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should fail conjunctions if one side can\'t be satisfied' do
|
37
|
+
(@x.must > 3) & (@y.must == 3)
|
38
|
+
lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should solve conjunctions' do
|
42
|
+
(@x.must > 0) & (@y.must == 2)
|
43
|
+
sol = @model.solve!
|
44
|
+
sol.should_not be_nil
|
45
|
+
sol.x.should have_domain([1])
|
46
|
+
sol.y.should have_domain([2])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should handle the same variable being used multiple times' do
|
50
|
+
(@z.must == 4) | (@z.must == 4)
|
51
|
+
sol = @model.solve!
|
52
|
+
sol.should_not be_nil
|
53
|
+
sol.z.should have_domain([4])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should handle nested operations' do
|
57
|
+
((@x.must > 3) & (@y.must == 2)) | (@z.must == 4) | (
|
58
|
+
(@x.must == 0) & (@z.must == 4))
|
59
|
+
sol = @model.solve!
|
60
|
+
sol.should_not be_nil
|
61
|
+
sol.x.should have_domain([0])
|
62
|
+
sol.z.should have_domain([4])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should handle negations' do
|
66
|
+
(@z.must_not == 4) & (@z.must == 4)
|
67
|
+
lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class SelectionSampleProblem < Gecode::Model
|
4
|
+
attr :sets
|
5
|
+
attr :set
|
6
|
+
attr :target
|
7
|
+
attr :index
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@sets = set_var_array(3, [], 0..20)
|
11
|
+
@set = set_var([], 0...3)
|
12
|
+
@target = set_var([], 0..20)
|
13
|
+
@index = int_var(0...3)
|
14
|
+
branch_on wrap_enum([@index])
|
15
|
+
branch_on @sets
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Gecode::SetEnum::Select, ' (disjoint)' do
|
20
|
+
include GecodeR::Specs::SetHelper
|
21
|
+
|
22
|
+
before do
|
23
|
+
@model = SelectionSampleProblem.new
|
24
|
+
@sets = @model.sets
|
25
|
+
@set = @model.set
|
26
|
+
@target = @model.target
|
27
|
+
@model.branch_on @model.wrap_enum([@target, @set])
|
28
|
+
|
29
|
+
@types = [:selected_set]
|
30
|
+
@invoke = lambda do |receiver, hash|
|
31
|
+
receiver.disjoint(hash)
|
32
|
+
@model.solve!
|
33
|
+
end
|
34
|
+
@expect = lambda do |var, opts, reif_var|
|
35
|
+
set_enum, set = var
|
36
|
+
Gecode::Raw.should_receive(:selectDisjoint).once.with(
|
37
|
+
an_instance_of(Gecode::Raw::Space),
|
38
|
+
set_enum, set)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should constrain the selected sets to be disjoint' do
|
43
|
+
@sets[0].must_be.superset_of([7,8])
|
44
|
+
@sets[1].must_be.superset_of([5,7,9])
|
45
|
+
@sets[2].must_be.superset_of([6,8,10])
|
46
|
+
@sets[@set].must_be.disjoint
|
47
|
+
@set.size.must > 1
|
48
|
+
@model.solve!.should_not be_nil
|
49
|
+
|
50
|
+
@set.value.to_a.sort.should == [1,2]
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like 'non-reifiable set constraint'
|
54
|
+
it_should_behave_like 'non-negatable constraint'
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
class SelectionSampleProblem < Gecode::Model
|
4
|
+
attr :sets
|
5
|
+
attr :set
|
6
|
+
attr :target
|
7
|
+
attr :index
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@sets = set_var_array(3, [], 0..20)
|
11
|
+
@set = set_var([], 0...3)
|
12
|
+
@target = set_var([], 0..20)
|
13
|
+
@index = int_var(0...3)
|
14
|
+
branch_on wrap_enum([@index])
|
15
|
+
branch_on @sets
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Gecode::SelectedSet::Select, ' (union)' do
|
20
|
+
include GecodeR::Specs::SetHelper
|
21
|
+
|
22
|
+
before do
|
23
|
+
@model = SelectionSampleProblem.new
|
24
|
+
@sets = @model.sets
|
25
|
+
@set = @model.set
|
26
|
+
@model.branch_on @set
|
27
|
+
|
28
|
+
@property_types = [:selected_set]
|
29
|
+
@select_property = lambda do |selected_set|
|
30
|
+
selected_set.union
|
31
|
+
end
|
32
|
+
@selected_property = @sets[@set].union
|
33
|
+
@constraint_class = Gecode::BlockConstraint
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should constrain the selected union of an enum of sets' do
|
37
|
+
@sets[@set].union.must_be.subset_of([5,7,9])
|
38
|
+
@sets[@set].union.must_be.superset_of([5])
|
39
|
+
@model.solve!
|
40
|
+
union = @set.value.inject([]) do |union, i|
|
41
|
+
union += @sets[i].value.to_a
|
42
|
+
end.uniq
|
43
|
+
union.should include(5)
|
44
|
+
(union - [5,7,9]).should be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should translate into a select union constraint' do
|
48
|
+
Gecode::Raw.should_receive(:selectUnion)
|
49
|
+
@sets[@set].union.must_be.subset_of([5,7,9])
|
50
|
+
@model.solve!
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like(
|
54
|
+
'property that produces set operand by short circuiting equality')
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Gecode::SetEnum::Select, ' (intersection)' do
|
58
|
+
include GecodeR::Specs::SetHelper
|
59
|
+
|
60
|
+
before do
|
61
|
+
@model = SelectionSampleProblem.new
|
62
|
+
@sets = @model.sets
|
63
|
+
@set = @model.set
|
64
|
+
@model.branch_on @set
|
65
|
+
|
66
|
+
@property_types = [:selected_set]
|
67
|
+
@select_property = lambda do |selected_set|
|
68
|
+
selected_set.intersection
|
69
|
+
end
|
70
|
+
@selected_property = @sets[@set].intersection
|
71
|
+
@constraint_class = Gecode::BlockConstraint
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should constrain the selected intersection of an enum of sets' do
|
75
|
+
@sets[@set].intersection.must_be.subset_of([5,7,9])
|
76
|
+
@sets[@set].intersection.must_be.superset_of([5])
|
77
|
+
@model.solve!
|
78
|
+
intersection = @set.value.inject(nil) do |intersection, i|
|
79
|
+
elements = @sets[i].value.to_a
|
80
|
+
next elements if intersection.nil?
|
81
|
+
intersection &= elements
|
82
|
+
end.uniq
|
83
|
+
intersection.should include(5)
|
84
|
+
(intersection - [5,7,9]).should be_empty
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should translate into a select intersection constraint' do
|
88
|
+
Gecode::Raw.should_receive(:selectInter)
|
89
|
+
@sets[@set].intersection.must_be.subset_of([5,7,9])
|
90
|
+
@model.solve!
|
91
|
+
end
|
92
|
+
|
93
|
+
it_should_behave_like(
|
94
|
+
'property that produces set operand by short circuiting equality')
|
95
|
+
end
|
96
|
+
|
97
|
+
describe Gecode::SelectedSet::Select, ' (intersection with universe)' do
|
98
|
+
include GecodeR::Specs::SetHelper
|
99
|
+
|
100
|
+
before do
|
101
|
+
@model = SelectionSampleProblem.new
|
102
|
+
@sets = @model.sets
|
103
|
+
@set = @model.set
|
104
|
+
@model.branch_on @set
|
105
|
+
@universe = [1,2]
|
106
|
+
|
107
|
+
@property_types = [:selected_set]
|
108
|
+
@select_property = lambda do |selected_set|
|
109
|
+
selected_set.intersection(:with => @universe)
|
110
|
+
end
|
111
|
+
@selected_property = @sets[@set].intersection(:with => @universe)
|
112
|
+
@constraint_class = Gecode::BlockConstraint
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should constrain the selected intersection of an enum of sets in a universe' do
|
116
|
+
@sets[@set].intersection(:with => @universe).must_be.subset_of([2])
|
117
|
+
@model.solve!
|
118
|
+
intersection = @set.value.inject(@universe) do |intersection, i|
|
119
|
+
intersection &= @sets[i].value.to_a
|
120
|
+
end.uniq
|
121
|
+
intersection.should include(2)
|
122
|
+
(intersection - [1,2]).should be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should allow the universe to be specified as a range' do
|
126
|
+
@sets[@set].intersection(:with => 1..2).must_be.subset_of([2])
|
127
|
+
@model.solve!
|
128
|
+
intersection = @set.value.inject(@universe) do |intersection, i|
|
129
|
+
intersection &= @sets[i].value.to_a
|
130
|
+
end.uniq
|
131
|
+
intersection.should include(2)
|
132
|
+
(intersection - [1,2]).should be_empty
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should translate into a select intersection constraint' do
|
136
|
+
Gecode::Raw.should_receive(:selectInterIn)
|
137
|
+
@sets[@set].intersection(:with => 1..2).must_be.subset_of([5,7,9])
|
138
|
+
@model.solve!
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should raise error if unknown options are specified' do
|
142
|
+
lambda do
|
143
|
+
@sets[@set].intersection(:does_not_exist => nil).must_be.subset_of([2])
|
144
|
+
end.should raise_error(ArgumentError)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should raise error if the universe is of the wrong type' do
|
148
|
+
lambda do
|
149
|
+
@sets[@set].intersection(:with => 'foo').must_be.subset_of([2])
|
150
|
+
end.should raise_error(TypeError)
|
151
|
+
end
|
152
|
+
|
153
|
+
it_should_behave_like(
|
154
|
+
'property that produces set operand by short circuiting equality')
|
155
|
+
end
|
156
|
+
|
157
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
describe Gecode::Set::Cardinality, ' (constraint)' do
|
4
|
+
before do
|
5
|
+
@model = Gecode::Model.new
|
6
|
+
@set = @model.set_var([], 0..10)
|
7
|
+
@model.branch_on @model.wrap_enum([@set])
|
8
|
+
@range = 1..2
|
9
|
+
@three_dot_range = 1...2
|
10
|
+
|
11
|
+
@invoke = lambda do |rhs|
|
12
|
+
@set.size.must_be.in(rhs)
|
13
|
+
@model.solve!
|
14
|
+
end
|
15
|
+
@expect = lambda do |rhs|
|
16
|
+
@model.allow_space_access do
|
17
|
+
Gecode::Raw.should_receive(:cardinality).once.with(
|
18
|
+
an_instance_of(Gecode::Raw::Space),
|
19
|
+
an_instance_of(Gecode::Raw::SetVar), rhs.first, rhs.last)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should translate cardinality constraints with ranges' do
|
25
|
+
@expect.call(@range)
|
26
|
+
@invoke.call(@range)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should translate cardinality constraints with three dot range domains' do
|
30
|
+
@expect.call(@three_dot_range)
|
31
|
+
@invoke.call(@three_dot_range)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should constrain the cardinality of a set' do
|
35
|
+
@set.size.must_be.in @range
|
36
|
+
@model.solve!
|
37
|
+
@range.should include(@set.value.size)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise error if the right hand side is not a range' do
|
41
|
+
lambda{ @set.size.must_be.in 'hello' }.should raise_error(TypeError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should not shadow the integer variable domain constrain' do
|
45
|
+
Gecode::Raw.should_receive(:dom).with(
|
46
|
+
an_instance_of(Gecode::Raw::Space),
|
47
|
+
an_instance_of(Gecode::Raw::IntVar), 0, 11, Gecode::Raw::ICL_DEF,
|
48
|
+
Gecode::Raw::PK_DEF)
|
49
|
+
Gecode::Raw.should_receive(:dom).with(
|
50
|
+
an_instance_of(Gecode::Raw::Space),
|
51
|
+
an_instance_of(Gecode::Raw::IntVar), an_instance_of(Gecode::Raw::IntSet),
|
52
|
+
an_instance_of(Gecode::Raw::BoolVar), Gecode::Raw::ICL_DEF,
|
53
|
+
Gecode::Raw::PK_DEF)
|
54
|
+
@set.size.must_not_be.in [1,3]
|
55
|
+
@model.solve!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
describe Gecode::Set::Cardinality, ' (property)' do
|
4
|
+
before do
|
5
|
+
@model = Gecode::Model.new
|
6
|
+
@set = @model.set_var([], 0..10)
|
7
|
+
@var = @model.int_var(0..11)
|
8
|
+
@model.branch_on @set
|
9
|
+
@model.branch_on @var
|
10
|
+
|
11
|
+
@property_types = [:set]
|
12
|
+
@select_property = lambda do |set|
|
13
|
+
set.size
|
14
|
+
end
|
15
|
+
@selected_property = @set.size
|
16
|
+
@constraint_class = Gecode::BlockConstraint
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should constrain the cardinality of a set' do
|
20
|
+
@set.size.must == @var
|
21
|
+
@model.solve!
|
22
|
+
@set.value.size.should == @var.value
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should constrain the cardinality of a set (2)' do
|
26
|
+
@set.size.must == 2
|
27
|
+
@model.solve!.should_not be_nil
|
28
|
+
@set.value.size.should == 2
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should constrain the cardinality of a set (3)' do
|
32
|
+
@set.size.must == @var
|
33
|
+
@var.must == 2
|
34
|
+
@model.solve!
|
35
|
+
@set.value.size.should == 2
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should translate into a cardinality constraint' do
|
39
|
+
Gecode::Raw.should_receive(:cardinality)
|
40
|
+
@set.size.must == @var
|
41
|
+
@model.solve!
|
42
|
+
end
|
43
|
+
|
44
|
+
it_should_behave_like(
|
45
|
+
'property that produces int operand by short circuiting equality')
|
46
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class SetChannelSampleProblem < Gecode::Model
|
4
|
+
attr :bool_enum
|
5
|
+
attr :set
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@bool_enum = bool_var_array(4)
|
9
|
+
@set = set_var([], 0..3)
|
10
|
+
|
11
|
+
branch_on @bool_enum
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Gecode::Set::Channel, ' (set variable as lhs with bool enum)' do
|
16
|
+
before do
|
17
|
+
@model = SetChannelSampleProblem.new
|
18
|
+
@bools = @model.bool_enum
|
19
|
+
@set = @model.set
|
20
|
+
|
21
|
+
@types = [:set, :bool_enum]
|
22
|
+
@invoke = lambda do |receiver, bool_enum, hash|
|
23
|
+
receiver.channel(bool_enum, hash)
|
24
|
+
@model.solve!
|
25
|
+
end
|
26
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
27
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
28
|
+
an_instance_of(Gecode::Raw::Space),
|
29
|
+
var1, var2)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should channel the bool enum with the set variable' do
|
34
|
+
@set.must_be.superset_of [0, 2]
|
35
|
+
@set.must.channel @bools
|
36
|
+
@model.solve!.should_not be_nil
|
37
|
+
set_values = @set.value
|
38
|
+
@bools.values.each_with_index do |bool, index|
|
39
|
+
bool.should == set_values.include?(index)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should_behave_like 'non-reifiable set constraint'
|
44
|
+
it_should_behave_like 'non-negatable constraint'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Gecode::Set::Channel, ' (bool enum as lhs with set variable)' do
|
48
|
+
before do
|
49
|
+
@model = SetChannelSampleProblem.new
|
50
|
+
@bools = @model.bool_enum
|
51
|
+
@set = @model.set
|
52
|
+
|
53
|
+
@types = [:bool_enum, :set]
|
54
|
+
@invoke = lambda do |receiver, set, hash|
|
55
|
+
receiver.channel(set, hash)
|
56
|
+
@model.solve!
|
57
|
+
end
|
58
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
59
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
60
|
+
an_instance_of(Gecode::Raw::Space),
|
61
|
+
var1, var2)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should channel the bool enum with the set variable' do
|
66
|
+
@set.must_be.superset_of [0, 2]
|
67
|
+
@bools.must.channel @set
|
68
|
+
@model.solve!.should_not be_nil
|
69
|
+
set_values = @set.value
|
70
|
+
@bools.values.each_with_index do |bool, index|
|
71
|
+
bool.should == set_values.include?(index)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it_should_behave_like 'non-reifiable set constraint'
|
76
|
+
it_should_behave_like 'non-negatable constraint'
|
77
|
+
end
|