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

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#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, args) ⇒ Object



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

def self.definition(name, args)
  identifier = "#{name}#{args.join("_")}"
  self.class.send(:define_method, identifier){|index=nil|
    if index
      self.definition(name, index)
    else
      defined = LV::names_table["#{identifier}"]
      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, args)
      else
        defined
      end
    end
  }
  return self.send(identifier) || self.new(name, args)
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)
end

Instance Method Details

#*(numeric) ⇒ Object



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

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

#+(expressions) ⇒ Object



65
66
67
# File 'lib/rulp/lv.rb', line 65

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

#-(other) ⇒ Object



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

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

#-@Object



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

def -@
  return self * -1
end

#inspectObject



80
81
82
# File 'lib/rulp/lv.rb', line 80

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

#methObject



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

def meth
  "#{self.name}_#{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