gecoder 0.8.3 → 0.9.0
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 +15 -0
- data/README +6 -2
- data/example/equation_system.rb +15 -0
- data/example/magic_sequence.rb +7 -7
- data/example/money.rb +36 -0
- data/example/queens.rb +7 -8
- data/example/send_most_money.rb +1 -1
- data/example/square_tiling.rb +2 -2
- data/example/sudoku-set.rb +11 -12
- data/example/sudoku.rb +40 -45
- data/ext/extconf.rb +0 -0
- data/lib/gecoder/bindings.rb +42 -0
- data/lib/gecoder/bindings/bindings.rb +16 -0
- data/lib/gecoder/interface.rb +2 -1
- data/lib/gecoder/interface/branch.rb +16 -9
- data/lib/gecoder/interface/constraints.rb +410 -451
- data/lib/gecoder/interface/constraints/bool/boolean.rb +205 -213
- data/lib/gecoder/interface/constraints/bool/channel.rb +4 -5
- data/lib/gecoder/interface/constraints/bool/linear.rb +192 -21
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +43 -39
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +43 -49
- data/lib/gecoder/interface/constraints/bool_enum/relation.rb +38 -71
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +73 -22
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +140 -61
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +4 -4
- 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 +131 -130
- data/lib/gecoder/interface/constraints/int/channel.rb +21 -31
- data/lib/gecoder/interface/constraints/int/domain.rb +45 -42
- data/lib/gecoder/interface/constraints/int/linear.rb +85 -239
- data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +55 -64
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +35 -37
- data/lib/gecoder/interface/constraints/int_enum/count.rb +53 -78
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +36 -46
- data/lib/gecoder/interface/constraints/int_enum/element.rb +39 -57
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +15 -19
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +65 -72
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +42 -45
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +79 -22
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +215 -44
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +14 -14
- 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 +43 -53
- data/lib/gecoder/interface/constraints/set/channel.rb +26 -29
- data/lib/gecoder/interface/constraints/set/connection.rb +89 -152
- data/lib/gecoder/interface/constraints/set/domain.rb +112 -65
- data/lib/gecoder/interface/constraints/set/include.rb +36 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +96 -110
- data/lib/gecoder/interface/constraints/set/relation.rb +114 -137
- 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 +23 -27
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +18 -19
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +62 -53
- data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +73 -23
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +222 -57
- data/lib/gecoder/interface/enum_matrix.rb +4 -4
- data/lib/gecoder/interface/enum_wrapper.rb +71 -22
- data/lib/gecoder/interface/model.rb +167 -12
- data/lib/gecoder/interface/model_sugar.rb +84 -0
- data/lib/gecoder/interface/search.rb +30 -18
- data/lib/gecoder/interface/variables.rb +103 -33
- data/lib/gecoder/version.rb +2 -2
- data/specs/bool_var.rb +19 -12
- data/specs/constraints/{boolean.rb → bool/boolean.rb} +103 -28
- 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/{extensional.rb → bool_enum/extensional.rb} +32 -101
- data/specs/constraints/constraint_helper.rb +149 -179
- data/specs/constraints/constraint_receivers.rb +103 -0
- data/specs/constraints/constraints.rb +6 -63
- 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 +4 -5
- 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/enum_wrapper.rb +53 -3
- data/specs/int_var.rb +44 -25
- data/specs/model.rb +58 -1
- data/specs/model_sugar.rb +30 -0
- data/specs/search.rb +24 -5
- data/specs/selected_set.rb +39 -0
- data/specs/set_elements.rb +34 -0
- data/specs/set_var.rb +22 -8
- data/specs/spec_helper.rb +206 -6
- data/tasks/distribution.rake +22 -7
- data/tasks/svn.rake +3 -1
- metadata +218 -134
- data/lib/gecoder/interface/constraints/set_enum/selection.rb +0 -217
- data/specs/constraints/arithmetic.rb +0 -351
- data/specs/constraints/bool_enum_relation.rb +0 -160
- data/specs/constraints/cardinality.rb +0 -157
- data/specs/constraints/channel.rb +0 -454
- data/specs/constraints/connection.rb +0 -369
- data/specs/constraints/count.rb +0 -146
- data/specs/constraints/distinct.rb +0 -164
- data/specs/constraints/element.rb +0 -108
- data/specs/constraints/equality.rb +0 -31
- data/specs/constraints/int_domain.rb +0 -70
- data/specs/constraints/int_relation.rb +0 -82
- data/specs/constraints/linear.rb +0 -340
- data/specs/constraints/selection.rb +0 -292
- data/specs/constraints/set_domain.rb +0 -185
- data/specs/constraints/set_operation.rb +0 -285
- data/specs/constraints/set_relation.rb +0 -197
- data/specs/constraints/sort.rb +0 -179
@@ -0,0 +1,116 @@
|
|
1
|
+
module Gecode::SetElements
|
2
|
+
class SetElementsConstraintReceiver
|
3
|
+
# Constrains the set elements to equal +operand+ (either a
|
4
|
+
# constant integer or an integer operand).
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# # The elements of +set+ must equal +int+
|
9
|
+
# set.elements.must == int
|
10
|
+
#
|
11
|
+
# # The elements of +set+ must equal 17
|
12
|
+
# set.elements.must == 17
|
13
|
+
def ==(operand, options = {})
|
14
|
+
comparison(:==, operand, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Constrains the set elements to be strictly greater than
|
18
|
+
# +operand+ (either a constant integer or an integer operand).
|
19
|
+
#
|
20
|
+
# ==== Examples
|
21
|
+
#
|
22
|
+
# # The elements of +set+ must be strictly greater than +int+
|
23
|
+
# set.elements.must > int
|
24
|
+
#
|
25
|
+
# # The elements of +set+ must be strictly greater than 17
|
26
|
+
# set.elements.must > 17
|
27
|
+
def >(operand, options = {})
|
28
|
+
comparison(:>, operand, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Constrains the set elements to be greater than or equal to
|
32
|
+
# +operand+ (either a constant integer or an integer operand).
|
33
|
+
#
|
34
|
+
# ==== Examples
|
35
|
+
#
|
36
|
+
# # The elements of +set+ must be greater than or equal to +int+
|
37
|
+
# set.elements.must >= int
|
38
|
+
#
|
39
|
+
# # The elements of +set+ must be greater than or equal to 17
|
40
|
+
# set.elements.must >= 17
|
41
|
+
def >=(operand, options = {})
|
42
|
+
comparison(:>=, operand, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Constrains the set elements to be strictly less than
|
46
|
+
# +operand+ (either a constant integer or an integer operand).
|
47
|
+
#
|
48
|
+
# ==== Examples
|
49
|
+
#
|
50
|
+
# # The elements of +set+ must be strictly less than +int+
|
51
|
+
# set.elements.must < int
|
52
|
+
#
|
53
|
+
# # The elements of +set+ must be strictly less than 17
|
54
|
+
# set.elements.must < 17
|
55
|
+
def <(operand, options = {})
|
56
|
+
comparison(:<, operand, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Constrains the set elements to be less than or equal to
|
60
|
+
# +operand+ (either a constant integer or an integer operand).
|
61
|
+
#
|
62
|
+
# ==== Examples
|
63
|
+
#
|
64
|
+
# # The elements of +set+ must be less than or equal to +int+
|
65
|
+
# set.elements.must <= int
|
66
|
+
#
|
67
|
+
# # The elements of +set+ must be less than or equal to 17
|
68
|
+
# set.elements.must <= 17
|
69
|
+
def <=(operand, options = {})
|
70
|
+
comparison(:<=, operand, options)
|
71
|
+
end
|
72
|
+
|
73
|
+
alias_comparison_methods
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Helper for the comparison methods. The reason that they are not
|
78
|
+
# generated in a loop is that it would mess up the RDoc.
|
79
|
+
def comparison(name, operand, options)
|
80
|
+
unless operand.respond_to?(:to_int_var) or
|
81
|
+
operand.kind_of?(Fixnum)
|
82
|
+
raise TypeError, "Expected int operand or integer, got " +
|
83
|
+
"#{operand.class}."
|
84
|
+
end
|
85
|
+
unless options[:reify].nil?
|
86
|
+
raise ArgumentError, 'Reification is not supported by the elements ' +
|
87
|
+
'relation constraint.'
|
88
|
+
end
|
89
|
+
|
90
|
+
unless @params[:negate]
|
91
|
+
relation_type = Gecode::Util::RELATION_TYPES[name]
|
92
|
+
else
|
93
|
+
relation_type = Gecode::Util::NEGATED_RELATION_TYPES[name]
|
94
|
+
end
|
95
|
+
@params.update Gecode::Set::Util.decode_options(options)
|
96
|
+
@model.add_constraint Relation::RelationConstraint.new(@model,
|
97
|
+
@params.update(:relation_type => relation_type, :rhs => operand))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
module Relation #:nodoc:
|
102
|
+
class RelationConstraint < Gecode::Constraint #:nodoc:
|
103
|
+
def post
|
104
|
+
set_elements, rhs, type = @params.values_at(:lhs, :rhs, :relation_type)
|
105
|
+
set = set_elements.to_set_elements
|
106
|
+
|
107
|
+
if rhs.kind_of? Fixnum
|
108
|
+
# Use a proxy int variable to cover.
|
109
|
+
rhs = @model.int_var(rhs)
|
110
|
+
end
|
111
|
+
Gecode::Raw::rel(@model.active_space, set.to_set_var.bind,
|
112
|
+
type, rhs.to_int_var.bind)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# A module containing constraints that have set.elements as left hand
|
2
|
+
# side.
|
3
|
+
module Gecode::SetElements #:nodoc:
|
4
|
+
# A SetElementsOperand is an uncommon operand that results from calling
|
5
|
+
# SetOperand#elements. It facilitates placing the constraints defined
|
6
|
+
# in SetElementsConstraintReceiver
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
#
|
10
|
+
# Producing a SetElementsOperand from +set_operand+:
|
11
|
+
#
|
12
|
+
# set_operand.elements
|
13
|
+
#
|
14
|
+
class SetElementsOperand
|
15
|
+
include Gecode::Operand
|
16
|
+
|
17
|
+
# Constructs a new set elements operand +set+.
|
18
|
+
def initialize(set) #:nodoc:
|
19
|
+
unless set.respond_to? :to_set_var
|
20
|
+
raise TypeError, "Expected set operand, got #{set.class}."
|
21
|
+
end
|
22
|
+
|
23
|
+
@set = set
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the set operand that makes up the set elements operand.
|
27
|
+
def to_set_elements #:nodoc:
|
28
|
+
return @set
|
29
|
+
end
|
30
|
+
|
31
|
+
def model #:nodoc:
|
32
|
+
@set.model
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def construct_receiver(params)
|
38
|
+
SetElementsConstraintReceiver.new(model, params)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# SetElementsConstraintReceiver contains all constraints that can be
|
43
|
+
# placed on a SetElementsOperand.
|
44
|
+
#
|
45
|
+
# Constraints are placed by calling SetElementsOperand#must (or any other
|
46
|
+
# of the variations defined in Operand), which produces a
|
47
|
+
# SetElementsConstraintReceiver from which the desired constraint can
|
48
|
+
# be used.
|
49
|
+
#
|
50
|
+
# Each constraint accepts a number of options. See ConstraintReceiver
|
51
|
+
# for more information.
|
52
|
+
#
|
53
|
+
# ==== Examples
|
54
|
+
#
|
55
|
+
# Constrains all elements in +set_operand+ to be strictly greater than 17
|
56
|
+
# using SetOperand#elements and SetElementsConstraintReceiver#>:
|
57
|
+
#
|
58
|
+
# set.elements.must > 17
|
59
|
+
#
|
60
|
+
# Constrains all elements in +set_operand+ to be strictly greater than
|
61
|
+
# +int_operand+ using SetOperand#elements and SetElementsConstraintReceiver#>:
|
62
|
+
#
|
63
|
+
# set.elements.must > int_operand
|
64
|
+
#
|
65
|
+
# The same as above, but specifying that strength :domain should be
|
66
|
+
# used and that the constraint should be reified with +bool_operand+:
|
67
|
+
#
|
68
|
+
# set.elements.must_be.greater_than(int_operand, :strength => :domain, :reify => bool_operand)
|
69
|
+
#
|
70
|
+
class SetElementsConstraintReceiver < Gecode::ConstraintReceiver
|
71
|
+
# Raises TypeError unless the left hand side is set elements operand.
|
72
|
+
def initialize(model, params) #:nodoc:
|
73
|
+
super
|
74
|
+
|
75
|
+
unless params[:lhs].respond_to? :to_set_elements
|
76
|
+
raise TypeError, 'Must have set elements operand as left hand side.'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Gecode::Set #:nodoc:
|
83
|
+
module SetOperand
|
84
|
+
# Produces a SetElementsOperand on which relation constraints can be placed that
|
85
|
+
# constrain all elements in the set.
|
86
|
+
#
|
87
|
+
# ==== Examples
|
88
|
+
#
|
89
|
+
# # The elements of +set+.
|
90
|
+
# set.elements
|
91
|
+
def elements
|
92
|
+
Gecode::SetElements::SetElementsOperand.new(self)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
require 'gecoder/interface/constraints/set_elements/relation.rb'
|
@@ -1,10 +1,21 @@
|
|
1
|
-
module Gecode::
|
2
|
-
class
|
3
|
-
#
|
4
|
-
#
|
1
|
+
module Gecode::SetEnum
|
2
|
+
class SetEnumConstraintReceiver
|
3
|
+
# Constrains this set enum to channel +int_enum_operand+. The i:th set
|
4
|
+
# in the enumeration of set operands is constrained to includes the value
|
5
|
+
# of the j:th integer operand.
|
6
|
+
#
|
7
|
+
# Neither reification nor negation is supported.
|
8
|
+
#
|
9
|
+
# ==== Examples
|
10
|
+
#
|
11
|
+
# # +set_enum+ is constrained to channel +int_enum+.
|
12
|
+
# int_enum.must.channel set_enum
|
13
|
+
#
|
14
|
+
# # This is another way of writing the above.
|
15
|
+
# set_enum.must.channel int_enum
|
5
16
|
def channel(enum, options = {})
|
6
|
-
unless enum.respond_to? :
|
7
|
-
raise TypeError, "Expected integer
|
17
|
+
unless enum.respond_to? :to_int_enum
|
18
|
+
raise TypeError, "Expected integer enum, for #{enum.class}."
|
8
19
|
end
|
9
20
|
if @params[:negate]
|
10
21
|
raise Gecode::MissingConstraintError, 'A negated channel constraint ' +
|
@@ -15,35 +26,20 @@ module Gecode::Constraints::SetEnum
|
|
15
26
|
'reification option.'
|
16
27
|
end
|
17
28
|
|
18
|
-
@params.update(Gecode::
|
29
|
+
@params.update(Gecode::Set::Util.decode_options(options))
|
19
30
|
@params.update(:rhs => enum)
|
20
|
-
@model.add_constraint Channel::
|
31
|
+
@model.add_constraint Channel::IntEnumChannelConstraint.new(@model, @params)
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
35
|
# A module that gathers the classes and modules used in channel constraints.
|
25
36
|
module Channel #:nodoc:
|
26
|
-
|
27
|
-
# integer variables with one enumeration of set variables. The i:th set
|
28
|
-
# in the enumeration of set variables is constrainde to includes the value
|
29
|
-
# of the j:th integer variable.
|
30
|
-
#
|
31
|
-
# Neither reification nor negation is supported.
|
32
|
-
#
|
33
|
-
# == Examples
|
34
|
-
#
|
35
|
-
# # +set_enum+ is constrained to channel +int_enum+.
|
36
|
-
# int_enum.must.channel set_enum
|
37
|
-
#
|
38
|
-
# # This is another way of saying the above.
|
39
|
-
# set_enum.must.channel int_enum
|
40
|
-
#
|
41
|
-
class IntChannelConstraint < Gecode::Constraints::Constraint
|
37
|
+
class IntEnumChannelConstraint < Gecode::Constraint #:nodoc:
|
42
38
|
def post
|
43
39
|
lhs, rhs = @params.values_at(:lhs, :rhs)
|
44
|
-
Gecode::Raw::channel(@model.active_space, rhs.
|
45
|
-
lhs.
|
40
|
+
Gecode::Raw::channel(@model.active_space, rhs.to_int_enum.bind_array,
|
41
|
+
lhs.to_set_enum.bind_array)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
49
|
-
end
|
45
|
+
end
|
@@ -1,12 +1,21 @@
|
|
1
|
-
module Gecode::
|
2
|
-
class
|
3
|
-
#
|
4
|
-
# one element in common
|
5
|
-
#
|
1
|
+
module Gecode::SetEnum
|
2
|
+
class SetEnumConstraintReceiver
|
3
|
+
# Constrains all pairs of set operands in the enumeration to at
|
4
|
+
# most have one element in common and be of a specified size.
|
5
|
+
# Providing a size is not optional.
|
6
|
+
#
|
7
|
+
# Neither negation nor reification is supported.
|
8
|
+
#
|
9
|
+
# ==== Examples
|
10
|
+
#
|
11
|
+
# # All set operands in +sets+ must have cardinality 17 and no pair may
|
12
|
+
# # have more than one element in common.
|
13
|
+
# sets.must.at_most_share_one_element(:size => 17)
|
6
14
|
def at_most_share_one_element(options = {})
|
7
15
|
unless options.has_key? :size
|
8
16
|
raise ArgumentError, 'Option :size has to be specified.'
|
9
17
|
end
|
18
|
+
# TODO can we use Set::Util::decode_options here instead?
|
10
19
|
unless options.size == 1
|
11
20
|
raise ArgumentError, 'Only the option :size is accepted, got ' +
|
12
21
|
"#{options.keys.join(', ')}."
|
@@ -23,22 +32,12 @@ module Gecode::Constraints::SetEnum
|
|
23
32
|
|
24
33
|
# A module that gathers the classes and modules used in distinct constraints.
|
25
34
|
module Distinct #:nodoc:
|
26
|
-
|
27
|
-
# variables in the enumeration to at most have one element in common and be
|
28
|
-
# of a specified size. Providing a size is not optional.
|
29
|
-
#
|
30
|
-
# Neither negation nor reification is supported.
|
31
|
-
#
|
32
|
-
# == Examples
|
33
|
-
#
|
34
|
-
# # All set variables in +sets+ must have cardinality 17 and no pair may
|
35
|
-
# # have more than one element in common.
|
36
|
-
# sets.must.at_most_share_one_element(:size => 17)
|
37
|
-
class AtMostOneConstraint < Gecode::Constraints::Constraint
|
35
|
+
class AtMostOneConstraint < Gecode::Constraint #:nodoc:
|
38
36
|
def post
|
39
37
|
sets, size = @params.values_at(:lhs, :size)
|
40
|
-
Gecode::Raw::atmostOne(@model.active_space,
|
38
|
+
Gecode::Raw::atmostOne(@model.active_space,
|
39
|
+
sets.to_set_enum.bind_array, size)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
44
|
-
end
|
43
|
+
end
|
@@ -1,60 +1,69 @@
|
|
1
|
-
module Gecode::
|
2
|
-
|
3
|
-
|
1
|
+
module Gecode::SetEnum
|
2
|
+
module SetEnumOperand
|
3
|
+
# Produces a SetOperand representing the union of all sets in this
|
4
|
+
# enumeration.
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# # The union of all sets in +set_enum+.
|
9
|
+
# set_enum.union
|
10
|
+
def union
|
11
|
+
set_operation(:union)
|
12
|
+
end
|
4
13
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
# Produces a SetOperand representing the intersection of all sets in this
|
15
|
+
# enumeration.
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# # The intersection of all sets in +set_enum+.
|
20
|
+
# set_enum.intersection
|
21
|
+
def intersection
|
22
|
+
set_operation(:intersection)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Produces a SetOperand representing the disjoint union of all sets
|
26
|
+
# in this enumeration.
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
#
|
30
|
+
# # The disjoint union of all sets in +set_enum+.
|
31
|
+
# set_enum.disjoint_union
|
32
|
+
def disjoint_union
|
33
|
+
set_operation(:disjoint_union)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Produces the SetOperand resulting from +operator+ applied to this
|
39
|
+
# operand.
|
40
|
+
def set_operation(operator)
|
41
|
+
Operation::OperationSetOperand.new(model, self, operator)
|
42
|
+
end
|
13
43
|
end
|
14
|
-
end
|
15
44
|
|
16
|
-
# A module that gathers the classes and modules used
|
17
|
-
module
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# # The intersection of all set variables must equal [1,3,5].
|
34
|
-
# sets.intersection.must == [1,3,5]
|
35
|
-
#
|
36
|
-
# # The union of all set variable must be a subset of the set variable
|
37
|
-
# # +universe+.
|
38
|
-
# sets.union.must_be.subset_of universe
|
39
|
-
#
|
40
|
-
# # The same as above, but reified with the boolean variable
|
41
|
-
# # +is_within_universe+.
|
42
|
-
# sets.union.must_be.subset_of(universe, :reify => is_within_universe)
|
43
|
-
class ExpressionStub < Gecode::Constraints::Set::CompositeStub
|
44
|
-
def constrain_equal(variable, params, constrain)
|
45
|
-
enum, operation = @params.values_at(:lhs, :operation)
|
46
|
-
|
47
|
-
if constrain
|
48
|
-
if operation == Gecode::Raw::SOT_INTER or
|
49
|
-
operation == Gecode::Raw::SOT_MINUS
|
50
|
-
variable.must_be.subset_of enum.first.upper_bound
|
51
|
-
else
|
52
|
-
variable.must_be.subset_of enum.upper_bound_range
|
45
|
+
# A module that gathers the classes and modules used in operation constraints.
|
46
|
+
module Operation #:nodoc:
|
47
|
+
class OperationSetOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc:
|
48
|
+
def initialize(model, enum, operator)
|
49
|
+
super model
|
50
|
+
@enum = enum
|
51
|
+
@operator = operator
|
52
|
+
end
|
53
|
+
|
54
|
+
def constrain_equal(set_operand, constrain_domain, propagation_options)
|
55
|
+
operation = Gecode::Util::SET_OPERATION_TYPES[@operator]
|
56
|
+
if constrain_domain
|
57
|
+
if operation == Gecode::Raw::SOT_INTER
|
58
|
+
set_operand.must_be.subset_of @enum.first.upper_bound
|
59
|
+
else
|
60
|
+
set_operand.must_be.subset_of @enum.upper_bound_range
|
61
|
+
end
|
53
62
|
end
|
63
|
+
|
64
|
+
Gecode::Raw::rel(@model.active_space, operation,
|
65
|
+
@enum.to_set_enum.bind_array, set_operand.to_set_var.bind)
|
54
66
|
end
|
55
|
-
|
56
|
-
Gecode::Raw::rel(@model.active_space, operation, enum.to_set_var_array,
|
57
|
-
variable.bind)
|
58
67
|
end
|
59
68
|
end
|
60
|
-
end
|
69
|
+
end
|