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
|
56
57
58
59
60
61
62
63
|
# File 'lib/rulp/lv.rb', line 56
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
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/rulp/lv.rb', line 28
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
|
Instance Method Details
#*(numeric) ⇒ Object
39
40
41
42
|
# File 'lib/rulp/lv.rb', line 39
def * (numeric)
self.nocoerce
Expressions.new([Fragment.new(self, numeric)])
end
|
#+(expressions) ⇒ Object
52
53
54
|
# File 'lib/rulp/lv.rb', line 52
def + (expressions)
Expressions[self] + Expressions[expressions]
end
|
48
49
50
|
# File 'lib/rulp/lv.rb', line 48
def -(other)
self + (-other)
end
|
44
45
46
|
# File 'lib/rulp/lv.rb', line 44
def -@
return self * -1
end
|
69
70
71
|
# File 'lib/rulp/lv.rb', line 69
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
|
24
25
26
|
# File 'lib/rulp/lv.rb', line 24
def suffix
"f"
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?
65
66
67
|
# File 'lib/rulp/lv.rb', line 65
def value?
value ? value : false
end
|