Module: Gecode::Bool::BoolOperand
- Includes:
- BoolLinearOperations, Operand
- Included in:
- ExpressionTree, ShortCircuitEqualityOperand, Gecode::BoolVar
- Defined in:
- lib/gecoder/interface/constraints/bool_var_constraints.rb,
lib/gecoder/interface/constraints/bool/linear.rb,
lib/gecoder/interface/constraints/bool/boolean.rb
Overview
A BoolOperand is a combination of variables on which the constraints defined in BoolConstraintReceiver can be placed.
Boolean operands can be created either by using Gecode::Mixin#bool_var et al, or by using properties that produce boolean operands. The operands, no matter how they were created, all respond to the properties defined by BoolOperand.
Examples
Produces a single boolean operand (more specifically a BoolVar) inside a problem formulation, using Gecode::Mixin#bool_var:
bool_operand = bool_var
Uses the BoolOperand#& property to produce a new boolean operand representing bool_operand1
AND bool_operand2
:
new_bool_operand = bool_operand1 & bool_operand2
Uses the BoolEnumOperand#conjunction property to produce a new boolean operand representing the conjunction of all boolean operands in the enumeration bool_enum
:
new_bool_operand = bool_enum.conjunction
– Classes that mix in BoolOperand must define #model and #to_bool_var .
Instance Method Summary collapse
-
#&(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand AND
bool_op
. -
#*(fixnum) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) times a constant.
-
#+(op2) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) plus
op2
. -
#-(op2) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) minus
op2
. -
#^(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand XOR
bool_op
. -
#implies(bool_op) ⇒ Object
Produces a new BoolOperand representing that this operand implies
bool_op
. -
#method_missing(method, *args) ⇒ Object
:nodoc:.
-
#|(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand OR
bool_op
.
Methods included from Operand
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
:nodoc:
35 36 37 38 39 40 41 42 |
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 35 def method_missing(method, *args) #:nodoc: if Gecode::BoolVar.instance_methods.include? method.to_s # Delegate to the bool var. to_bool_var.method(method).call(*args) else super end end |
Instance Method Details
#&(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand AND bool_op
.
Examples
# (+b1+ and +b2+) or +b3+
(b1 & b1) | b3
19 20 21 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 19 def &(bool_op) bool_expression_operation(:&, bool_op) end |
#*(fixnum) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) times a constant.
Examples
# +bool+ times 17
bool * 17
80 81 82 83 84 85 86 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 80 def *(fixnum) if fixnum.kind_of? Fixnum bool_linear_expression_operation(:*, fixnum) else raise TypeError, "Expected fixnum, got #{fixnum.class}." end end |
#+(op2) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) plus op2
.
Examples
# +bool1+ plus +bool2+
bool1 + bool2
69 70 71 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 69 def +(op2) bool_linear_expression_operation(:+, op2) end |
#-(op2) ⇒ Object
Produces an IntOperand representing the value of this boolean operand (0 or 1) minus op2
.
Examples
# +bool1+ minus +bool2+
bool1 - bool2
95 96 97 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 95 def -(op2) bool_linear_expression_operation(:-, op2) end |
#^(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand XOR bool_op
.
Examples
# (+b1+ and +b2+) or (+b3+ exclusive or +b1+)
(b1 & b2) | (b3 ^ b1)
29 30 31 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 29 def ^(bool_op) bool_expression_operation(:^, bool_op) end |
#implies(bool_op) ⇒ Object
Produces a new BoolOperand representing that this operand implies bool_op
.
Examples
# (+b1+ implies +b2+) and (+b3+ implies +b2+)
(b1.implies b2) & (b3.implies b2)
40 41 42 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 40 def implies(bool_op) bool_expression_operation(:implies, bool_op) end |
#|(bool_op) ⇒ Object
Produces a new BoolOperand representing this operand OR bool_op
.
Examples
# +b1+ and +b2+
b1 & b2
9 10 11 |
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 9 def |(bool_op) bool_expression_operation(:|, bool_op) end |