Class: Gecode::ConstraintReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/gecoder/interface/constraints.rb

Overview

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:

operand.must.constraint_method(params)

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:

:strength

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

Value consistency (naive).

:bounds

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

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

:default

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.

:kind

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

The different kinds are:

:speed

Prefer speed over memory consumption.

:memory

Prefer low memory consumption over speed.

:default

Uses the constraint’s default propagation kind.

:reify

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.

Instance Method Summary collapse

Constructor Details

#initialize(model, params) ⇒ ConstraintReceiver

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.



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/gecoder/interface/constraints.rb', line 128

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(', ')}."
  end
  unless params[:lhs].kind_of? Operand
    raise ArgumentError, 'Expected :lhs to be an operand, received ' + 
      "#{params[:lhs].class}."
  end
  
  @model = model
  @params = params
end