Class: LV

Inherits:
Object show all
Includes:
Rulp::Bounds, Rulp::Initializers
Defined in:
lib/rulp/lv.rb

Overview

An LP Variable. Used as arguments in LP Expressions. The subtypes BV and IV represent Binary and Integer variables. These are constructed dynamically by using the special Capitalised variable declaration syntax.

Direct Known Subclasses

BV, IV

Constant Summary

Constants included from Rulp::Bounds

Rulp::Bounds::DIRS, Rulp::Bounds::DIRS_REVERSED

Instance Attribute Summary collapse

Attributes included from Rulp::Bounds

#const

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rulp::Initializers

included, #initialize, #to_s

Methods included from Rulp::Bounds

#<, #<=, #==, #>, #>=, #bounds, #coerce, #coerced?, #nocoerce, #relative_constraint

Instance Attribute Details

#gtObject

Returns the value of attribute gt.



8
9
10
# File 'lib/rulp/lv.rb', line 8

def gt
  @gt
end

#gteObject

Returns the value of attribute gte.



8
9
10
# File 'lib/rulp/lv.rb', line 8

def gte
  @gte
end

#ltObject

Returns the value of attribute lt.



8
9
10
# File 'lib/rulp/lv.rb', line 8

def lt
  @lt
end

#lteObject

Returns the value of attribute lte.



8
9
10
# File 'lib/rulp/lv.rb', line 8

def lte
  @lte
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rulp/lv.rb', line 7

def name
  @name
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/rulp/lv.rb', line 8

def value
  @value
end

Class Method Details

.const_missing(name) ⇒ Object



28
29
30
# File 'lib/rulp/lv.rb', line 28

def self.const_missing(name)
  return self.definition(name)
end

.definition(name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rulp/lv.rb', line 32

def self.definition(name)
  self.class.send(:define_method, name){
    defined = LV::names_table["#{name}"]
    if defined && defined.class != self
      raise StandardError.new("ERROR:\n#{name} was already defined as a variable of type #{defined.class}."+
                              "You are trying to redefine it as a variable of type #{self}")
    elsif(!defined)
      self.new(name)
    else
      defined
    end
  }
  return self.send(name) || self.new(name)
end

.method_missing(name, *args) ⇒ Object



24
25
26
# File 'lib/rulp/lv.rb', line 24

def self.method_missing(name, *args)
  return self.definition( "#{name}#{args.join("_")}" )
end

Instance Method Details

#*(numeric) ⇒ Object



47
48
49
50
# File 'lib/rulp/lv.rb', line 47

def * (numeric)
  self.nocoerce
  Expressions.new([Fragment.new(self, numeric)])
end

#+(expressions) ⇒ Object



60
61
62
# File 'lib/rulp/lv.rb', line 60

def + (expressions)
  Expressions[self] + Expressions[expressions]
end

#-(other) ⇒ Object



56
57
58
# File 'lib/rulp/lv.rb', line 56

def -(other)
  self + (-other)
end

#-@Object



52
53
54
# File 'lib/rulp/lv.rb', line 52

def -@
  return self * -1
end

#inspectObject



75
76
77
# File 'lib/rulp/lv.rb', line 75

def inspect
  "#{name}(#{suffix})[#{value || 'undefined'}]"
end

#meth(*args) ⇒ Object



16
17
18
# File 'lib/rulp/lv.rb', line 16

def meth(*args)
  "#{self.name}#{args.join("_")}_#{self.suffix}"
end

#suffixObject



20
21
22
# File 'lib/rulp/lv.rb', line 20

def suffix
  "f"
end

#to_procObject



12
13
14
# File 'lib/rulp/lv.rb', line 12

def to_proc
  ->(index){ send(self.meth(index)) }
end