gecoder 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGES +6 -0
  2. data/README +1 -1
  3. data/example/square_tiling.rb +84 -0
  4. data/example/sudoku-set.rb +107 -0
  5. data/example/sudoku.rb +2 -6
  6. data/lib/gecoder/bindings.rb +1 -1
  7. data/lib/gecoder/bindings/bindings.rb +20 -0
  8. data/lib/gecoder/interface/binding_changes.rb +2 -2
  9. data/lib/gecoder/interface/branch.rb +50 -51
  10. data/lib/gecoder/interface/constraints.rb +10 -10
  11. data/lib/gecoder/interface/constraints/bool/boolean.rb +79 -5
  12. data/lib/gecoder/interface/constraints/bool/linear.rb +29 -0
  13. data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +34 -4
  14. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +14 -9
  15. data/lib/gecoder/interface/constraints/int/arithmetic.rb +26 -8
  16. data/lib/gecoder/interface/constraints/int/domain.rb +30 -3
  17. data/lib/gecoder/interface/constraints/int/linear.rb +82 -16
  18. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +31 -3
  19. data/lib/gecoder/interface/constraints/int_enum/channel.rb +63 -3
  20. data/lib/gecoder/interface/constraints/int_enum/count.rb +20 -3
  21. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +22 -2
  22. data/lib/gecoder/interface/constraints/int_enum/element.rb +23 -4
  23. data/lib/gecoder/interface/constraints/int_enum/equality.rb +9 -2
  24. data/lib/gecoder/interface/constraints/int_enum/sort.rb +28 -3
  25. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +1 -1
  26. data/lib/gecoder/interface/constraints/int_var_constraints.rb +13 -8
  27. data/lib/gecoder/interface/constraints/set/cardinality.rb +27 -8
  28. data/lib/gecoder/interface/constraints/set/connection.rb +72 -6
  29. data/lib/gecoder/interface/constraints/set/domain.rb +46 -3
  30. data/lib/gecoder/interface/constraints/set/operation.rb +35 -4
  31. data/lib/gecoder/interface/constraints/set/relation.rb +59 -6
  32. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +22 -3
  33. data/lib/gecoder/interface/constraints/set_enum/operation.rb +26 -2
  34. data/lib/gecoder/interface/constraints/set_enum/selection.rb +110 -36
  35. data/lib/gecoder/interface/constraints/set_var_constraints.rb +11 -7
  36. data/lib/gecoder/interface/model.rb +6 -6
  37. data/lib/gecoder/interface/search.rb +6 -6
  38. data/lib/gecoder/interface/variables.rb +56 -12
  39. data/lib/gecoder/version.rb +1 -1
  40. data/specs/constraints/linear.rb +167 -1
  41. data/specs/constraints/set_domain.rb +6 -0
  42. data/tasks/distribution.rake +25 -3
  43. data/tasks/website.rake +5 -12
  44. metadata +10 -4
  45. data/vendor/rust/configure.rb +0 -6
  46. data/vendor/rust/out.rb +0 -627
@@ -15,8 +15,22 @@ module Gecode::IntEnumMethods
15
15
  end
16
16
 
17
17
  # A module that gathers the classes and modules used by arithmetic constraints.
18
- module Gecode::Constraints::IntEnum::Arithmetic
19
- # Describes an expression stub started with an int var enum following by #max.
18
+ module Gecode::Constraints::IntEnum::Arithmetic #:nodoc:
19
+ # Describes a CompositeStub for the max constraint, which constrains the
20
+ # maximum value of the integer variables in an enumeration.
21
+ #
22
+ # == Example
23
+ #
24
+ # # The maximum must be positive.
25
+ # int_enum.max.must > 0
26
+ #
27
+ # # The maximum must equal a integer variable +max+.
28
+ # int_enum.max.must == max
29
+ #
30
+ # # The maximum must not be negative. The constraint is reified with the
31
+ # # boolean variable +is_negative+ and strength +domain+ is selected.
32
+ # int_enum.max.must_not_be.less_than(0, :reify => is_negative,
33
+ # :strength => :domain)
20
34
  class MaxExpressionStub < Gecode::Constraints::Int::CompositeStub
