Class: LV
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
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
included, #initialize, #to_s
#<, #<=, #==, #>, #>=, #bounds, #coerce, #coerced?, #nocoerce, #relative_constraint
Instance Attribute Details
Returns the value of attribute args.
9
10
11
|
# File 'lib/rulp/lv.rb', line 9
def args
@args
end
|
Returns the value of attribute gt.
11
12
13
|
# File 'lib/rulp/lv.rb', line 11
def gt
@gt
end
|
Returns the value of attribute gte.
11
12
13
|
# File 'lib/rulp/lv.rb', line 11
def gte
@gte
end
|
Returns the value of attribute lt.
11
12
13
|
# File 'lib/rulp/lv.rb', line 11
def lt
@lt
end
|
Returns the value of attribute lte.
11
12
13
|
# File 'lib/rulp/lv.rb', line 11
def lte
@lte
end
|
Returns the value of attribute name.
9
10
11
|
# File 'lib/rulp/lv.rb', line 9
def name
@name
end
|
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
|
24
25
26
|
# File 'lib/rulp/lv.rb', line 24
def self.suffix
ENV['RULP_LV_SUFFIX'] || "f"
end
|
Instance Method Details
52
53
54
|
# File 'lib/rulp/lv.rb', line 52
def -(other)
self + (-other)
end
|
48
49
50
|
# File 'lib/rulp/lv.rb', line 48
def -@
return self * -1
end
|
73
74
75
|
# File 'lib/rulp/lv.rb', line 73
def inspect
"#{name}#{args.join("-")}(#{suffix})[#{value.nil? ? 'undefined' : value }]"
end
|
20
21
22
|
# File 'lib/rulp/lv.rb', line 20
def meth
"#{self.name}_#{self.suffix}"
end
|
28
29
30
|
# File 'lib/rulp/lv.rb', line 28
def suffix
self.class.suffix
end
|
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?
69
70
71
|
# File 'lib/rulp/lv.rb', line 69
def value?
value ? value : false
end
|