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,103 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe 'constraint receiver', :shared => true do
|
4
|
+
it 'should raise error unless an operand of the correct type is given as lhs' do
|
5
|
+
lambda do
|
6
|
+
op = Object.new
|
7
|
+
class <<op
|
8
|
+
include Gecode::Operand
|
9
|
+
end
|
10
|
+
@receiver.new(@model, {:lhs => op, :negate => false})
|
11
|
+
end.should raise_error(TypeError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Gecode::ConstraintReceiver do
|
16
|
+
before do
|
17
|
+
@model = Gecode::Model.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise error if the negate params is not given' do
|
21
|
+
lambda do
|
22
|
+
Gecode::ConstraintReceiver.new(@model, {:lhs => nil})
|
23
|
+
end.should raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise error if the lhs params is not given' do
|
27
|
+
lambda do
|
28
|
+
Gecode::ConstraintReceiver.new(@model, {:lhs => nil})
|
29
|
+
end.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Gecode::Int::IntConstraintReceiver, ' (not subclassed)' do
|
34
|
+
before do
|
35
|
+
@model = Gecode::Model.new
|
36
|
+
@receiver = Gecode::Int::IntConstraintReceiver
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_behave_like 'constraint receiver'
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Gecode::IntEnum::IntEnumConstraintReceiver do
|
43
|
+
before do
|
44
|
+
@model = Gecode::Model.new
|
45
|
+
@receiver = Gecode::IntEnum::IntEnumConstraintReceiver
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like 'constraint receiver'
|
49
|
+
end
|
50
|
+
|
51
|
+
describe Gecode::Bool::BoolConstraintReceiver do
|
52
|
+
before do
|
53
|
+
@model = Gecode::Model.new
|
54
|
+
@receiver = Gecode::Bool::BoolConstraintReceiver
|
55
|
+
end
|
56
|
+
|
57
|
+
it_should_behave_like 'constraint receiver'
|
58
|
+
end
|
59
|
+
|
60
|
+
describe Gecode::BoolEnum::BoolEnumConstraintReceiver do
|
61
|
+
before do
|
62
|
+
@model = Gecode::Model.new
|
63
|
+
@receiver = Gecode::BoolEnum::BoolEnumConstraintReceiver
|
64
|
+
end
|
65
|
+
|
66
|
+
it_should_behave_like 'constraint receiver'
|
67
|
+
end
|
68
|
+
|
69
|
+
describe Gecode::Set::SetConstraintReceiver do
|
70
|
+
before do
|
71
|
+
@model = Gecode::Model.new
|
72
|
+
@receiver = Gecode::Set::SetConstraintReceiver
|
73
|
+
end
|
74
|
+
|
75
|
+
it_should_behave_like 'constraint receiver'
|
76
|
+
end
|
77
|
+
|
78
|
+
describe Gecode::SelectedSet::SelectedSetConstraintReceiver do
|
79
|
+
before do
|
80
|
+
@model = Gecode::Model.new
|
81
|
+
@receiver = Gecode::SelectedSet::SelectedSetConstraintReceiver
|
82
|
+
end
|
83
|
+
|
84
|
+
it_should_behave_like 'constraint receiver'
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Gecode::SetElements::SetElementsConstraintReceiver do
|
88
|
+
before do
|
89
|
+
@model = Gecode::Model.new
|
90
|
+
@receiver = Gecode::SetElements::SetElementsConstraintReceiver
|
91
|
+
end
|
92
|
+
|
93
|
+
it_should_behave_like 'constraint receiver'
|
94
|
+
end
|
95
|
+
|
96
|
+
describe Gecode::SetEnum::SetEnumConstraintReceiver do
|
97
|
+
before do
|
98
|
+
@model = Gecode::Model.new
|
99
|
+
@receiver = Gecode::SetEnum::SetEnumConstraintReceiver
|
100
|
+
end
|
101
|
+
|
102
|
+
it_should_behave_like 'constraint receiver'
|
103
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Gecode::Constraint, ' (not subclassed)' do
|
4
|
+
before do
|
5
|
+
@con = Gecode::Constraint.new(Gecode::Model.new, {})
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should raise error when calling #post because it\'s not overridden' do
|
9
|
+
lambda{ @con.post }.should raise_error(NotImplementedError)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Gecode::Util do
|
14
|
+
it 'should raise error when giving incorrect set to #constant_set_to_params' do
|
15
|
+
lambda do
|
16
|
+
Gecode::Util.constant_set_to_params('hello')
|
17
|
+
end.should raise_error(TypeError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise error when giving incorrect set to #constant_set_to_int_set' do
|
21
|
+
lambda do
|
22
|
+
Gecode::Util.constant_set_to_int_set('hello')
|
23
|
+
end.should raise_error(TypeError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
class FixnumElementSampleProblem < Gecode::Model
|
4
|
+
attr :prices
|
5
|
+
attr :store
|
6
|
+
attr :price
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
prices = [17, 63, 45, 63]
|
10
|
+
@prices = wrap_enum(prices)
|
11
|
+
@store = int_var(0...prices.size)
|
12
|
+
@price = int_var(prices)
|
13
|
+
branch_on @store
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Gecode::FixnumEnum::Element do
|
18
|
+
before do
|
19
|
+
@model = FixnumElementSampleProblem.new
|
20
|
+
@price = @model.price
|
21
|
+
@store = @model.store
|
22
|
+
@enum = @model.prices
|
23
|
+
|
24
|
+
# For int operand producing property spec.
|
25
|
+
@property_types = [:fixnum_enum, :int]
|
26
|
+
@select_property = lambda do |fixnum_enum, int|
|
27
|
+
fixnum_enum[int]
|
28
|
+
end
|
29
|
+
@selected_property = @enum[@store]
|
30
|
+
@constraint_class = Gecode::BlockConstraint
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should not disturb normal array access' do
|
34
|
+
@enum[2].should_not be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should constrain the selected element' do
|
38
|
+
@enum[@store].must == @enum[2]
|
39
|
+
@model.solve!.should_not be_nil
|
40
|
+
@store.value.should equal(2)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be translated into an element constraint' do
|
44
|
+
@enum[@store].must == @price
|
45
|
+
@model.allow_space_access do
|
46
|
+
Gecode::Raw.should_receive(:element).once.with(
|
47
|
+
an_instance_of(Gecode::Raw::Space),
|
48
|
+
an_instance_of(Array),
|
49
|
+
@store.bind, @price.bind,
|
50
|
+
Gecode::Raw::ICL_DEF,
|
51
|
+
Gecode::Raw::PK_DEF)
|
52
|
+
end
|
53
|
+
@model.solve!
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like(
|
57
|
+
'property that produces int operand by short circuiting equality')
|
58
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
Gecode::Util::SET_OPERATION_TYPES.each_pair do |operation, type|
|
4
|
+
describe Gecode::FixnumEnum::Operation, " (#{operation} with set variable)" do
|
5
|
+
before do
|
6
|
+
@model = Gecode::Model.new
|
7
|
+
@constant_lhs = @model.wrap_enum [0, 4, 7]
|
8
|
+
@set = @model.set_var([1], 0..20)
|
9
|
+
@constant_set = [2, 3, 5]
|
10
|
+
@rhs = @model.set_var([], 0..20)
|
11
|
+
@model.branch_on @model.wrap_enum([@set, @rhs])
|
12
|
+
|
13
|
+
@property_types = [:fixnum_enum, :set]
|
14
|
+
@select_property = lambda do |fixnum_enum, set|
|
15
|
+
fixnum_enum.method(operation).call(set)
|
16
|
+
end
|
17
|
+
@selected_property = @constant_lhs.method(operation).call(@set)
|
18
|
+
@constraint_class =
|
19
|
+
Gecode::Set::Operation::OperationConstraint
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should translate #{operation} into an operation constraint" do
|
23
|
+
@model.allow_space_access do
|
24
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
25
|
+
an_instance_of(Gecode::Raw::Space),
|
26
|
+
an_instance_of(Gecode::Raw::IntSet), type, @set.bind,
|
27
|
+
Gecode::Raw::SRT_EQ, @rhs.bind)
|
28
|
+
end
|
29
|
+
@constant_lhs.method(operation).call(@set).must == @rhs
|
30
|
+
@model.solve!
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should constrain the #{operation} of the sets with variable rhs" do
|
34
|
+
@constant_lhs.method(operation).call(@set).must == @rhs
|
35
|
+
@model.solve!
|
36
|
+
|
37
|
+
s1 = @constant_lhs
|
38
|
+
s2 = @set.value.to_a
|
39
|
+
rhs = @rhs.value.to_a
|
40
|
+
case operation
|
41
|
+
when :union
|
42
|
+
(s1 | s2).sort.should == rhs.sort
|
43
|
+
when :disjoint_union
|
44
|
+
(s1 | s2 - (s1 & s2)).sort.should == rhs.sort
|
45
|
+
when :intersection
|
46
|
+
(s1 & s2).should == rhs
|
47
|
+
when :minus
|
48
|
+
(s1 - s2).should == rhs
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not allow constant sets to be given as argument' do
|
53
|
+
lambda do
|
54
|
+
@constant_lhs.method(operation).call(@constant_set).must == @rhs
|
55
|
+
end.should raise_error(TypeError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not allow all three parameters to be constant sets' do
|
59
|
+
lambda do
|
60
|
+
@constant_lhs.method(operation).call(@constant_set).must == [0]
|
61
|
+
end.should raise_error(TypeError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like(
|
65
|
+
'property that produces set operand by short circuiting set relations')
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
class ArithmeticSampleProblem < Gecode::Model
|
4
|
+
attr :var
|
5
|
+
attr :var2
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@var = int_var(-9..9)
|
9
|
+
@var2 = int_var(0..9)
|
10
|
+
branch_on wrap_enum([@var, @var2])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Gecode::Int::Arithmetic, ' (abs)' do
|
15
|
+
before do
|
16
|
+
@model = ArithmeticSampleProblem.new
|
17
|
+
@var = @model.var
|
18
|
+
|
19
|
+
@property_types = [:int]
|
20
|
+
@select_property = lambda do |int|
|
21
|
+
int.abs
|
22
|
+
end
|
23
|
+
@selected_property = @var.abs
|
24
|
+
@constraint_class = Gecode::BlockConstraint
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should constrain the absolute value' do
|
28
|
+
@var.must < 0
|
29
|
+
@var.abs.must == 5
|
30
|
+
@model.solve!.var.value.should == -5
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should translate into an abs constraint' do
|
34
|
+
Gecode::Raw.should_receive(:abs)
|
35
|
+
@var.abs.must == 5
|
36
|
+
@model.solve!
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_behave_like(
|
40
|
+
'property that produces int operand by short circuiting equality')
|
41
|
+
end
|
42
|
+
|
43
|
+
describe Gecode::Int::Arithmetic, ' (multiplication)' do
|
44
|
+
before do
|
45
|
+
@model = ArithmeticSampleProblem.new
|
46
|
+
@var = @model.var
|
47
|
+
@var2 = @model.var2
|
48
|
+
|
49
|
+
@property_types = [:int, :int]
|
50
|
+
@select_property = lambda do |int1, int2|
|
51
|
+
int1 * int2
|
52
|
+
end
|
53
|
+
@selected_property = @var * @var2
|
54
|
+
@constraint_class = Gecode::BlockConstraint
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should constrain the value of the multiplication' do
|
58
|
+
(@var * @var2).must == 56
|
59
|
+
sol = @model.solve!
|
60
|
+
[sol.var.value, sol.var2.value].sort.should == [7, 8]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should translate into a mult constraint' do
|
64
|
+
Gecode::Raw.should_receive(:mult)
|
65
|
+
(@var * @var2).must == 56
|
66
|
+
@model.solve!
|
67
|
+
end
|
68
|
+
|
69
|
+
it_should_behave_like(
|
70
|
+
'property that produces int operand by short circuiting equality')
|
71
|
+
end
|
72
|
+
|
73
|
+
describe Gecode::Int::Arithmetic, ' (squared)' do
|
74
|
+
before do
|
75
|
+
@model = ArithmeticSampleProblem.new
|
76
|
+
@var = @model.var
|
77
|
+
|
78
|
+
@property_types = [:int]
|
79
|
+
@select_property = lambda do |int|
|
80
|
+
int.squared
|
81
|
+
end
|
82
|
+
@selected_property = @var.squared
|
83
|
+
@constraint_class = Gecode::BlockConstraint
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should constrain the value of the variable squared' do
|
87
|
+
@var.squared.must == 9
|
88
|
+
sol = @model.solve!
|
89
|
+
sol.var.value.abs.should == 3
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should translate into a squared constraint' do
|
93
|
+
Gecode::Raw.should_receive(:sqr)
|
94
|
+
@var.squared.must == 4
|
95
|
+
@model.solve!
|
96
|
+
end
|
97
|
+
|
98
|
+
it_should_behave_like(
|
99
|
+
'property that produces int operand by short circuiting equality')
|
100
|
+
end
|
101
|
+
|
102
|
+
describe Gecode::Int::Arithmetic, ' (square root)' do
|
103
|
+
before do
|
104
|
+
@model = ArithmeticSampleProblem.new
|
105
|
+
@var = @model.var
|
106
|
+
|
107
|
+
@property_types = [:int]
|
108
|
+
@select_property = lambda do |int|
|
109
|
+
int.sqrt
|
110
|
+
end
|
111
|
+
@selected_property = @var.sqrt
|
112
|
+
@constraint_class = Gecode::BlockConstraint
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should constrain the square root of the variable' do
|
116
|
+
@var.square_root.must == 3
|
117
|
+
sol = @model.solve!
|
118
|
+
Math.sqrt(sol.var.value).floor.should == 3
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should constrain the square root of the variable (2)' do
|
122
|
+
@var.square_root.must == 0
|
123
|
+
sol = @model.solve!
|
124
|
+
Math.sqrt(sol.var.value).floor.should == 0
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should constrain the square root of the variable (3)' do
|
128
|
+
@var.must < 0
|
129
|
+
@var.square_root.must == 0
|
130
|
+
lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should round down the square root' do
|
134
|
+
@var.must > 4
|
135
|
+
@var.square_root.must == 2
|
136
|
+
sol = @model.solve!
|
137
|
+
sol.var.value.should be_between(5,8)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should translate into a square root constraint' do
|
141
|
+
Gecode::Raw.should_receive(:sqrt)
|
142
|
+
@var.sqrt.must == 2
|
143
|
+
@model.solve!
|
144
|
+
end
|
145
|
+
|
146
|
+
it_should_behave_like(
|
147
|
+
'property that produces int operand by short circuiting equality')
|
148
|
+
end
|
149
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class BoolChannelSampleProblem < Gecode::Model
|
4
|
+
attr :bool_enum
|
5
|
+
attr :bool
|
6
|
+
attr :int
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@bool_enum = bool_var_array(4)
|
10
|
+
@int = int_var(0..3)
|
11
|
+
@bool = bool_var
|
12
|
+
|
13
|
+
branch_on @int
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Gecode::Int::Channel, ' (one int and one bool variable)' do
|
18
|
+
before do
|
19
|
+
@model = BoolChannelSampleProblem.new
|
20
|
+
@bool = @model.bool_var
|
21
|
+
@int = @model.int_var
|
22
|
+
|
23
|
+
@types = [:int, :bool]
|
24
|
+
@invoke = lambda do |receiver, bool, hash|
|
25
|
+
receiver.equal(bool, hash)
|
26
|
+
@model.solve!
|
27
|
+
end
|
28
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
29
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
30
|
+
an_instance_of(Gecode::Raw::Space),
|
31
|
+
var1, var2, *opts)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should not shadow linear boolean constraints' do
|
36
|
+
lambda do
|
37
|
+
(@bool + @bool).must == @bool
|
38
|
+
@model.solve!
|
39
|
+
end.should_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should constrain the int variable to be 1 when the boolean variable is true' do
|
43
|
+
@bool.must_be.true
|
44
|
+
@int.must == @bool
|
45
|
+
@model.solve!
|
46
|
+
@int.value.should == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should constrain the int variable to be 0 when the boolean variable is false' do
|
50
|
+
@bool.must_be.false
|
51
|
+
@int.must == @bool
|
52
|
+
@model.solve!
|
53
|
+
@int.value.should == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like 'non-reifiable constraint'
|
57
|
+
it_should_behave_like 'non-negatable constraint'
|
58
|
+
end
|
59
|
+
|
60
|
+
describe Gecode::Int::Channel, ' (one bool and one int variable)' do
|
61
|
+
before do
|
62
|
+
@model = BoolChannelSampleProblem.new
|
63
|
+
@bool = @model.bool_var
|
64
|
+
@int = @model.int_var
|
65
|
+
|
66
|
+
@types = [:bool, :int]
|
67
|
+
@invoke = lambda do |receiver, int, hash|
|
68
|
+
receiver.equal(int, hash)
|
69
|
+
@model.solve!
|
70
|
+
end
|
71
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
72
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
73
|
+
an_instance_of(Gecode::Raw::Space),
|
74
|
+
var2, var1, *opts)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not shadow linear boolean constraints' do
|
79
|
+
lambda do
|
80
|
+
@bool.must == @bool + @bool
|
81
|
+
@model.solve!
|
82
|
+
end.should_not raise_error
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should constrain the int variable to be 1 when the boolean variable is true' do
|
86
|
+
@bool.must_be.true
|
87
|
+
@bool.must == @int
|
88
|
+
@model.solve!
|
89
|
+
@int.value.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should constrain the int variable to be 0 when the boolean variable is false' do
|
93
|
+
@bool.must_be.false
|
94
|
+
@bool.must == @int
|
95
|
+
@model.solve!
|
96
|
+
@int.value.should == 0
|
97
|
+
end
|
98
|
+
|
99
|
+
it_should_behave_like 'non-reifiable constraint'
|
100
|
+
it_should_behave_like 'non-negatable constraint'
|
101
|
+
end
|