21
35
  def constrain_equal(variable, params, constrain)
22
36
  enum, strength = @params.values_at(:lhs, :strength)
@@ -29,7 +43,21 @@ module Gecode::Constraints::IntEnum::Arithmetic
29
43
  end
30
44
  end
31
45
 
32
- # Describes an expression stub started with an int var enum following by #min.
46
+ # Describes a CompositeStub for the min constraint, which constrains the
47
+ # minimum value of the integer variables in an enumeration.
48
+ #
49
+ # == Example
50
+ #
51
+ # # The minimum must be positive.
52
+ # int_enum.min.must > 0
53
+ #
54
+ # # The minimum must equal a integer variable +min+.
55
+ # int_enum.min.must == min
56
+ #
57
+ # # The minimum must not be non-positive. The constraint is reified with the
58
+ # # boolean variable +is_positive+ and strength +domain+ is selected.
59
+ # int_enum.min.must_not_be.less_or_equal(0, :reify => is_positive,
60
+ # :strength => :domain)
33
61
  class MinExpressionStub < Gecode::Constraints::Int::CompositeStub
34
62
  def constrain_equal(variable, params, constrain)
35
63
  enum, strength = @params.values_at(:lhs, :strength)
@@ -1,6 +1,6 @@
1
1
  module Gecode::Constraints::IntEnum
2
2
  class Expression
3
- # Posts a channel constraint on the variables in the enum with the specified
3
+ # Adds a channel constraint on the variables in the enum with the specified
4
4
  # other set or int enum.
5
5
  def channel(enum, options = {})
6
6
  if @params[:negate]
@@ -19,8 +19,68 @@ module Gecode::Constraints::IntEnum
19
19
  end
20
20
 
21
21
  # A module that gathers the classes and modules used in channel constraints.
22
- module Channel
23
- # Describes a channel constraint.
22
+ module Channel #:nodoc:
23
+ # Describes a channel constraint which "channels" two enumerations of
24
+ # integer variables or one enumeration of integer variables and one
25
+ # enumeration of set variables. Channel constraints are used to give
26
+ # access to multiple viewpoints when modelling.
27
+ #
28
+ # When used on two integer enumeration, the channel constraint can be
29
+ # thought of as constraining the arrays to be each other's inverses. When
30
+ # used with an enumeration of sets the i:th set includes the value of the
31
+ # j:th integer.
32
+ #
33
+ # Neither reification nor negation is supported. Selecting strength is only
34
+ # supported when using the constraint between two integer enumerations,
35
+ # it's not supported when a set enumeration is used.
36
+ #
37
+ # == Example
38
+ #
39
+ # Lets say that we’re modelling a sequence of numbers that must be distinct
40
+ # and that we want access to the following two view simultaneously.
41
+ #
42
+ # === First view
43
+ #
44
+ # The sequence is modelled as an array of integer variables where the first
45
+ # variable holds the value of the first position in the sequence, the
46
+ # second the value of the second position and so on.
47
+ #
48
+ # # n variables with values from 0 to n-1.
49
+ # elements = int_var_array(n, 0...n)
50
+ # elements.must_be.distinct
51
+ #
52
+ # That way +elements+ will contain the actual sequence when the problem has
53
+ # been solved.
54
+ #
55
+ # === Second view
56
+ #
57
+ # The sequence is modelled as the positions of each value in 0..(n-1) in
58
+ # the sequence. That way the first variable would hold the positions of 0
59
+ # in the sequence, the second variable would hold the positions of 1 in the
60
+ # sequence and so on.
61
+ #
62
+ # positions = int_var_array(n, 0...n)
63
+ # positions.must_be.distinct
64
+ #
65
+ # === Connecting the views
66
+ #
67
+ # In essence the relationship between the two arrays +elements+ and
68
+ # +positions+ is that
69
+ #
70
+ # elements.map{ |e| e.val }[i] == positions.map{ |p| p.val }.index(i)
71
+ #
72
+ # for all i in 0..(n-1). This relationship is enforced by the channel
73
+ # constraint as follows.
74
+ #
75
+ # elements.must.channel positions
76
+ #
77
+ # == Example (sets)
78
+ #
79
+ # # +set_enum+ is constrained to channel +int_enum+.
80
+ # int_enum.must.channel set_enum
81
+ #
82
+ # # This is another way of saying the above.
83
+ # set_enum.must.channel int_enum
24
84
  class ChannelConstraint < Gecode::Constraints::Constraint
