class Gecode::ConstraintReceiver

Describes a constraint receiver, something that receives and places constraints on various Operand. Constraint receivers are created by calling must or must_not (the latter negates the constraint) on something that mixes in Operand.

A constraint is placed on an Operand operand as follows:


The constraint receiver is created by the call to must and the constraint is then placed by the call to constraint_method. See e.g. Gecode::Int::IntConstraintReceiver for concrete examples.

The following options can be specified in a hash with symbols as keys when placing a constraint:


The propagation strength suggests how much effort the solver should put into trying to prune the domains of variables using the constraint.

The allowed values are:


Value consistency (naive).


Bounds consistency. The bounds of the operand will always be constrained as much as possible (but pruning may not be done inside the bounds, even though it may be possible).


Domain consistency. All values that can be pruned away, given the current amount of information, are pruned away.


Uses the default consistency of the constraint.

The strength generally progresses as :value < :bounds < :domain (:value being the weakest, :domain being the strongest). A higher strength can reduce the search space quicker, but at the cost of making each propagation more costly.


The propagation kind option suggests the implementation that should be preferred if there are multiple implementations of a constraint.

The different kinds are:


Prefer speed over memory consumption.


Prefer low memory consumption over speed.


Uses the constraint’s default propagation kind.


Reification is used to link a constraint to a boolean operand in such a way that the variable is true if and only if the constraint is satisfied. The propagation goes both ways, so if the variable is constrained to be false then the constraint is not allowed to be satisfied.

Reification can be thought of as a last resort glue which can be used to combine constraints so that e.g. exactly 3 out of 17 constraints must be satisfied.

Not all constraints accept all options. Constraints that have sets as operands (e.g. SetConstraintReceiver and SetEnumConstraintReceiver) do not accept the :strength and :kind options, all other do. Some constraints do not accept the :reify option.

See e.g. Gecode::Int::IntConstraintReceiver for concrete examples of options being specified.

Public Class Methods

new(model, params) click to toggle source

Constructs a new expression with the specified parameters. The parameters should at least contain the keys :lhs, and :negate.

Raises ArgumentError if any of those keys are missing or if :lhs is not an operand.

# File lib/gecoder/interface/constraints.rb, line 132
def initialize(model, params)
  unless params.has_key?(:lhs) and params.has_key?(:negate)
    raise ArgumentError, 'Expression requires at least :lhs, ' + 
      "and :negate as parameter keys, got #{params.keys.join(', ')}."
  unless params[:lhs].kind_of? Operand
    raise ArgumentError, 'Expected :lhs to be an operand, received ' + 
  @model = model
  @params = params