Class: Dither::Aetg::Pairwise
- Inherits:
-
Object
- Object
- Dither::Aetg::Pairwise
- Includes:
- Dither::Aetg
- Defined in:
- lib/dither/aetg_pairwise.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#comb ⇒ Object
readonly
Returns the value of attribute comb.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#pair_cache ⇒ Object
readonly
Returns the value of attribute pair_cache.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#random ⇒ Object
readonly
Returns the value of attribute random.
-
#scratch ⇒ Object
readonly
Returns the value of attribute scratch.
-
#t ⇒ Object
readonly
Returns the value of attribute t.
Instance Method Summary collapse
- #best_fit ⇒ Object
- #filter ⇒ Object
- #generate ⇒ Object
-
#initialize(params, opts = {}) ⇒ Pairwise
constructor
Pairs.
- #stop? ⇒ Boolean
Methods included from Dither::Aetg
Constructor Details
#initialize(params, opts = {}) ⇒ Pairwise
Pairs
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dither/aetg_pairwise.rb', line 18 def initialize(params, opts = {}) raise Dither::Error, 't must be >= 2' if opts[:t] < 2 raise Dither::Error, 't must be <= params.length' if opts[:t] > params.length params.each do |param| raise Dither::Error, 'param length must be > 1' if param.length < 2 end @params = params @n = 50 @scratch = Array.new(@n) seed = opts[:seed] || Random.new.seed @random = Random.new(seed) @pair_cache = Array.new(params.length) params.each_with_index do |param, i| pair_cache[i] = (0...param.length).map { |j| Pair.new(i, j).freeze } end if opts[:previously_tested] opts[:constraints] = [] unless opts[:constraints] opts[:previously_tested].each do |a| arr = [] a.each_with_index { |b,i| arr << [i, b] } opts[:constraints] << Hash[arr] end end @constraints = nil if opts[:constraints] @constraints = [] opts[:constraints].each do |a| constraint = a.map { |k, v| pair_cache[k][v] } constraint.extend(Pairs) @constraints << constraint end end @comb = [] @t = opts[:t] (0...params.length).to_a.combination(t).each do |a| car, *cdr = a.map { |b| pair_cache[b] } tmp = car.product(*cdr) tmp.each { |b| b.extend(Pairs) } tmp.reject! { |b| constraints.any? { |c| c.all? { |d| b.include?(d)} } } if constraints @comb.push(*tmp) end end |
Instance Attribute Details
#comb ⇒ Object (readonly)
Returns the value of attribute comb.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def comb @comb end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def constraints @constraints end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def n @n end |
#pair_cache ⇒ Object (readonly)
Returns the value of attribute pair_cache.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def pair_cache @pair_cache end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def params @params end |
#random ⇒ Object (readonly)
Returns the value of attribute random.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def random @random end |
#scratch ⇒ Object (readonly)
Returns the value of attribute scratch.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def scratch @scratch end |
#t ⇒ Object (readonly)
Returns the value of attribute t.
7 8 9 |
# File 'lib/dither/aetg_pairwise.rb', line 7 def t @t end |
Instance Method Details
#best_fit ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/dither/aetg_pairwise.rb', line 79 def best_fit max, _ = scratch.compact .map { |a| [a, comb.count { |b| b.in_test_case?(a) }] } .max { |a, b| a[1] <=> b[1] } comb.delete_if { |a| a.in_test_case?(max) } max end |
#filter ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/dither/aetg_pairwise.rb', line 69 def filter return unless constraints comb.first.each do |pair| scratch[pair.i] = pair.j end scratch.each_with_index do |e, i| scratch[i] = nil if constraints.any? { |a| a.in_test_case?(e) } end end |
#generate ⇒ Object
63 64 65 66 67 |
# File 'lib/dither/aetg_pairwise.rb', line 63 def generate (0...n).each do |i| scratch[i] = params.map { |a| random.rand(a.length) } end end |
#stop? ⇒ Boolean
87 88 89 |
# File 'lib/dither/aetg_pairwise.rb', line 87 def stop? comb.empty? end |