25
85
  def post
26
86
  lhs, rhs, strength = @params.values_at(:lhs, :rhs, :strength)
@@ -16,9 +16,9 @@ module Gecode
16
16
  end
17
17
 
18
18
  # A module that gathers the classes and modules used in count constraints.
19
- module Gecode::Constraints::IntEnum::Count
19
+ module Gecode::Constraints::IntEnum::Count #:nodoc:
20
20
  # Describes an expression
21
- class Expression < Gecode::Constraints::IntEnum::Expression
21
+ class Expression < Gecode::Constraints::IntEnum::Expression #:nodoc:
22
22
  def initialize(model, params)
23
23
  super
24
24
  unless params[:negate]
@@ -47,7 +47,24 @@ module Gecode::Constraints::IntEnum::Count
47
47
  alias_comparison_methods
48
48
  end
49
49
 
50
- # Describes a count constraint.
50
+ # Describes a count constraint, which constrains the number of times a value
51
+ # (constant or a variable) may occurr in an enumeration of integer variable.
52
+ #
53
+ # All relations available for +SimpleRelationConstraint+ can be used with
54
+ # count constraints. Negation and reification is supported.
55
+ #
56
+ # == Examples
57
+ #
58
+ # # Constrain +int_enum+ to not contain 0 exactly once.
59
+ # int_enum.count(0).must_not == 1
60
+ #
61
+ # # Constrain +int_enum+ to contain +x+ exactly +x_count+ times.
62
+ # int_enum.count(x).must == x_count
63
+ #
64
+ # # Reifies the constraint that +int_enum+ has +x+ zeros with the boolean
65
+ # # variable +has_x_zeros+ and selects the strength +domain+.
66
+ # int_enum.count(0).must.equal(x, :reify => has_x_zeros,
67
+ # :strength => :domain)
51
68
  class CountConstraint < Gecode::Constraints::ReifiableConstraint
52
69
  def post
53
70
  lhs, element, relation_type, rhs, strength, reif_var =
@@ -32,8 +32,28 @@ module Gecode::Constraints::IntEnum
32
32
  end
33
33
 
34
34
  # A module that gathers the classes and modules used in distinct constraints.
35
- module Distinct
36
- # Describes a distinct constraint (optionally with offsets).
35
+ module Distinct #:nodoc:
36
+ # Describes a distinct constraint, which constrains all integer variables
37
+ # in an enumeration to be distinct (different). The constraint can also be
38
+ # used with constant offsets, so that the variables, with specified offsets
39
+ # added, must be distinct.
40
+ #
41
+ # The constraint does not support negation nor reification.
42
+ #
43
+ # == Examples
44
+ #
45
+ # # Constrains all variables in +int_enum+ to be assigned different
46
+ # # values.
47
+ # int_enum.must_be.distinct
48
+ #
49
+ # # The same as above, but also selects that the strength +domain+ should
50
+ # # be used.
51
+ # int_enum.must_be.distinct(:strength => :domain)
52
+ #
53
+ # # Uses the offset to constrain that no number may be the previous number
54
+ # # incremented by one.
55
+ # numbers = int_var_array(8, 0..9)
56
+ # numbers.with_offset((1..numbers.size).to_a.reverse).must_be.distinct
37
57
  class DistinctConstraint < Gecode::Constraints::Constraint
