Class: Gecode::Bool::BoolConstraintReceiver
- Inherits:
-
ConstraintReceiver
- Object
- ConstraintReceiver
- Gecode::Bool::BoolConstraintReceiver
- Defined in:
- lib/gecoder/interface/constraints/bool_var_constraints.rb,
lib/gecoder/interface/constraints/bool/boolean.rb,
lib/gecoder/interface/constraints/bool/channel.rb
Overview
BoolConstraintReceiver contains all constraints that can be placed on a BoolOperand.
Constraints are placed by calling BoolOperand#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
BoolConstraintReceiver#true:
bool_operand.must_be.true
Constrains bool_operand1 AND bool_operand2 to be true using
the BoolOperand#& property and BoolConstraintReceiver#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 BoolConstraintReceiver#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)
Instance Method Summary collapse
-
#==(bool_op, options = {}) ⇒ Object
Constrains the boolean operand to be equal to
bool_op. -
#false(options = {}) ⇒ Object
Constrains the boolean operand to be false.
-
#imply(bool_op, options = {}) ⇒ Object
Constrains the boolean operand to imply
bool_op. -
#initialize(model, params) ⇒ BoolConstraintReceiver
constructor
Raises TypeError unless the left hand side is an bool operand.
-
#true(options = {}) ⇒ Object
Constrains the boolean operand to be true.
Constructor Details
#initialize(model, params) ⇒ BoolConstraintReceiver
Raises TypeError unless the left hand side is an bool operand.
86 87 88 89 90 91 92 |
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 86 def initialize(model, params) #:nodoc: super unless params[:lhs].respond_to? :to_bool_var raise TypeError, 'Must have bool operand as left hand side.' end end |
Instance Method Details
#==(bool_op, options = {}) ⇒ Object
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)
72 73 74 75 76 77 78 79 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 72 def ==(bool_op, = {}) unless bool_op.respond_to? :to_minimodel_bool_expr bool_op = ExpressionNode.new(bool_op, @model) end @params.update Gecode::Util.() @params.update(:lhs => @params[:lhs], :rhs => bool_op) @model.add_constraint BooleanConstraint.new(@model, @params) end |
#false(options = {}) ⇒ Object
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)
130 131 132 133 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 130 def false( = {}) @params[:negate] = !@params[:negate] self.true() end |
#imply(bool_op, options = {}) ⇒ Object
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)
92 93 94 95 96 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 92 def imply(bool_op, = {}) @params.update Gecode::Util.() @params.update(:lhs => @params[:lhs].implies(bool_op), :rhs => true) @model.add_constraint BooleanConstraint.new(@model, @params) end |
#true(options = {}) ⇒ Object
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)
111 112 113 114 115 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 111 def true( = {}) @params.update Gecode::Util.() @model.add_constraint BooleanConstraint.new(@model, @params.update(:rhs => true)) end |