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,117 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
Gecode::Util::SET_RELATION_TYPES.each_pair do |relation, type|
|
4
|
+
next if relation == :==
|
5
|
+
|
6
|
+
describe Gecode::Set::Relation, " (#{relation})" do
|
7
|
+
before do
|
8
|
+
@model = Gecode::Model.new
|
9
|
+
@set = @model.set_var([0], 0..3)
|
10
|
+
@set2 = @model.set_var([1], 0..3)
|
11
|
+
@model.branch_on @model.wrap_enum([@set, @set2])
|
12
|
+
|
13
|
+
@types = [:set, :set]
|
14
|
+
@invoke = lambda do |receiver, set_op, hash|
|
15
|
+
receiver.method(relation).call(set_op, hash)
|
16
|
+
@model.solve!
|
17
|
+
end
|
18
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
19
|
+
if reif_var.nil?
|
20
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
21
|
+
an_instance_of(Gecode::Raw::Space),
|
22
|
+
var1, type, var2)
|
23
|
+
else
|
24
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
25
|
+
an_instance_of(Gecode::Raw::Space),
|
26
|
+
var1, type, var2, reif_var)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should correctly constrain the set when #{relation} is used" do
|
32
|
+
@set = @model.set_var if relation == :complement
|
33
|
+
@set.must.method(relation).call(@set2)
|
34
|
+
@model.solve!
|
35
|
+
@set.should be_assigned
|
36
|
+
@set2.should be_assigned
|
37
|
+
case relation
|
38
|
+
when :superset
|
39
|
+
(@set2.value.to_a - @set.value.to_a).should be_empty
|
40
|
+
when :subset
|
41
|
+
(@set.value.to_a - @set2.value.to_a).should be_empty
|
42
|
+
when :complement
|
43
|
+
val = @set.value
|
44
|
+
val.min.should == Gecode::Model::SET_MIN_INT
|
45
|
+
val.max.should == Gecode::Model::SET_MAX_INT
|
46
|
+
@set2.value.each do |element|
|
47
|
+
@set.not_in_upper_bound?(element).should be_true
|
48
|
+
end
|
49
|
+
when :disjoint
|
50
|
+
(@set2.value.to_a & @set.value.to_a).should be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should correctly constrain the set when negated #{relation} is used" do
|
55
|
+
@set.must_not.method(relation).call(@set2)
|
56
|
+
@model.solve!
|
57
|
+
@set.should be_assigned
|
58
|
+
@set2.should be_assigned
|
59
|
+
case relation
|
60
|
+
when :superset
|
61
|
+
(@set2.value.to_a - @set.value.to_a).should_not be_empty
|
62
|
+
when :subset
|
63
|
+
(@set.value.to_a - @set2.value.to_a).should_not be_empty
|
64
|
+
when :complement
|
65
|
+
val = @set.value
|
66
|
+
((val.min != Gecode::Model::SET_MIN_INT) ||
|
67
|
+
(val.max != Gecode::Model::SET_MAX_INT) ||
|
68
|
+
@set.value.to_a.any?{ |element| @set.in_lower_bound?(element) }
|
69
|
+
).should be_true
|
70
|
+
when :disjoint
|
71
|
+
(@set.value.to_a & @set.value.to_a).should_not be_empty
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it_should_behave_like 'reifiable set constraint'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe Gecode::Set::Relation, ' (equality)' do
|
80
|
+
before do
|
81
|
+
@model = Gecode::Model.new
|
82
|
+
@set = @model.set_var([0], 0..1)
|
83
|
+
@set2 = @model.set_var([1], 0..1)
|
84
|
+
@model.branch_on @model.wrap_enum([@set, @set2])
|
85
|
+
|
86
|
+
@types = [:set, :set]
|
87
|
+
@invoke = lambda do |receiver, set_op, hash|
|
88
|
+
receiver.equal(set_op, hash)
|
89
|
+
@model.solve!
|
90
|
+
end
|
91
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
92
|
+
if reif_var.nil?
|
93
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
94
|
+
an_instance_of(Gecode::Raw::Space),
|
95
|
+
var1, Gecode::Raw::SRT_EQ, var2)
|
96
|
+
else
|
97
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
98
|
+
an_instance_of(Gecode::Raw::Space),
|
99
|
+
var1, Gecode::Raw::SRT_EQ, var2, reif_var)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should constrain sets to be equal' do
|
105
|
+
@set.must == @set2
|
106
|
+
@model.solve!
|
107
|
+
@set.value.to_a.should == @set2.value.to_a
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should constrain sets to not be equal when negated' do
|
111
|
+
@set.must_not == @set2
|
112
|
+
@model.solve!
|
113
|
+
@set.value.to_a.should_not == @set2.value.to_a
|
114
|
+
end
|
115
|
+
|
116
|
+
it_should_behave_like 'reifiable set constraint'
|
117
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
|
4
|
+
describe Gecode::SetElements::Relation, " (#{relation} with int op)" do
|
5
|
+
before do
|
6
|
+
@model = Gecode::Model.new
|
7
|
+
@set = @model.set_var([0], 0..2)
|
8
|
+
@int = @model.int_var(-1..2)
|
9
|
+
@model.branch_on @set
|
10
|
+
@model.branch_on @int
|
11
|
+
|
12
|
+
# For constraint spec.
|
13
|
+
@types = [:set_elements, :int]
|
14
|
+
@invoke = lambda do |receiver, op, hash|
|
15
|
+
receiver.method(relation).call(op, hash)
|
16
|
+
@model.solve!
|
17
|
+
end
|
18
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
19
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
20
|
+
an_instance_of(Gecode::Raw::Space),
|
21
|
+
var1, rel_value, var2)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should constrain the elements of the set when #{relation} is used" do
|
26
|
+
@set.elements.must.method(relation).call(@int)
|
27
|
+
@model.solve!
|
28
|
+
@set.value.each do |i|
|
29
|
+
i.should.method(relation).call(@int.value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should constrain the elements of the set when negated #{relation} is used" do
|
34
|
+
@set.elements.must_not.method(relation).call(@int)
|
35
|
+
@model.solve!
|
36
|
+
@set.value.each do |i|
|
37
|
+
i.should_not.method(relation).call(@int.value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it_should_behave_like 'non-reifiable set constraint'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
|
46
|
+
describe Gecode::SetElements::Relation, " (#{relation} with fixnum)" do
|
47
|
+
before do
|
48
|
+
@model = Gecode::Model.new
|
49
|
+
@set = @model.set_var([], 0..2)
|
50
|
+
@int_constant = 1
|
51
|
+
@model.branch_on @set
|
52
|
+
|
53
|
+
# For constraint spec.
|
54
|
+
@types = [:set_elements]
|
55
|
+
@invoke = lambda do |receiver, hash|
|
56
|
+
receiver.method(relation).call(@int_constant, hash)
|
57
|
+
@model.solve!
|
58
|
+
end
|
59
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
60
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
61
|
+
an_instance_of(Gecode::Raw::Space),
|
62
|
+
var1, rel_value, an_instance_of(Gecode::Raw::IntVar))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should constrain the elements of the set when #{relation} is used" do
|
67
|
+
@set.elements.must.method(relation).call(@int_constant)
|
68
|
+
@model.solve!
|
69
|
+
@set.value.each do |i|
|
70
|
+
i.should.method(relation).call(@int_constant)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should constrain the elements of the set when negated #{relation} is used" do
|
75
|
+
@set.elements.must_not.method(relation).call(@int_constant)
|
76
|
+
@model.solve!
|
77
|
+
@set.value.each do |i|
|
78
|
+
i.should_not.method(relation).call(@int_constant)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it_should_behave_like 'non-reifiable set constraint'
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class ChannelSampleProblem < Gecode::Model
|
4
|
+
attr :elements
|
5
|
+
attr :positions
|
6
|
+
attr :sets
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@elements = int_var_array(4, 0..3)
|
10
|
+
@elements.must_be.distinct
|
11
|
+
@positions = int_var_array(4, 0..3)
|
12
|
+
@positions.must_be.distinct
|
13
|
+
@sets = set_var_array(4, [], 0..3)
|
14
|
+
branch_on @positions
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Gecode::SetEnum::Channel::IntEnumChannelConstraint, ' (channel with set as right hand side)' do
|
19
|
+
before do
|
20
|
+
@model = ChannelSampleProblem.new
|
21
|
+
@positions = @model.positions
|
22
|
+
@sets = @model.sets
|
23
|
+
|
24
|
+
@types = [:int_enum, :set_enum]
|
25
|
+
@invoke = lambda do |receiver, set_enum, hash|
|
26
|
+
receiver.channel(set_enum, hash)
|
27
|
+
@model.solve!
|
28
|
+
end
|
29
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
30
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
31
|
+
an_instance_of(Gecode::Raw::Space),
|
32
|
+
var1, var2)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should constrain variables to be channelled' do
|
37
|
+
@positions.must.channel @sets
|
38
|
+
@model.solve!
|
39
|
+
sets = @model.sets
|
40
|
+
positions = @model.positions.values
|
41
|
+
positions.each_with_index do |position, i|
|
42
|
+
sets[position].value.should include(i)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it_should_behave_like 'non-reifiable set constraint'
|
47
|
+
it_should_behave_like 'non-negatable constraint'
|
48
|
+
end
|
49
|
+
|
50
|
+
describe Gecode::SetEnum::Channel::IntEnumChannelConstraint, ' (channel with set as left hand side)' do
|
51
|
+
before do
|
52
|
+
@model = ChannelSampleProblem.new
|
53
|
+
@positions = @model.positions
|
54
|
+
@sets = @model.sets
|
55
|
+
|
56
|
+
@types = [:set_enum, :int_enum]
|
57
|
+
@invoke = lambda do |receiver, int_enum, hash|
|
58
|
+
receiver.channel(int_enum, hash)
|
59
|
+
@model.solve!
|
60
|
+
end
|
61
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
62
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
63
|
+
an_instance_of(Gecode::Raw::Space),
|
64
|
+
var2, var1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should constrain variables to be channelled' do
|
69
|
+
@sets.must.channel @positions
|
70
|
+
@model.solve!
|
71
|
+
sets = @model.sets
|
72
|
+
positions = @model.positions.values
|
73
|
+
positions.each_with_index do |position, i|
|
74
|
+
sets[position].value.should include(i)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it_should_behave_like 'non-reifiable set constraint'
|
79
|
+
it_should_behave_like 'non-negatable constraint'
|
80
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class SetEnumDistinctSampleProblem < Gecode::Model
|
4
|
+
attr :vars
|
5
|
+
attr :sets
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@vars = int_var_array(2, 1)
|
9
|
+
@sets = set_var_array(2, [], 0..2)
|
10
|
+
branch_on @sets
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Gecode::SetEnum::Distinct, ' (at most one)' do
|
15
|
+
before do
|
16
|
+
@model = SetEnumDistinctSampleProblem.new
|
17
|
+
@sets = @model.sets
|
18
|
+
@size = 2
|
19
|
+
|
20
|
+
@types = [:set_enum]
|
21
|
+
@invoke = lambda do |receiver, hash|
|
22
|
+
receiver.at_most_share_one_element hash.update(:size => @size)
|
23
|
+
@model.solve!
|
24
|
+
end
|
25
|
+
@expect = lambda do |var, opts, reif_var|
|
26
|
+
Gecode::Raw.should_receive(:atmostOne).once.with(
|
27
|
+
an_instance_of(Gecode::Raw::Space),
|
28
|
+
var, @size)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should translate into a atmostOne constraint' do
|
33
|
+
Gecode::Raw.should_receive(:atmostOne).once.with(
|
34
|
+
an_instance_of(Gecode::Raw::Space),
|
35
|
+
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
36
|
+
@sets.must.at_most_share_one_element(:size => @size)
|
37
|
+
@model.solve!
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should constrain sets to have at most one element in common' do
|
41
|
+
@sets.must.at_most_share_one_element(:size => @size)
|
42
|
+
@sets[0].must_not_be.superset_of 0
|
43
|
+
solution = @model.solve!
|
44
|
+
solution.should_not be_nil
|
45
|
+
set1, set2 = solution.sets
|
46
|
+
set1.value.size.should == @size
|
47
|
+
set2.value.size.should == @size
|
48
|
+
(set1.value.to_a & set2.value.to_a).size.should <= 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should raise error if :size is not specified' do
|
52
|
+
lambda do
|
53
|
+
@sets.must.at_most_share_one_element
|
54
|
+
end.should raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
|
57
|
+
it_should_behave_like 'non-reifiable set constraint'
|
58
|
+
it_should_behave_like 'non-negatable constraint'
|
59
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
# Assumes that @operation, @set and @set_enum are defined.
|
4
|
+
describe 'set enum operation property', :shared => true do
|
5
|
+
before do
|
6
|
+
@property_types = [:set_enum]
|
7
|
+
@select_property = lambda do |set_enum|
|
8
|
+
set_enum.method(@operation).call
|
9
|
+
end
|
10
|
+
@selected_property = @set_enum.method(@operation).call
|
11
|
+
|
12
|
+
@constraint_class = Gecode::BlockConstraint
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should translate #{@operation} into an operand constraint" do
|
16
|
+
operation_type = Gecode::Util::SET_OPERATION_TYPES[@operation]
|
17
|
+
@model.allow_space_access do
|
18
|
+
Gecode::Raw.should_receive(:rel).with(
|
19
|
+
an_instance_of(Gecode::Raw::Space), operation_type,
|
20
|
+
@set_enum.bind_array, @set.bind)
|
21
|
+
end
|
22
|
+
@set_enum.method(@operation).call.must == @set
|
23
|
+
@model.solve!
|
24
|
+
end
|
25
|
+
|
26
|
+
it_should_behave_like(
|
27
|
+
'property that produces set operand by short circuiting equality')
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Gecode::SetEnum::Operation, ' (union)' do
|
31
|
+
before do
|
32
|
+
@model = Gecode::Model.new
|
33
|
+
@set_enum = @sets = @model.set_var_array(10, [], 0..20)
|
34
|
+
@set = @model.set_var([], 0..20)
|
35
|
+
@model.branch_on @sets
|
36
|
+
|
37
|
+
@operation = :union
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should constrain the union of the sets' do
|
41
|
+
@sets.union.must_be.subset_of [1,4,17]
|
42
|
+
@sets.union.must_be.superset_of 1
|
43
|
+
@model.solve!.should_not be_nil
|
44
|
+
union = @sets.values.inject([]){ |union, set| union += set.to_a }.uniq
|
45
|
+
union.should include(1)
|
46
|
+
(union - [1,4,17]).should be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it_should_behave_like 'set enum operation property'
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Gecode::SetEnum::Operation, ' (intersection)' do
|
53
|
+
before do
|
54
|
+
@model = Gecode::Model.new
|
55
|
+
@set_enum = @sets = @model.set_var_array(10, [], 0..20)
|
56
|
+
@set = @model.set_var([], 0..20)
|
57
|
+
@model.branch_on @sets
|
58
|
+
|
59
|
+
@operation = :intersection
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should constrain the intersection of the sets' do
|
63
|
+
@sets.intersection.must_be.subset_of [1,4,17]
|
64
|
+
@sets.intersection.must_be.superset_of [1]
|
65
|
+
@model.solve!.should_not be_nil
|
66
|
+
intersection = @sets.values.inject(nil) do |intersection, set|
|
67
|
+
next set.to_a if intersection.nil?
|
68
|
+
intersection &= set.to_a
|
69
|
+
end.uniq
|
70
|
+
intersection.should include(1)
|
71
|
+
(intersection - [1,4,17]).should be_empty
|
72
|
+
end
|
73
|
+
|
74
|
+
it_should_behave_like 'set enum operation property'
|
75
|
+
end
|
76
|
+
|
77
|
+
describe Gecode::SetEnum::Operation, ' (disjoint union)' do
|
78
|
+
before do
|
79
|
+
@model = Gecode::Model.new
|
80
|
+
@set_enum = @sets = @model.set_var_array(10, [], 0..20)
|
81
|
+
@set = @model.set_var([], 0..20)
|
82
|
+
@model.branch_on @sets
|
83
|
+
|
84
|
+
@operation = :disjoint_union
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should constrain the disjoint union of the sets' do
|
88
|
+
@sets.disjoint_union.must_be.subset_of [1,4,17]
|
89
|
+
@sets.disjoint_union.must_be.superset_of [1]
|
90
|
+
@model.solve!.should_not be_nil
|
91
|
+
disjoint_union = @sets.values.inject([]) do |union, set|
|
92
|
+
unless union.any?{ |x| set.to_a.include? x }
|
93
|
+
union += set.to_a
|
94
|
+
end
|
95
|
+
end.uniq
|
96
|
+
disjoint_union.should include(1)
|
97
|
+
(disjoint_union - [1,4,17]).should be_empty
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should constrain the disjoint union of the sets (2)' do
|
101
|
+
@sets.disjoint_union.must_be.subset_of [1,4,17]
|
102
|
+
@sets.disjoint_union.must_be.superset_of [1]
|
103
|
+
@sets[0].must_be.superset_of [1]
|
104
|
+
@sets[1].must_be.superset_of [1]
|
105
|
+
lambda do
|
106
|
+
@model.solve!
|
107
|
+
end.should raise_error(Gecode::NoSolutionError)
|
108
|
+
end
|
109
|
+
|
110
|
+
it_should_behave_like 'set enum operation property'
|
111
|
+
end
|