Class: BinPacking::Score
- Inherits:
-
Object
- Object
- BinPacking::Score
- Includes:
- Comparable
- Defined in:
- lib/bin_packing/score.rb
Constant Summary collapse
- MAX_INT =
(2**(0.size * 8 -2) -1)
Instance Attribute Summary collapse
-
#score_1 ⇒ Object
readonly
Returns the value of attribute score_1.
-
#score_2 ⇒ Object
readonly
Returns the value of attribute score_2.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Smaller number is greater (used by original algorithm).
- #assign(other) ⇒ Object
- #decrease_by(delta) ⇒ Object
-
#initialize(score_1 = nil, score_2 = nil) ⇒ Score
constructor
A new instance of Score.
- #is_blank? ⇒ Boolean
Constructor Details
Instance Attribute Details
#score_1 ⇒ Object (readonly)
Returns the value of attribute score_1.
7 8 9 |
# File 'lib/bin_packing/score.rb', line 7 def score_1 @score_1 end |
#score_2 ⇒ Object (readonly)
Returns the value of attribute score_2.
7 8 9 |
# File 'lib/bin_packing/score.rb', line 7 def score_2 @score_2 end |
Class Method Details
.new_blank ⇒ Object
9 10 11 |
# File 'lib/bin_packing/score.rb', line 9 def self.new_blank new end |
Instance Method Details
#<=>(other) ⇒ Object
Smaller number is greater (used by original algorithm).
19 20 21 22 23 24 25 26 27 |
# File 'lib/bin_packing/score.rb', line 19 def <=>(other) if self.score_1 > other.score_1 || (self.score_1 == other.score_1 && self.score_2 > other.score_2) -1 elsif self.score_1 < other.score_1 || (self.score_1 == other.score_1 && self.score_2 < other.score_2) 1 else 0 end end |
#assign(other) ⇒ Object
29 30 31 32 |
# File 'lib/bin_packing/score.rb', line 29 def assign(other) @score_1 = other.score_1 @score_2 = other.score_2 end |
#decrease_by(delta) ⇒ Object
38 39 40 41 |
# File 'lib/bin_packing/score.rb', line 38 def decrease_by(delta) @score_1 += delta @score_2 += delta end |
#is_blank? ⇒ Boolean
34 35 36 |
# File 'lib/bin_packing/score.rb', line 34 def is_blank? @score_1 == MAX_INT end |