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.



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

def args
  @args
end

#gtObject

Returns the value of attribute gt.



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

def gt
  @gt
end

#gteObject

Returns the value of attribute gte.



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

def gte
  @gte
end

#ltObject

Returns the value of attribute lt.



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

def lt
  @lt
end

#lteObject

Returns the value of attribute lte.



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

def lte
  @lte
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#valueObject



60
61
62
63
64
65
66
67
# File 'lib/rulp/lv.rb', line 60

def value
  return nil unless @value
  case self
  when BV then @value.round(2) == 1
  when IV then @value
  else @value
  end
end

Class Method Details

.definition(name, *args) ⇒ Object



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

def self.definition(name, *args)
  identifier = "#{name}#{args.join("_")}"
  defined = LV::names_table["#{identifier}"]
  case defined
  when self then defined
  when nil then self.new(name, args)
  else 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}")
  end
end

.suffixObject



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

def self.suffix
  ENV['RULP_LV_SUFFIX'] || "f"
end

Instance Method Details

#*(numeric) ⇒ Object



43
44
45
46
# File 'lib/rulp/lv.rb', line 43

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

#+(expressions) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#-@Object



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

def -@
  return self * -1
end

#inspectObject



73
74
75
# File 'lib/rulp/lv.rb', line 73

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

#methObject



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

def meth
  "#{self.name}_#{self.suffix}"
end

#suffixObject



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

def suffix
  self.class.suffix
end

#to_procObject



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

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

#value?Boolean Also known as: selected?

Returns:

  • (Boolean)


69
70
71
# File 'lib/rulp/lv.rb', line 69

def value?
  value ? value : false
end