class Gecode::Bool::BoolConstraintReceiver
BoolConstraintReceiver contains all constraints that can be placed on a BoolOperand.
Constraints are placed by calling Gecode::Operand#must (or any other of the variations defined in Operand), which produces a BoolConstraintReceiver from which the desired constraint can be used.
Each constraint accepts a number of options. See ConstraintReceiver for more information.
Examples ¶ ↑
Constrains bool_operand
to be true using #true:
bool_operand.must_be.true
Constrains bool_operand1
AND bool_operand2
to be
true using the BoolOperand#& property and #true:
(bool_operand1 & bool_operand2).must_be.true
Constrains the conjunction of all boolean operands in
bool_enum
to not imply bool_operand
using the BoolEnumOperand#conjunction property and #imply:
bool_enum.conjunction.must_not.imply bool_operand
The same as above, but specifying that strength :domain should be used and
that the constraint should be reified with bool_operand2
:
bool_enum.conjunction.must_not.imply(bool_operand, :strength => :domain, :reify => bool_operand2)
Public Instance Methods
Constrains the boolean operand to be equal to bool_op
. Any of
==
, equal
and equal_to
may be used
for equality.
Examples ¶ ↑
# +b1+ and +b2+ must equal +b1+ or +b2+. (b1 & b2).must == (b1 | b2) # +b1+ and +b2+ must not equal +b3+. We reify it with +bool+ and select # the strength +domain+. (b1 & b2).must_not.equal(b3, :reify => bool, :select => :domain)
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/bool/boolean.rb, line 72 def ==(bool_op, options = {}) unless bool_op.respond_to? :to_minimodel_bool_expr bool_op = ExpressionNode.new(bool_op, @model) end @params.update Gecode::Util.decode_options(options) @params.update(:lhs => @params[:lhs], :rhs => bool_op) @model.add_constraint BooleanConstraint.new(@model, @params) end
Constrains the boolean operand to be false.
Examples ¶ ↑
# +b1+ and +b2+ must be false. (b1 & b2).must_be.false # (+b1+ implies +b2+) and (+b3+ implies +b2+) must be false. ((b1.implies b2) & (b3.implies b2)).must_be.false # +b1+ and +b2+ must be false. We reify it with +bool+ and select the # strength +domain+. (b1 & b2).must_be.false(:reify => bool, :strength => :domain)
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/bool/boolean.rb, line 130 def false(options = {}) @params[:negate] = !@params[:negate] self.true(options) end
Constrains the boolean operand to imply bool_op
.
Examples ¶ ↑
# +b1+ must imply +b2+ b1.must.imply b2 # +b1+ and +b2+ must not imply +b3+. We reify it with +bool+ and select # +domain+ as strength. (b1 & b2).must_not.imply(b3, :reify => bool, :strength => :domain)
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/bool/boolean.rb, line 92 def imply(bool_op, options = {}) @params.update Gecode::Util.decode_options(options) @params.update(:lhs => @params[:lhs].implies(bool_op), :rhs => true) @model.add_constraint BooleanConstraint.new(@model, @params) end
Constrains the boolean operand to be true.
Examples ¶ ↑
# +b1+ and +b2+ must be true. (b1 & b2).must_be.true # (+b1+ implies +b2+) and (+b3+ implies +b2+) must be true. ((b1.implies b2) & (b3.implies b2)).must_be.true # +b1+ and +b2+ must be true. We reify it with +bool+ and select the # strength +domain+. (b1 & b2).must_be.true(:reify => bool, :strength => :domain)
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/bool/boolean.rb, line 111 def true(options = {}) @params.update Gecode::Util.decode_options(options) @model.add_constraint BooleanConstraint.new(@model, @params.update(:rhs => true)) end
Public Class Methods
Raises TypeError unless the left hand side is an bool operand.
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/bool_var_constraints.rb, line 86 def initialize(model, params) super unless params[:lhs].respond_to? :to_bool_var raise TypeError, 'Must have bool operand as left hand side.' end end