38
58
  def post
39
59
  # Bind lhs.
@@ -1,7 +1,26 @@
1
1
  # A module that gathers the classes and modules used by element constraints.
2
- module Gecode::Constraints::IntEnum::Element
3
- # Describes an expression stub started with an int var enum following with an
4
- # array access using an integer variables .
2
+ module Gecode::Constraints::IntEnum::Element #:nodoc:
3
+ # Describes a CompositeStub for the element constraint, which places a
4
+ # constraint on a variable at the specified position in an enumeration of
5
+ # integer variables. It's basically the array access of constraint
6
+ # programming.
7
+ #
8
+ # == Example
9
+ #
10
+ # # The variable at the +x+:th position in +int_enum+ must be larger than
11
+ # # +y+.
12
+ # int_enum[x].must > y
13
+ #
14
+ # # The price of +selected_item+ as described by +prices+ must not be
15
+ # # larger than 100.
16
+ # prices = wrap_enum([500, 24, 4711, 412, 24])
17
+ # prices[selected_item].must_not > 100
18
+ #
19
+ # # Reify the constraint that the +x+:th variable in +int_enum+ must be in
20
+ # # range 7..17 with the boolean variable +bool+ and select strength
21
+ # # +domain+.
22
+ #
23
+ # int_enum[x].must_be.in(7..17, :reify => bool, :strength => :domain)
5
24
  class ExpressionStub < Gecode::Constraints::Int::CompositeStub
6
25
  def constrain_equal(variable, params, constrain)
7
26
  enum, position, strength = @params.values_at(:lhs, :position, :strength)
@@ -17,7 +36,7 @@ module Gecode::Constraints::IntEnum::Element
17
36
  end
18
37
 
19
38
  # Methods needed to add support for element constraints to enums.
20
- module AdditionalEnumMethods
39
+ module AdditionalEnumMethods #:nodoc:
21
40
  # This adds the adder for the methods in the modules including it. The
22
41
  # reason for doing it so indirect is that the first #[] won't be defined
23
42
  # before the module that this is mixed into is mixed into an enum.
@@ -15,8 +15,15 @@ module Gecode::Constraints::IntEnum
15
15
  end
16
16
 
17
17
  # A module that gathers the classes and modules used in equality constraints.
18
- module Equality
19
- # Describes an equality constraint.
18
+ module Equality #:nodoc:
19
+ # Describes an equality constraint, which constrains all variables in an
20
+ # integer enumeration to be equal. Neither negation nor reification is
21
+ # supported.
22
+ #
23
+ # == Example
24
+ #
25
+ # # Constrains all variables in +int_enum+ to be equal.
26
+ # int_enum.must_be.equal
20
27
  class EqualityConstraint < Gecode::Constraints::Constraint
21
28
  def post
22
29
  # Bind lhs.
@@ -47,8 +47,22 @@ module Gecode::Constraints::IntEnum
47
47
  end
48
48
 
49
49
  # A module that gathers the classes and modules used in sort constraints.
50
- module Sort
51
- # Describes a sort constraint with target and order.
50
+ module Sort #:nodoc:
51
+ # Describes a sort constraint which constrains a target enumeration of
52
+ # integer variables to be the sorted version of another set of integer
53
+ # variables. Optionally a third enumeration may be used to define the order
54
+ # in which the the variables should be sorted.
55
+ #
56
+ # Neither negation nor reification is supported.
57
+ #
58
+ # == Example
59
+ #
60
+ # # Constrains +sorted_numbers+ to be a sorted version of +numbers+.
61
+ # numbers.must_be.sorted(:as => sorted_numbers)
62
+ #
63
+ # # Constrains +sorted_numbers+ to be +numbers+ sorted in the order
64
+ # # described by the integer variable enumeration +order+.
65
+ # numbers.must_be.sorted(:as => sorted_numbers, :order => order)
52
66
  class SortConstraintWithOptions < Gecode::Constraints::Constraint
