Module: ORTools::ExpressionMethods
- Included in:
- Expression, Variable
- Defined in:
- lib/or_tools/expression.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
-
#coerce(other) ⇒ Object
keep order.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #vars ⇒ Object
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
3 4 5 |
# File 'lib/or_tools/expression.rb', line 3 def parts @parts end |
Instance Method Details
#!=(other) ⇒ Object
41 42 43 |
# File 'lib/or_tools/expression.rb', line 41 def !=(other) Comparison.new(self, :!=, other) end |
#*(other) ⇒ Object
17 18 19 |
# File 'lib/or_tools/expression.rb', line 17 def *(other) Expression.new([Product.new(self, Expression.to_expression(other))]) end |
#+(other) ⇒ Object
5 6 7 |
# File 'lib/or_tools/expression.rb', line 5 def +(other) Expression.new((parts || [self]) + [Expression.to_expression(other)]) end |
#-(other) ⇒ Object
9 10 11 |
# File 'lib/or_tools/expression.rb', line 9 def -(other) Expression.new((parts || [self]) + [-Expression.to_expression(other)]) end |
#-@ ⇒ Object
13 14 15 |
# File 'lib/or_tools/expression.rb', line 13 def -@ -1 * self end |
#<(other) ⇒ Object
25 26 27 |
# File 'lib/or_tools/expression.rb', line 25 def <(other) Comparison.new(self, :<, other) end |
#<=(other) ⇒ Object
33 34 35 |
# File 'lib/or_tools/expression.rb', line 33 def <=(other) Comparison.new(self, :<=, other) end |
#==(other) ⇒ Object
37 38 39 |
# File 'lib/or_tools/expression.rb', line 37 def ==(other) Comparison.new(self, :==, other) end |
#>(other) ⇒ Object
21 22 23 |
# File 'lib/or_tools/expression.rb', line 21 def >(other) Comparison.new(self, :>, other) end |
#>=(other) ⇒ Object
29 30 31 |
# File 'lib/or_tools/expression.rb', line 29 def >=(other) Comparison.new(self, :>=, other) end |
#coerce(other) ⇒ Object
keep order
54 55 56 57 58 59 60 |
# File 'lib/or_tools/expression.rb', line 54 def coerce(other) if other.is_a?(Numeric) [Constant.new(other), self] else raise TypeError, "#{self.class} can't be coerced into #{other.class}" end end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/or_tools/expression.rb', line 45 def inspect @parts.reject { |v| v.is_a?(Constant) && v.value == 0 }.map(&:inspect).join(" + ").gsub(" + -", " - ") end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/or_tools/expression.rb', line 49 def to_s inspect end |
#vars ⇒ Object
62 63 64 |
# File 'lib/or_tools/expression.rb', line 62 def vars @vars ||= @parts.flat_map(&:vars) end |