gecoder-with-gecode 0.9.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- 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,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Gecode::SelectedSet::SelectedSetOperand do
|
4
|
+
before do
|
5
|
+
@model = Gecode::Model.new
|
6
|
+
set_enum = @model.set_var_array(5, [], 0..9)
|
7
|
+
set = @model.set_var([], 0..4)
|
8
|
+
@operand = Gecode::SelectedSet::SelectedSetOperand.new(
|
9
|
+
set_enum, set)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should implement #model' do
|
13
|
+
@operand.model.should be_kind_of(Gecode::Model)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should implement #to_selected_set' do
|
17
|
+
enum, set = @operand.to_selected_set
|
18
|
+
enum.should be_respond_to(:to_set_enum)
|
19
|
+
set.should be_respond_to(:to_set_var)
|
20
|
+
@model.solve!
|
21
|
+
set_var = set.to_set_var
|
22
|
+
((set_var.lower_bound == []) &&
|
23
|
+
(set_var.upper_bound == Gecode::Model::LARGEST_SET_BOUND)).should_not(
|
24
|
+
be_true)
|
25
|
+
enum.each do |element|
|
26
|
+
set_var = element.to_set_var
|
27
|
+
((set_var.lower_bound == []) &&
|
28
|
+
(set_var.upper_bound == Gecode::Model::LARGEST_SET_BOUND)).should_not(
|
29
|
+
be_true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should implement #must' do
|
34
|
+
receiver = @operand.must
|
35
|
+
receiver.should be_kind_of(
|
36
|
+
Gecode::SelectedSet::SelectedSetConstraintReceiver)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Gecode::SelectedSet::SelectedSetOperand do
|
4
|
+
before do
|
5
|
+
@model = Gecode::Model.new
|
6
|
+
@set = @model.set_var([], 0..4)
|
7
|
+
@operand = Gecode::SetElements::SetElementsOperand.new(@set)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should implement #model' do
|
11
|
+
@operand.model.should be_kind_of(Gecode::Model)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should implement #to_set_elements' do
|
15
|
+
set = @operand.to_set_elements
|
16
|
+
set.should be_respond_to(:to_set_var)
|
17
|
+
@model.solve!
|
18
|
+
set_var = set.to_set_var
|
19
|
+
((set_var.lower_bound == []) &&
|
20
|
+
(set_var.upper_bound == Gecode::Model::LARGEST_SET_BOUND)).should_not(
|
21
|
+
be_true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should implement #must' do
|
25
|
+
receiver = @operand.must
|
26
|
+
receiver.should be_kind_of(
|
27
|
+
Gecode::SetElements::SetElementsConstraintReceiver)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should be produces by SetOperand#elements' do
|
31
|
+
@set.elements.should be_respond_to(:to_set_elements)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/specs/set_var.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/constraints/property_helper'
|
2
|
+
|
3
|
+
describe Gecode::SetVar, '(not assigned)' do
|
4
|
+
before do
|
5
|
+
@model = Gecode::Model.new
|
6
|
+
@operand = @var = @model.set_var(1..3, 0..4)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should not be assigned' do
|
10
|
+
@var.should_not be_assigned
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should give glb and lub ranges when inspecting' do
|
14
|
+
@var.inspect.should include('lub-range')
|
15
|
+
@var.inspect.should include('glb-range')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should allow inspection even when the bounds are too large to display' do
|
19
|
+
var = @model.set_var
|
20
|
+
var.inspect.should include('too large')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should report the correct bounds' do
|
24
|
+
@var.lower_bound.sort.to_a.should == (1..3).to_a
|
25
|
+
@var.upper_bound.sort.to_a.should == (0..4).to_a
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should report correct bounds on upper bound' do
|
29
|
+
@var.upper_bound.min.should == 0
|
30
|
+
@var.upper_bound.max.should == 4
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should report correct bounds on lower bound' do
|
34
|
+
@var.lower_bound.min.should == 1
|
35
|
+
@var.lower_bound.max.should == 3
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should raise error when trying to access assigned value' do
|
39
|
+
lambda{ @var.value }.should raise_error(RuntimeError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should not raise error when enumerating over bound multiple times' do
|
43
|
+
# For C0 coverage.
|
44
|
+
lower_bound = @var.lower_bound
|
45
|
+
lambda do
|
46
|
+
lower_bound.each{}
|
47
|
+
lower_bound.each{}
|
48
|
+
end.should_not raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it_should_behave_like 'set var operand'
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Gecode::SetVar, '(assigned)' do
|
55
|
+
before do
|
56
|
+
@model = Gecode::Model.new
|
57
|
+
@operand = @var = @model.set_var(1, 1)
|
58
|
+
@model.solve!
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should be assigned' do
|
62
|
+
@var.should be_assigned
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should give it's value when inspecting" do
|
66
|
+
@var.inspect.should include('[1]')
|
67
|
+
@var.inspect.should_not include('lub-range')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should report the correct bounds' do
|
71
|
+
@var.upper_bound.to_a.should == [1]
|
72
|
+
@var.lower_bound.to_a.should == [1]
|
73
|
+
@var.value.to_a.should == [1]
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should allow inspection even when the bounds are too large to display' do
|
77
|
+
var = @model.set_var(0..10**4, 0..10**4)
|
78
|
+
var.inspect.should include('too large')
|
79
|
+
end
|
80
|
+
|
81
|
+
it_should_behave_like 'set var operand'
|
82
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/gecoder'
|
4
|
+
|
5
|
+
module CustomVarMatchers
|
6
|
+
class HaveDomain
|
7
|
+
def initialize(expected)
|
8
|
+
@expected = expected
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(target)
|
12
|
+
@target = target
|
13
|
+
if @expected.kind_of? Range
|
14
|
+
last = @expected.end
|
15
|
+
last -= 1 if @expected.exclude_end?
|
16
|
+
return @target.range? && @expected.begin == @target.min &&
|
17
|
+
last == @target.max
|
18
|
+
else
|
19
|
+
@expected = @expected.to_a
|
20
|
+
return false unless @target.size == @expected.size
|
21
|
+
@expected.each do |element|
|
22
|
+
return false unless @target.include? element
|
23
|
+
end
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message
|
30
|
+
"expected #{@target.inspect} to have domain #{@expected.inspect}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def negative_failure_message
|
34
|
+
"expected #{@target.inspect} not to have domain #{@expected.inspect}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Tests whether a variable has the expected domain.
|
39
|
+
def have_domain(expected)
|
40
|
+
HaveDomain.new(expected)
|
41
|
+
end
|
42
|
+
|
43
|
+
class HaveBounds
|
44
|
+
def initialize(expected_glb, expected_lub)
|
45
|
+
@expected_glb = expected_glb.to_a
|
46
|
+
@expected_lub = expected_lub.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
def matches?(target)
|
50
|
+
@target = target
|
51
|
+
return @target.lower_bound.size == @expected_glb.size &&
|
52
|
+
@target.upper_bound.size == @expected_lub.size &&
|
53
|
+
@target.lower_bound.to_a == @expected_glb &&
|
54
|
+
@target.upper_bound.to_a == @expected_lub
|
55
|
+
end
|
56
|
+
|
57
|
+
def failure_message
|
58
|
+
"expected #{@target.inspect} to have greatest lower bound " +
|
59
|
+
"#{@expected_glb.inspect} and least upper bound #{@expected_lub.inspect}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def negative_failure_message
|
63
|
+
"expected #{@target.inspect} to not have greatest lower bound " +
|
64
|
+
"#{@expected_glb.inspect} and least upper bound #{@expected_lub.inspect}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Tests whether a set variable has the expected bounds.
|
69
|
+
def have_bounds(expected_glb, expected_lub)
|
70
|
+
HaveBounds.new(expected_glb, expected_lub)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Spec::Runner.configure do |config|
|
75
|
+
config.include(CustomVarMatchers)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Help methods for the GecodeR specs.
|
80
|
+
module GecodeR::Specs
|
81
|
+
module SetHelper
|
82
|
+
module_function
|
83
|
+
|
84
|
+
# Returns the arguments that should be used in a partial mock to expect the
|
85
|
+
# specified constant set (possibly an array of arguments).
|
86
|
+
def expect_constant_set(constant_set)
|
87
|
+
if constant_set.kind_of? Range
|
88
|
+
return constant_set.first, constant_set.last
|
89
|
+
elsif constant_set.kind_of? Fixnum
|
90
|
+
constant_set
|
91
|
+
else
|
92
|
+
an_instance_of(Gecode::Raw::IntSet)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
module GeneralHelper
|
98
|
+
module_function
|
99
|
+
|
100
|
+
# Produces a base operand that can be used to mock specific types of
|
101
|
+
# operands.
|
102
|
+
def general_operand_base(model)
|
103
|
+
mock_op_class = Class.new
|
104
|
+
mock_op_class.class_eval do
|
105
|
+
attr :model
|
106
|
+
|
107
|
+
def bind
|
108
|
+
raise 'Bind should not be called directly for an operand.'
|
109
|
+
end
|
110
|
+
alias_method :bind_array, :bind
|
111
|
+
end
|
112
|
+
op = mock_op_class.new
|
113
|
+
op.instance_eval do
|
114
|
+
@model = model
|
115
|
+
end
|
116
|
+
return op
|
117
|
+
end
|
118
|
+
|
119
|
+
# Produces a general int operand. The method returns two objects:
|
120
|
+
# the operand itself and the variable it returns when #to_int_var
|
121
|
+
# is called.
|
122
|
+
def general_int_operand(model)
|
123
|
+
op = general_operand_base(model)
|
124
|
+
|
125
|
+
int_var = model.int_var
|
126
|
+
class <<op
|
127
|
+
include Gecode::Int::IntOperand
|
128
|
+
attr :model
|
129
|
+
end
|
130
|
+
op.stub!(:to_int_var).and_return int_var
|
131
|
+
|
132
|
+
return op, int_var
|
133
|
+
end
|
134
|
+
|
135
|
+
# Produces a general bool operand. The method returns two objects:
|
136
|
+
# the operand itself and the variable it returns when #to_bool_var
|
137
|
+
# is called.
|
138
|
+
def general_bool_operand(model)
|
139
|
+
op = general_operand_base(model)
|
140
|
+
|
141
|
+
bool_var = model.bool_var
|
142
|
+
class <<op
|
143
|
+
include Gecode::Bool::BoolOperand
|
144
|
+
attr :model
|
145
|
+
end
|
146
|
+
op.stub!(:to_bool_var).and_return bool_var
|
147
|
+
|
148
|
+
return op, bool_var
|
149
|
+
end
|
150
|
+
|
151
|
+
# Produces a general set operand. The method returns two objects:
|
152
|
+
# the operand itself and the variable it returns when #to_set_var
|
153
|
+
# is called.
|
154
|
+
def general_set_operand(model)
|
155
|
+
op = general_operand_base(model)
|
156
|
+
|
157
|
+
set_var = model.set_var
|
158
|
+
class <<op
|
159
|
+
include Gecode::Set::SetOperand
|
160
|
+
attr :model
|
161
|
+
end
|
162
|
+
op.stub!(:to_set_var).and_return set_var
|
163
|
+
|
164
|
+
return op, set_var
|
165
|
+
end
|
166
|
+
|
167
|
+
# Produces a general int enum operand. The method returns two objects:
|
168
|
+
# the operand itself and the variable it returns when #to_int_enum
|
169
|
+
# is called.
|
170
|
+
def general_int_enum_operand(model)
|
171
|
+
op = general_operand_base(model)
|
172
|
+
|
173
|
+
int_enum = model.int_var_array(5)
|
174
|
+
class <<op
|
175
|
+
include Gecode::IntEnum::IntEnumOperand
|
176
|
+
attr :model
|
177
|
+
end
|
178
|
+
op.stub!(:to_int_enum).and_return int_enum
|
179
|
+
|
180
|
+
return op, int_enum
|
181
|
+
end
|
182
|
+
|
183
|
+
# Produces a general bool enum operand. The method returns two objects:
|
184
|
+
# the operand itself and the variable it returns when #to_bool_enum
|
185
|
+
# is called.
|
186
|
+
def general_bool_enum_operand(model)
|
187
|
+
op = general_operand_base(model)
|
188
|
+
|
189
|
+
bool_enum = model.bool_var_array(5)
|
190
|
+
class <<op
|
191
|
+
include Gecode::BoolEnum::BoolEnumOperand
|
192
|
+
attr :model
|
193
|
+
end
|
194
|
+
op.stub!(:to_bool_enum).and_return bool_enum
|
195
|
+
|
196
|
+
return op, bool_enum
|
197
|
+
end
|
198
|
+
|
199
|
+
# Produces a general set enum operand. The method returns two objects:
|
200
|
+
# the operand itself and the variable it returns when #to_set_enum
|
201
|
+
# is called.
|
202
|
+
def general_set_enum_operand(model)
|
203
|
+
op = general_operand_base(model)
|
204
|
+
|
205
|
+
set_enum = model.set_var_array(5)
|
206
|
+
class <<op
|
207
|
+
include Gecode::SetEnum::SetEnumOperand
|
208
|
+
attr :model
|
209
|
+
end
|
210
|
+
op.stub!(:to_set_enum).and_return set_enum
|
211
|
+
|
212
|
+
return op, set_enum
|
213
|
+
end
|
214
|
+
|
215
|
+
# Produces a general selected set operand. The method returns two objects:
|
216
|
+
# the operand itself and the array of variables corresponding to the
|
217
|
+
# operands it returns when # #to_selected_set is called.
|
218
|
+
def general_selected_set_operand(model)
|
219
|
+
set_enum, set_enum_var = general_set_enum_operand(model)
|
220
|
+
set, set_var = general_set_operand(model)
|
221
|
+
op = Gecode::SelectedSet::SelectedSetOperand.new(
|
222
|
+
set_enum, set)
|
223
|
+
return op, [set_enum_var, set_var]
|
224
|
+
end
|
225
|
+
|
226
|
+
# Produces a general set elements operand. The method returns two
|
227
|
+
# objects: the operand itself and the set var corresponding to the
|
228
|
+
# operands it returns when # #to_selected_set is called.
|
229
|
+
def general_set_elements_operand(model)
|
230
|
+
set, set_var = general_set_operand(model)
|
231
|
+
op = Gecode::SetElements::SetElementsOperand.new(set)
|
232
|
+
return op, set_var
|
233
|
+
end
|
234
|
+
|
235
|
+
# Produces a general fixnum enum operand. The method returns two objects:
|
236
|
+
# the operand itself and the variable it returns when #to_fixnum_enum
|
237
|
+
# is called.
|
238
|
+
def general_fixnum_enum_operand(model)
|
239
|
+
op = general_operand_base(model)
|
240
|
+
|
241
|
+
fixnum_enum = model.wrap_enum([1, -4, 9, 4, 0])
|
242
|
+
class <<op
|
243
|
+
include Gecode::FixnumEnum::FixnumEnumOperand
|
244
|
+
attr :model
|
245
|
+
end
|
246
|
+
op.stub!(:to_fixnum_enum).and_return fixnum_enum
|
247
|
+
|
248
|
+
return op, fixnum_enum
|
249
|
+
end
|
250
|
+
|
251
|
+
# Produces an array of general operands of the specified types.
|
252
|
+
# Returns an array of operands and an array of their variables.
|
253
|
+
def produce_general_arguments(property_types)
|
254
|
+
operands = []
|
255
|
+
variables = []
|
256
|
+
property_types.each do |type|
|
257
|
+
op, var = eval "general_#{type}_operand(@model)"
|
258
|
+
operands << op
|
259
|
+
variables << var
|
260
|
+
end
|
261
|
+
return operands, variables
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
include GecodeR::Specs::GeneralHelper
|
data/tasks/all_tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Doing the full "release" task requires a number of gems:
|
2
|
+
|
3
|
+
# To run the Rake scripts.
|
4
|
+
rake
|
5
|
+
|
6
|
+
# To generate the website.
|
7
|
+
webgen
|
8
|
+
coderay
|
9
|
+
|
10
|
+
# To run the specs and produce a report for the website.
|
11
|
+
rspec
|
12
|
+
rcov
|
13
|
+
|
14
|
+
# To release files to RubyForge.
|
15
|
+
meta_project
|
16
|
+
rubyforge
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
To precompile the Windows gem you need to set up a cross-compilation
|
21
|
+
environment. See the following notes for instructions:
|
22
|
+
http://rubyforge.org/pipermail/gecoder-devel/2008-January/000039.html
|