53
67
  def post
54
68
  if @params[:target].nil?
@@ -70,7 +84,18 @@ module Gecode::Constraints::IntEnum
70
84
  end
71
85
  end
72
86
 
73
- # Describes a sort constraint.
87
+ # Describes a sort constraint which constrains an enumeration of integer
88
+ # variables to be sorted. Supports reification and negation.
89
+ #
90
+ # == Example
91
+ #
92
+ # # Constrains the variables in +int_enum+ to be sorted ascendingly.
93
+ # int_enum.must_be.sorted
94
+ #
95
+ # # Reifies the constraint that the variables in +int_enum+ to be sorted
96
+ # # ascendingly with the boolean variable +is_sorted+, while selecting
97
+ # # +domain+ as strength.
98
+ # int_enum.must_be.sorted(:reify => :is_sorted, :strength => :domain)
74
99
  class SortConstraint < Gecode::Constraints::ReifiableConstraint
75
100
  def post
76
101
  lhs, strength, reif_var = @params.values_at(:lhs, :strength, :reif)
@@ -15,7 +15,7 @@ module Gecode
15
15
  # variables as left hand side.
16
16
  module Constraints::IntEnum
17
17
  # Expressions with int enums as left hand sides.
18
- class Expression < Gecode::Constraints::Expression
18
+ class Expression < Gecode::Constraints::Expression #:nodoc:
19
19
  # Raises TypeError unless the left hand side is an int enum.
20
20
  def initialize(model, params)
21
21
  super
@@ -14,12 +14,13 @@ module Gecode
14
14
  # A module containing constraints that have int variables as left hand side
15
15
  # (but not enumerations).
16
16
  module Constraints::Int
17
- class Expression < Gecode::Constraints::Expression
17
+ # Describes an integer expression.
18
+ class Expression < Gecode::Constraints::Expression #:nodoc:
18
19
  end
19
20
 
20
21
  # A composite expression which is an int expression with a left hand side
21
22
  # resulting from a previous constraint.
22
- class CompositeExpression < Gecode::Constraints::CompositeExpression
23
+ class CompositeExpression < Gecode::Constraints::CompositeExpression #:nodoc:
23
24
  # The block given should take three parameters. The first is the variable
24
25
  # that should be the left hand side, if it's nil then a new one should be
25
26
  # created. The second is the has of parameters. The block should return
@@ -30,16 +31,20 @@ module Gecode
30
31
  end
31
32
  end
32
33
 
33
- # Describes a stub that produces an int variable, which can then be used with
34
- # the normal int variable constraints. An example would be the element
34
+ # Describes a stub that produces an int variable, which can then be used
35
+ # with the normal int variable constraints. An example would be the element
35
36
  # constraint.
36
37
  #
37
38
  # int_enum[int_var].must > rhs
38
39
  #
39
- # The int_enum[int_var] part produces an int variable which the constraint
40
- # ".must > rhs" is then applied to. In the above case two constraints (and
41
- # one temporary variable) are required, but in the case of equality only
42
- # one constraint is required.
40
+ # <tt>int_enum[int_var]</tt> produces an int variable which the constraint
41
+ # <tt>.must > rhs</tt> is then applied to. In the above case two
42
+ # constraints (and one temporary variable) are required, but in the case of
43
+ # equality only one constraint is required.
44
+ #
45
+ # Whether a constraint involving a reification stub supports negation,
46
+ # reification, strength options and so on depends on the constraint on the
47
+ # right hand side.
43
48
  class CompositeStub < Gecode::Constraints::CompositeStub
44
49
  def initialize(model, params)
45
50
  super(CompositeExpression, model, params)
@@ -3,7 +3,8 @@ module Gecode
3
3
  # Starts a constraint on the size of the set.
4
4
  def size
5
5
  params = {:lhs => self}
6
- Gecode::Constraints::Set::Cardinality::SizeExpressionStub.new(@model, params)
6
+ Gecode::Constraints::Set::Cardinality::SizeExpressionStub.new(
7
+ @model, params)
7
8
  end
8
9
  end
9
10
  end
@@ -11,9 +12,11 @@ end
11
12
  module Gecode::Constraints::Set
12
13
  # A module that gathers the classes and modules used in cardinality
13
14
  # constraints.
14
- module Cardinality
15
- # Describes a cardinality constraint.
16
- class CardinalityConstraint < Gecode::Constraints::Constraint
15
+ module Cardinality #:nodoc:
16
+ # Describes a cardinality constraint specifically for ranges. This is just
17
+ # a special case which is used instead of the more general composite
18
+ # constraint when the target cardinality is a range.
19
+ class CardinalityConstraint < Gecode::Constraints::Constraint #:nodoc:
17
20
  def post
18
21
  var, range = @params.values_at(:lhs, :range)
19
22
  Gecode::Raw::cardinality(@model.active_space, var.bind, range.first,
@@ -22,14 +25,14 @@ module Gecode::Constraints::Set
22
25
  end
23
26
 
24
27
  # A custom composite stub to change the composite expression used.
25
- class CompositeStub < Gecode::Constraints::CompositeStub
28
+ class CompositeStub < Gecode::Constraints::CompositeStub #:nodoc:
26
29
  def initialize(model, params)
27
30
  super(Expression, model, params)
28
31
  end
29
32
  end
30
33
 
31
34
  # Describes a cardinality expression started with set.size.must .
32
- class Expression < Gecode::Constraints::Int::CompositeExpression
35
+ class Expression < Gecode::Constraints::Int::CompositeExpression #:nodoc:
33
36
  def in(range)
34
37
  if range.kind_of?(Range) and !@params[:negate]
35
38
  @params.update(:range => range)
@@ -40,8 +43,24 @@ module Gecode::Constraints::Set
40
43
  end
41
44
  end
42
45
 
43
- # Describes an expression stub started with a set variable followed by
44
- # #size .
46
+ # Describes a CompositeStub for the cardianlity constraint which constrains
47
+ # the cardianlity (size) of a set.
48
+ #
49
+ # == Example
50
+ #
51
+ # # The size of +set+ must be within 1..17
52
+ # set.size.must_be.in 1..17
53
+ #
54
+ # # The size must equal the integer variable +size+.
55
+ # set.size.must == size
56
+ #
57
+ # # The size must not be larger than 17
58
+ # set.size.must_not > 17
59
+ #
60
+ # # We reify the above with a boolean variable called +is_not_large+ and
61
+ # # select the strength +domain+.
62
+ # set.size.must_not_be.larger_than(17, :reify => is_not_large,
63
+ # :strength => :domain)
45
64
  class SizeExpressionStub < CompositeStub
46
65
  def constrain_equal(variable, params, constrain)
47
66
  lhs = @params[:lhs]
@@ -68,8 +68,27 @@ module Gecode::Constraints::Set
68
68
 
69
69
  # A module that gathers the classes and modules used in connection
70
70
  # constraints.
71
- module Connection
72
- # Describes an expression stub started with an int var following by #min.
71
+ module Connection #:nodoc:
72
+ # Describes a CompositeStub for the min constraint which constrains the
73
+ # minimum value of a set variable.
74
+ #
75
+ # == Examples
76
+ #
77
+ # # Constrains the minimum value of +set+ to be larger than 17.
78
+ # set.min.must > 17
79
+ #
80
+ # # Constrains the minimum value of +set+ to equal the integer variable
81
+ # # +min+.
82
+ # set.min.must == min
83
+ #
84
+ # # Constrains the minimum value of +set+ to not be larger than the
85
+ # # integer variable +ceil+.
86
+ # set.min.must_not > ceil
87
+ #
88
+ # # The same as above but reified with the boolean variable
89
+ # # +is_not_above_ceiling+ and with the strength +domain+ applied.
90
+ # set.min.must_not_be.larger_than(ceil, :reify => :is_not_above_ceiling,
91
+ # :strength => :domain)
73
92
  class MinExpressionStub < Gecode::Constraints::Int::CompositeStub
74
93
  def constrain_equal(variable, params, constrain)
75
94
  set = params[:lhs]
@@ -81,7 +100,26 @@ module Gecode::Constraints::Set
81
100
  end
82
101
  end
83
102
 
84
- # Describes an expression stub started with an int var following by #max.
103
+ # Describes a CompositeStub for the max constraint which constrains the
104
+ # maximum value of a set variable.
105
+ #
106
+ # == Examples
107
+ #
108
+ # # Constrains the maximum value of +set+ to be larger than 17.
109
+ # set.max.must > 17
110
+ #
111
+ # # Constrains the maximum value of +set+ to equal the integer variable
112
+ # # +max+.
113
+ # set.max.must == max
114
+ #
115
+ # # Constrains the maximum value of +set+ to not be less than the
116
+ # # integer variable +floor+.
117
+ # set.max.must_not < floor
118
+ #
119
+ # # The same as above but reified with the boolean variable
120
+ # # +is_not_below_floor+ and with the strength +domain+ applied.
121
+ # set.max.must_not_be.less_than(ceil, :reify => :is_not_below_floor,
122
+ # :strength => :domain)
85
123
  class MaxExpressionStub < Gecode::Constraints::Int::CompositeStub
86
124
  def constrain_equal(variable, params, constrain)
87
125
  set = params[:lhs]
@@ -93,7 +131,26 @@ module Gecode::Constraints::Set
93
131
  end
94
132
  end
95
133
 
96
- # Describes an expression stub started with an int var following by #max.
134
+ # Describes a CompositeStub for the sum constraint which constrains the
135
+ # sum of all values in a set variable.
136
+ #
137
+ # == Examples
138
+ #
139
+ # # Constrains the sum of all values in +set+ to be larger than 17.
140
+ # set.sum.must > 17
141
+ #
142
+ # # Constrains the sum of all values in +set+ to equal the integer
143
+ # # variable +sum+.
144
+ # set.sum.must == sum
145
+ #
146
+ # # Constrains the sum of all values in +set+ to not be larger than the
147
+ # # integer variable +resources+.
148
+ # set.sum.must_not > resources
149
+ #
150
+ # # The same as above but reified with the boolean variable
151
+ # # +not_over_budget+ and with the strength +domain+ applied.
152
+ # set.sum.must_not_be.larger_than(resources, :reify => :not_over_budget,
153
+ # :strength => :domain)
97
154
  class SumExpressionStub < Gecode::Constraints::Int::CompositeStub
98
155
  def constrain_equal(variable, params, constrain)
99
156
  set, subs = params.values_at(:lhs, :substitutions)
@@ -114,8 +171,17 @@ module Gecode::Constraints::Set
114
171
  end
115
172
  end
116
173
 
117
- # Describes a constraint that constrains a set to include a number of
118
- # integer variables.
174
+ # Describes an include constraint, which constrains the set to include the
175
+ # values of the specified enumeration of integer variables.
176
+ #
177
+ # The constraint has the side effect of sorting the integer variables in a
178
+ # non-descending order. It does not support reification nor negation.
179
+ #
180
+ # == Examples
181
+ #
182
+ # # Constrain +set+ to include the values of all variables in
183
+ # # +int_enum+.
184
+ # set.must.include int_enum
119
185
  class IncludeConstraint < Gecode::Constraints::Constraint
120
186
  def post
121
187
  set, variables = @params.values_at(:lhs, :variables)